以下 MWE 工作正常:
\documentclass{article}
\usepackage{url}
\renewcommand{\path}[1]{hidden for privacy}
\begin{document}
\path{C:\User\John Doe}
\end{document}
如果末尾有反斜杠 ( \path{C:\User\John Doe\}
),则无法编译。我有
Runaway argument?
{C:\User \John Doe\} \end {document}
! File ended while scanning use of \path.
我怎样才能重新定义\path
它以使其也适用于尾随反斜杠?
答案1
您可以使用xparse
及其v
类型参数说明符。如果您的 LaTeX 安装是 100% 最新的,xparse
则已内置到 latex 中
\RenewDocumentCommand\path{v}{hidden for privacy}
完整 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}
xparse
与显式加载类似
\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}