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...
newcommandwrapper 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