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.

abyshukla
  • 411
  • 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

1 Answers1

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. :-)

Mico
  • 506,678
  • 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
  • Please accept my apologies if this was not clear earlier. I implemented your solution and then this error with longtabu came up. There were some paths in table -- specifying files, their source and destination -- which had the trailing '/'. – abyshukla Jun 20 '16 at 14:22
  • @manucpp - Thanks. Just to reiterate: The definition of \path in the url package is very special -- mainly because a URL string or fully qualified path string can contain various characters that may have a "special" meaning for TeX. (One such character, as you've discovered, is the backslash character, "".) If you need to modify longtabu, I suggest you begin by perusing the code of the longtabu package. – Mico Jun 20 '16 at 14:28
  • Code is something, I do not understand much -- having had no exposure to it ever -- but I will try. Also, please explain about \let\path\relax command. What did you 'relax' here? – abyshukla Jun 20 '16 at 14:32
  • 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
  • @manucpp - As @egreg has commented in the meantime, the instruction \let\path\relax isn't strictly necessary here, as \DeclareUrlCommand is savvy enough to overwrite the existing definition of \path. Importantly, though,\let\path\relax doesn't hurt either. :-) – Mico Jun 20 '16 at 14:43