2

The following MWE works fine:

\documentclass{article}
\usepackage{url}
\renewcommand{\path}[1]{hidden for privacy}
\begin{document}
\path{C:\User\John Doe}
\end{document}

With a trailing backslash (\path{C:\User\John Doe\}) it won't compile. I've got

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

How can I redefine \path that it works with trailing backslashes, too?

Micha
  • 2,869
  • 1
    TeX interprets \} as a control sequence, so it does not recognize it as closing bracket for the argument of \path. If you use a space after the trailing backslash it should work. – Lupino Nov 05 '20 at 11:03
  • 2
    What exactly are you trying to do? If you want to change the style of \path, use: \DeclareUrlCommand – DG' Nov 05 '20 at 11:08
  • You should probably use the \} in the example as well, such that people who naïvely tests the example sees that the example works just fine. – daleif Nov 05 '20 at 11:33
  • an existing document should be prepared for publishing. As there are private data in it (e.g. in \path{}) the existing document should not be touched but with some redefinitions the private data should be replaced – Micha Nov 05 '20 at 11:34
  • @DG' The OP is trying to make a \path like macro, that just ignores the argument, but the bracing rules should be the same as the original \path – daleif Nov 05 '20 at 11:34
  • 2
    @DG' Come to think about it xparse and the v specifier can do this, see my answer – daleif Nov 05 '20 at 11:38

1 Answers1

4

You can use xparse and its v type argument specifier. If your LaTeX installation is 100% up to date, xparse is already build into latex

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

Full MWE:

\documentclass{article}
\usepackage{url}
%\renewcommand{\path}[1]{hidden for privacy}
\RenewDocumentCommand\path{v}{hidden for privacy}
\begin{document}
\path{C:\User\John Doe\}
\end{document}

Similar with xparse explicitly loaded

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{xparse}
\usepackage{url}
%\renewcommand{\path}[1]{hidden for privacy}
\RenewDocumentCommand\path{v}{»Path hidden for privacy«}
\begin{document}
\path{C:\User\John Doe\}
\end{document}
daleif
  • 54,450