3

MWE:

\documentclass{article}
\usepackage[obeyspaces]{url}
\usepackage{xcolor,letltxmacro,booktabs,longtable,tabu}

\LetLtxMacro{\oldpath}{\path}
\renewcommand{\path}[1]{\color{gray}{\oldpath{#1}}}


\begin{document}
    \section{Software Requirements}\label{scn:softreq}
    %
    \begin{enumerate}
        \item Windows 8.1 64-bit with .NET framework 3.5
        \item Microsoft Visual Studio 2010 Professional with Service Pack 1
        \item Download and install:
        %
        \begin{itemize}
            \item \texttt{qt-win-opensource-4.8.4-vs2010} from \url{http://download.qt.io/archive/qt/4.8/4.8.4/qt-win-opensource-4.8.4-vs2010.exe}.
            \item \texttt{qt-creator-windows-opensource-2.6.2} available in \path{C:\Code\Pre-requisite-Setup\}
            \item \texttt{qt-vs-addin-1.1.11-opensource} from  \url{http://download.qt.io/archive/vsaddin/qt-vs-addin-1.1.11-opensource.exe}.
            \item \texttt{qt-opensource-windows-x86-msvc2013-5.6.0} from \url{http://download.qt.io/archive/qt/5.6/5.6.0/qt-opensource-windows-x86-msvc2013-5.6.0.exe}.
        \end{itemize}
        %
    \end{enumerate}
\end{document}

If, instead of \path{C:\Code\Pre-requisite-Setup\} I write \path{C:\Code\Pre-requisite-Setup}, no errors are encountered. The problem is with LetLtxMacro which I have used.

Error: file ended while scanning use of \path

The document is too long for me to go back and change each instance.

I have gone through Can I redefine a command to contain itself? and could not implement it to modify path.

I need help to modify the useless macro and eventually find inner peace.

  • 1
    "The document is too long for me to go back and change each instance." Surely any editor will allow you to fix all such cases without much effort no matter how long the document? just globally change \path{([^{}]*)\} to \path{\1} – David Carlisle Jun 20 '16 at 11:20
  • Of course!! Why didn't I think of it? Maybe I was too hung up on fixing \path. Thanks :) – abyshukla Jun 20 '16 at 11:30
  • 2
    note you should anyway do as mico suggests as apart from the error from \} with your redefinition the argument is not read verbatim so you get a space after each "command" \Code, \Pre etc. – David Carlisle Jun 20 '16 at 11:44
4

The file url.sty defines \path as follows:

\@ifundefined{path}{\DeclareUrlCommand\path{\urlstyle{tt}}}{}

In constrast, your (re)definition of \path does not use the \DeclareUrlCommand machinery. That's why it gets hung up on the "\}" substring in \path{C:\Code\Pre-requisite-Setup\}. (Note also that \path -- as defined in the url package via \DeclareUrlCommand -- doesn't take optional arguments. Hence, using \LetLtxMacro achieves nothing that couldn't be handled via \let.)

The remedy is to redefine \path as follows (in the preamble, after loading the url package):

\let\path\relax
\DeclareUrlCommand\path{\color{gray}\urlstyle{tt}}

Addendum: As @egreg has pointed out in a comment, the instruction \let\path\relax isn't strictly necessary as the subsequent \DeclareUrlCommand instruction overwrites the existing definition of \path. Fortunately, \let\path\relax doesn't hurt either. :-)

  • Can I use this to edit other existing macros like \emph, \texttt etc? If each macro has different method to redefine it, how can I identify them? Any tell-tale signs? – abyshukla Jun 20 '16 at 12:04
  • Also, I tried to use it with \longtabu but failed. Error: File ended while scanning use of \tabu@collectbody. For now I have simply removed the offending '\' from the end of paths. – abyshukla Jun 20 '16 at 12:26
  • @manucpp - The definition of \path is very special. There's no reason to presume that its setup is of any relevance for other commands such as, say, \emph or \longtabu. (If you need help with redefining \longtabu, you should pose a new question.) Incidentally, is there a reason for not implementing the solution I suggested and, instead, editing all the path strings to remove the trailing backslash characters? – Mico Jun 20 '16 at 13:08
  • 2
    @manucpp The \let\path\relax line is not necessary: \DeclareUrlCommand silently overwrites. – egreg Jun 20 '16 at 14:35
  • 1
    @manucpp -- To redefine a macro safely, it's usually best to "undefine" it first. One such way is to equate the macro via a \let statement to the primitive instruction \relax. As its name suggests, the \relax macro is set up to do nothing. (More precisely, whatever is being executed by TeX is stopped cold when \relax is encountered.) For more information on "undefining" a macro via the \let approach see, e.g., @egreg's answer to the query How to undo a \def (i.e., Need a \undef capability). – Mico Jun 20 '16 at 14:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.