lierdakil / pandoc-crossref

Pandoc filter for cross-references
https://lierdakil.github.io/pandoc-crossref/
GNU General Public License v2.0
909 stars 73 forks source link

A question regarding the label syntax (allowable characters) #411

Closed tikuma-lsuhsc closed 6 months ago

tikuma-lsuhsc commented 8 months ago

Hi, first of all a great pandoc filter!

That being said, due to its incompatibility with LaTeX with journal specific document classes, I decided to write my own Python filter which is compatible with pandoc-crossref so I can simply swap the filter depending on the output format. Towards this goal, I have a question regarding the syntax of the labels.

The manual specifies, for example, from an eq label:

To label a display equation, append {#eq:label} (with label being something unique to reference this equation by) immediately after math block.

but it does not specify which characters are allowed for the label part of the syntax. Can a label consists of any non-space characters? Or are there a limit to which characters are eligible?

In my document, I have a label {#fig:fig1} and a reference to its subfigure @fig:fig1(a). This gets rendered correctly as Fig. 1(a). But, @fig:fig1a fails. So, I suspect there is a set of allowed characters for labels, but I don't know Haskell to pin down this info on the source.

Any input would be appreciated. Thanks! -Kesh

lierdakil commented 6 months ago

Pandoc-crossref doesn't impose any restrictions IIRC, but Pandoc does. Since pandoc-crossref piggybacks from Pandoc's citation syntax, the limitations are the same. The actual citation syntax is a bit complicated, but essentially you're looking at alphanumeric, _, and any of :.#$%&-+?<>~/ but not as the first of the last character.

lierdakil commented 6 months ago

FWIW, you can also brace {} citation identifiers to get more allowed characters (essentially anything except whitespace), but I don't know if it's particularly useful. But this works:

$$\begin{aligned}my fancy equation\end{aligned}$${#eq:test(a)}

@{eq:test(a)}

Since you're writing a filter, you don't really need to think about it too much, pandoc will do (most) of the parsing for you.

tikuma-lsuhsc commented 6 months ago

@lierdakil - thanks for your response. After I wrote this issue, I went with the allowed characters for HTML href tag: [a-zA-Z0-9\-_]. This worked for my personal case. I'll test later with the suggested addition of :.#$%&-+?<>~/ as middle characters. Thanks!