![用尾部反斜杠重新定义路径](https://linux22.com/image/423528/%E7%94%A8%E5%B0%BE%E9%83%A8%E5%8F%8D%E6%96%9C%E6%9D%A0%E9%87%8D%E6%96%B0%E5%AE%9A%E4%B9%89%E8%B7%AF%E5%BE%84.png)
以下 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}