tomduck / pandoc-tablenos

A pandoc filter for numbering tables and table references.
GNU General Public License v3.0
108 stars 8 forks source link

Macros prevent combining tex files #10

Closed will-hart closed 5 years ago

will-hart commented 5 years ago

The pandoc-xnos, pandoc-tablenos filters add latex macros to the body of the document, i.e.

\begin{document}
\maketitle

% pandoc-xnos: macro to create a caption without a prefix
\makeatletter
% ...

This means that even with LaTeX packages like docmute I can't \input or \subimport multiple tex files filtered by these packages into a main document as it results in errors:

! LaTeX Error: Command \c@tableno already defined.
               Or name \end... illegal, see p.192 of the manual.

Is there a way to put this output before \begin{document}, so that it can be ignored by docmute, or can they be wrapped in a semi-unique text marker so that they can be removed with a filter? For instance something like:

%%%% START pandoc-tablenos macros
macros in here
%%%% END pandoc-tablenos macros

🎄

will-hart commented 5 years ago

A fix for this in xelatex at least is to write the header code with two additional \ifdef{}{} commands as follows:


% pandoc-tablenos: environment disables table caption prefixes
\makeatletter
 \ifdef{\c@tableno}{}{\newcounter{tableno}}
 \ifdef{no-prefix-table-caption}{}{%
  \newenvironment{no-prefix-table-caption}{
    \let\LT@makecaption=\LT@makenoprefixcaption
    \renewcommand\thetable{x.\thetableno}
    \renewcommand\theHtable{x.\thetableno}
    \stepcounter{tableno}
  }{
    \let\thetable=\oldthetable
    \let\theHtable=\oldtheHtable
    \let\LT@makecaption=\LT@oldmakecaption
    \addtocounter{table}{-1}
  }
}
\makeatother

Unfortunately this only lasts until a rebuild.

tomduck commented 5 years ago

Hi, Will. Sorry for the delay.

The mechanism that I have in place to deal with cases like this is to set the xnos-cleveref-fake meta variable to False. Use \usepackage{cleveref} in your LaTeX header instead.

Does this work for you?

tomduck commented 5 years ago

Note that I am also considering removing the cleveref fakery from a pandoc-tablenos 2.0 release. In the meantime setting the xnos-cleveref-fake to False should continue to work.

tomduck commented 5 years ago

I just pushed out a new beta release in the 2.0 branch. The TeX handling has been entirely re-worked.

To install the beta release, run

pip install pandoc-tablenos --upgrade --pre --user

I would be grateful for any feedback that you wish to provide. Please be sure to read about what's new first.

tomduck commented 5 years ago

I'm quite confident that this is fixed in the 2.0 branch, as I have been battle-testing it extensively. A release to pypi is coming soon. In the meantime I am going to close this Issue as I am clearing out as many old Issues as I can before the next release. Please re-open it if in fact the Issue remains.