Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support autoref in LaTeX reader #7463

Open
Pusnow opened this issue Jul 28, 2021 · 9 comments
Open

Support autoref in LaTeX reader #7463

Pusnow opened this issue Jul 28, 2021 · 9 comments

Comments

@Pusnow
Copy link

Pusnow commented Jul 28, 2021

Describe your proposed improvement and the problem it solves.

Pandoc's LaTeX reader does not support \autoref from hyperref.sty.
It only supports followings:

refCommands = M.fromList
[ ("label", rawInlineOr "label" dolabel)
, ("ref", rawInlineOr "ref" $ doref "ref")
, ("cref", rawInlineOr "cref" $ doref "ref") -- from cleveref.sty
, ("vref", rawInlineOr "vref" $ doref "ref+page") -- from varioref.sty
, ("eqref", rawInlineOr "eqref" $ doref "eqref") -- from amsmath.sty
]

The hyperref.sty is one of the widely used packages and also in The ACM Publishing System (TAPS) List of Accepted LaTeX Packages.

Describe alternatives you've considered.

Preprocessing?

@jgm
Copy link
Owner

jgm commented Jul 29, 2021

It would be good to support this.

My understanding is that \autoref{foo} should be parsed as

Link ("",[],[]) [Str "Section\160\&1"] ("#foo","")

if foo is the label on the section numbered 1, and

Link ("",[],[]) [Str "Figure\160\&2"] ("#foo","")

if foo is the label on the figure numbered 2, and so on.

Now that we have localized names Figure and Section, as well as numbers, we should be able to do this.

@Pusnow
Copy link
Author

Pusnow commented Jul 30, 2021

Cleveref's cref and Cref also have the localized names: ref-example.pdf

\cref{foo} and \Cref{foo} should be parsed like autoref.

@jgm
Copy link
Owner

jgm commented Jul 30, 2021

One problem is that our localized terms don't include Section, let alone Subsection.

@jgm
Copy link
Owner

jgm commented Jul 30, 2021

Anyway, what would be needed for this change is:

  • localizations for Section
  • change sLabels in T.P.Readers.LaTeX.Parsing so that it records the type (or localized term) in addition to the number associated with a reference
  • change functions that add to sLabels to add this information
  • change resolveRefs in T.P.Readers.LaTeX to do something with this information
  • change doref in T.P.Readers.LaTeX.Inline so we can distinguish the different reference commands when we get to resolveRefs

@BishopWolf
Copy link

Any news on this topic?

@jgm
Copy link
Owner

jgm commented May 31, 2022

There's a roadmap above of what needs to be done. A first step would be localizations for Section for 48 languages. data/translations is where this would go.

@c-ding-math
Copy link

+1 feature request on \cref and \autoref.

@janosh
Copy link

janosh commented Feb 13, 2024

converting latex to typst, i'm seeing \cref{...} turned into #link(...) (should be #ref(...)) and the capitalized version \Cref{...} get swallowed (i.e. replaced with nothing)

jgm added a commit that referenced this issue Feb 13, 2024
@jgm
Copy link
Owner

jgm commented Feb 13, 2024

Re localizations, I did find this on my system:

% grep  'providetranslation{Section}' /opt/homebrew/share/texmf-dist/tex/latex/translator/*.dict | sed -e 's/.*basic-dictionary-//'
Bulgarian.dict:\providetranslation{Section}{Сечение}
Catalan.dict:\providetranslation{Section}{Secció}
Croatian.dict:\providetranslation{Section}{Odjeljak}
Czech.dict:\providetranslation{Section}{Odd\'il}
Danish.dict:\providetranslation{Section}{Sektion}
Dutch.dict:\providetranslation{Section}{Paragraaf}
English.dict:\providetranslation{Section}{Section}
French.dict:\providetranslation{Section}{Section}
German.dict:\providetranslation{Section}{Abschnitt}
Greek.dict:\providetranslation{Section}{En'othta}
Italian.dict:\providetranslation{Section}{Paragrafo}
Norsk.dict:\providetranslation{Section}{Avsnitt}
Nynorsk.dict:\providetranslation{Section}{Avsnitt}
Polish.dict:\providetranslation{Section}{Sekcja}
Russian.dict:\providetranslation{Section}{Раздел}
Serbian.dict:\providetranslation{Section}{Odeljak}
Spanish.dict:\providetranslation{Section}{Sección}
Swedish.dict:\providetranslation{Section}{Avsnitt}
Turkish.dict:\providetranslation{Section}{B\"{o}l\"{u}m}

That's a start, but it leaves a lot of the languages we support out.

It looks like we're adding a special reference-type attribute to the links produced by \cref, etc. I don't currently recall whether anything else in pandoc consumes this class, but in principle we could have typst attend to it and emit #ref in this case.

jgm added a commit that referenced this issue Feb 14, 2024
This attribute is added to LaTeX `\cref`, for example.
See #7463.
jgm added a commit that referenced this issue Feb 14, 2024
Associate with `\cref` and `\Cref` the reference-type `ref+label` and
`ref+Label`.  So far we don't do anything fancy with these.
Also, associate with `\vref` `ref` instead of `ref+page`.

See #7463.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants