tomduck / pandoc-fignos

A pandoc filter for numbering figures and figure references.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Considering locale of \cref

LukasCBossert opened this issue · comments

For me one of the big advantages of cleveref is that the prefix will be according to the main language (english=fig; ngerman=Abb. and so on).

But with a conversion (using -M fignos-cleveref) to {\xrefname{fig.}\cref{fig:label}} this clever feature of cleveref is gone. Why not simply \cref{fig:label}?
All further customisations like

% pandoc-xnos: cleveref fakery
\newcommand{\plusnamesingular}{}
\newcommand{\starnamesingular}{}
\newcommand{\xrefname}[1]{\protect\renewcommand{\plusnamesingular}{#1}}
\newcommand{\Xrefname}[1]{\protect\renewcommand{\starnamesingular}{#1}}
\providecommand{\cref}{\plusnamesingular~\ref}
\providecommand{\Cref}{\starnamesingular~\ref}
\providecommand{\crefformat}[2]{}
\providecommand{\Crefformat}[2]{}

% pandoc-xnos: cleveref formatting
\crefformat{figure}{fig.~#2#1#3}
\Crefformat{figure}{Figure~#2#1#3}

should be part of an individual use (using include-before etc.)

Or how could I get rid of that?
I just need the plain conversion of [@fig:label] to \cref{fig:label}

I agree. I have been thinking for a while now on removing the "cleveref fakery" for a pandoc-fignos 2.0 and relying on the cleveref package alone.

In the meantime you can set the xnos-cleveref-fake to False. Make sure you use \usepackage{cleveref} in your latex headers.

With xnos-cleveref-fake=False I do get only \cref but still there is a bunch of code in the preamble I do not need, since all cleveref-configurations are made in my custom made documentclass:

% pandoc-fignos: save original macros
\makeatletter
\let\@oldmakecaption=\@makecaption
\let\oldthefigure=\thefigure
\let\oldtheHfigure=\theHfigure
\makeatother

% pandoc-fignos: environment disables figure caption prefixes
\makeatletter
\newcounter{figno}
\newenvironment{no-prefix-figure-caption}{
  \let\@makecaption=\@makenoprefixcaption
  \renewcommand\thefigure{x.\thefigno}
  \renewcommand\theHfigure{x.\thefigno}
  \stepcounter{figno}
}{
  \let\thefigure=\oldthefigure
  \let\theHfigure=\oldtheHfigure
  \let\@makecaption=\@oldmakecaption
  \addtocounter{figure}{-1}
}
\makeatother

% pandoc-xnos: cleveref formatting
\crefformat{figure}{fig.~#2#1#3}
\Crefformat{figure}{Figure~#2#1#3}
\crefformat{figure}{fig.~#2#1#3}
\Crefformat{figure}{Figure~#2#1#3}

That would override several configurations.

The first two blocks of code are for disabling figure caption prefixes (e.g., "Fig. 1:") for unnumbered figures. These won't interfere with cleveref (I think). I should probably change the code to only install them as needed.

The last block does indeed hard-code in the cleverref formatting. I agree that this should be avoided.

I'm actively working on issues in this general area, so thanks for bringing the above to my attention.

Thanks for working on this issue.

One remark for the last block.
When I see it correctly you didn’t change the order (#2#1#3), so you just wanted to change the prefix.
A different approach would use \crefname (see below for German).

\crefname{subfigure}{Abb.}{Abb.}
\crefname{subtafel}{Taf.}{Taf.}
\crefname{footnote}{Anm.}{Anm.}
\crefname{equation}{Gleichung}{Gleichung}
\crefname{table}{Tab.}{Tab.}

Oh, that's better. Thanks!

In looking at the pandoc-fignos code, I see that the code blocks above labelled "pandoc-fignos: save original macros" and "pandoc-fignos: environment disables figure caption prefixes" only get installed if you have unnumbered figures in your document -- i.e., a markdown figure that is not given a # label . Those blocks of code are needed so that unnumbered and numbered figures can co-exist in the same document.

Ah - I see. Yes, then the first block(s) does make sense.

But since the format comes after \begin{document}

\begin{document}

% pandoc-xnos: cleveref formatting
\crefformat{figure}{fig.~#2#1#3}
\Crefformat{figure}{Figure~#2#1#3}

it is impossible to overwrite this in a custom made documentclass.
Otherwise one could use \AfterEndPreamble etc. for a re-definition

Yes, I expect to do away with that problem. Stay tuned. :o)

I have just posted a beta release for pandoc-fignos 2.0.0. @LukasCBossert, would you mind testing it to see if the new TeX codes are better? Please review the What's New notes first.

The beta release can be installed using

pip install pandoc-fignos --upgrade --pre --user

I confirm it works fine using --filter pandoc-fignos -M fignos-cleveref.
Just a minor thing: I get {SPACE\cref{fig:XX}}
I am just wondering if it could be transformed to \cref{fig:XX} instead?

I'm not sure that I understand. Consider the following line from demo2.md:

Reference to +@fig:1.

It gets converted to the following TeX using pandoc + pandoc-fignos:

Reference to \cref{fig:1}.

Is that not what is wanted?

Sorry, I was very unspecific.

in my .md I have [@fig:XX] which leads to { \cref{fig:august-boeckh}} .
So I understand that the outer {} come from the [] - TeXnically it doesn’t matter, but the unnecessary space could be removed. No biggie, just some TeX aesthetics.

Thanks for the clarification. It's now fixed. To upgrade, use

pip install pandoc-xnos --upgrade --pre --user

Your observation actually uncovered another bug. For markdown input [@fig:XX] the correct latex output should be {[}\cref{fig:XX}{]}. It is markdown input [@fig:XX]{} that should produce latex output {\cref{fig:XX}}. In the first case it is assumed that you want a reference enclosed in square brackets, whereas in the second case the reference is enclosed in a span. This is as per pandoc's documentation on bracketed spans.

I think that this issue is now dealt with, and so it is time to close it. Please feel welcome to reopen it if problems remain. I am looking to release pandoc-fignos 2.0.0 soon.