2

The solution using xparse with the following redefinition (see redefine path with trailing backslash)

\RenewDocumentCommand\path{v}{hidden for privacy}

does not seem to work in all contexts.

For example, the following MWE using path without a trailing backslash within a footnote does not work.

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{xparse}
\usepackage{url}
\RenewDocumentCommand\path{v}{Path hidden for privacy}
\begin{document}
\footnote{\path{C:\User\John Doe}}
\end{document}

Here, I get the following error:

! LaTeX3 Error: The verbatim command '\path' cannot be used inside an
(LaTeX3)        argument.

And when using a path argument with a trailing backslash within a footnote, it doesn't work due to another error (runaway argument?):

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{xparse}
\usepackage{url}
\RenewDocumentCommand\path{v}{Path hidden for privacy}
\begin{document}
\footnote{\path{C:\User\John Doe\}}
\end{document}

The error message for this MWE is as follows:

Runaway argument?
{\path {C:\User \John Doe\}} \end {document} 
! File ended while scanning use of \@footnotetext.

Is there a way to redefine path to replace its content with a placeholder that also works within other contexts like footnote?

  • That is to be expected one cannot use verbatim-like macros in arguments to other macros, same as with \verb+test+ – daleif Nov 16 '20 at 11:22
  • Is there a way to redefine path so that it works in the same contexts as the original version and with the same argument, but replaces its content by a placeholder? – Matthias Nov 16 '20 at 11:31
  • No idea, I would never promote the use of \ in path names in the first place. – daleif Nov 16 '20 at 12:33
  • You do not need to use C:\User\John Doe tex will accept C:/User/John Doe then you do not need any verbatim handling – David Carlisle Nov 16 '20 at 12:51
  • I need to have backslashes in my path argument when I'm dealing with Windows paths. – Matthias Nov 16 '20 at 13:04

0 Answers0