1

To get proper French punctuation in pandoc with babel, I followed the advice in https://tex.stackexchange.com/a/505068/17868 which requires enabling shorthands in babel.

However, as I found out, when I do inline listings such as `:Joueur` in markdown, they sometimes show up strangely in the PDF, e.g. Joueur: (the colon is at the end, or sometimes in the middle of a word). I narrowed it down to a problem with the French shorthands involving : in the LaTeX:

\passthrough{\lstinline!:Joueur!}

My workaround was to put into the markdown

\shorthandoff{:}`:Joueur`\shorthandon{:}

which results in LaTeX that looks like:

\shorthandoff{:}\passthrough{\lstinline!:Joueur!}\shorthandon{:}

which is impeccable in the PDF.

So, to avoid polluting my markdown with LaTeX commands, I would like to apply this globally. I tried changing the definition of \passthrough in the template.latex file as follows:

%\newcommand{\passthrough}[1]{#1}
\newcommand{\passthrough}[1]{\shorthandoff{:}{#1}\shorthandon{:}}

But, it doesn't produce the correct PDF. I see would think that in LaTeX I would get

\passthrough{\shorthandoff{:}\lstinline!:Joueur!\shorthandon{:}}

which doesn't work (the shorthandoff/on has to be outside the \passthrough for it to work).

Since Pandoc uses the \passthrough command for any inline listings, I'm not sure how to wrap it by redefining something I can control in Pandoc (latex template, header includes). How can I do this? Is there some magic in the \newcommand I am missing?

Edit The answer to this related question https://tex.stackexchange.com/a/167598/17868 explains why it's not possible to embed these in macros. If pandoc doesn't have a hook for it, then I don't think it's possible...

  • I think you are free to define newcommand wrapper in your preamble, or in any file needed, and then process it with pandoc. LaTeX macros are "passed through" unchanged, so the latex process should take definition of this command as-is. – Tomáš Kruliš Aug 06 '20 at 06:51
  • @TomášKruliš see my edit - the problem seems to be that the ":" character is already processed with the current state of shorthands (on or off) once the argument to the macro has been passed. – Fuhrmanator Aug 06 '20 at 22:03

1 Answers1

2

You can split the passthrough into two commands:

\newcommand{\passthrough}{\shorthandoff{:}\passthroughtwo}
\newcommand{\passthroughtwo}[1]{#1\shorthandon{:}}

The first command turns the shorthand off before the second command evaluates the argument.

In (La)TeX there is the concept of eyes, mouth and stomach working through the filecontent. Basically when the compiler sees \passthrough, it expands it to the content of the definition (mouth). \shorthandoff can not be just expanded because it changes the inner workings of the compiler (catcodes) and is sent to the stomach. When the compiler evaluates \passthroughtwo it just takes the next token on the stream as argument, but at that time it has already changed the way it turns characters into tokens.

This is why you can't do it with a single command. You have to change the way it sees the argument before looking at it.

Malte
  • 68
  • Wow. When I first looked at this, I thought it would not work because \passthroughtwo is not invoked in the command with any argument. Does this work because commands share an argument stack? – Fuhrmanator Aug 07 '20 at 02:08
  • 1
    I wouldn't call it a stack, because you can't push to it before calling another command like you would in a stack machine. I have added some explanations to the answer about the inner working, I hope that makes it a bit clearer. Generally a command will just get replaced, not executed, so it doesn't have to be syntactically correct in the definition yet. – Malte Aug 07 '20 at 07:26