lierdakil/pandoc-crossref

One space too many when prefix is set to empty

Opened this issue · 5 comments

Hello, and thank you for maintaining pandoc-crossref, it's super useful!

If figPrefix, secPrefix or eqPrefix is set to empty string, there's one extra space when converting to LaTeX. For example:

  • markdown histogram [@fig:histogram]
    becomes: histogram ~\ref{fig:histogram}
    instead of: histogram~\ref{fig:histogram}
  • markdown In the second section ([@sec:examples])
    becomes: In the second section (~\ref{sec:examples})
    instead of: In the second section~(\ref{sec:examples})

Is there a way to avoid this?

(similar to #11 and #12)

→ A workaround is to use the dash syntax in markdown:

Histogram [-@fig:histogram] is in
the next section ([-@sec:examples]).

This works:

---
figPrefixTemplate: $$i$$
---

![Foo](foo.jpg){#fig:foo}

See @fig:foo

See https://lierdakil.github.io/pandoc-crossref/#reference-templates

Ah yes, this seems better than using a dash everywhere. I didn't know about the templates, thank you!

It doesn't put non-breaking spaces in the right place automatically, though, right?

Nope, but neither do dashes. Essentially, putting nbsp outside the exact place where the citation occurs is a very non-trivial problem which I'm not smart enough to solve in general, so I didn't even try. If you want nbsp between the preceeding text and the citation, consider inserting it yourself, e.g. see section\ @sec:foo.

I guess there's an option of playing with citation prefixes, e.g. I could reasonably insert an nbsp if you wrote a citation like this: see [section @sec:foo] (the syntax works, but a regular space is currently inserted, and it doesn't work particularly well with multiple references). I'm not at all convinced it's markedly better than simply section\ @sec:foo though.

I see – thanks a lot for your answers and your time!