3

I foolishly included a # (number symbol) in a file path. Whenever I reference this it generates the following error:

Illegal parameter number in definition of \reserved@a. [.../Paper#1/2016-02-14/paper1_2016-02-14.pdf}]

Is there a solution to this that is easier than renaming the folder, and consequently, changing all of the code within it to reflect that?

\documentclass[a4paper,12pt]{article}
\begin{document}
\includepdf[pages=-]{../../Paper#1/2016-02-14/paper1_2016-02-14.pdf}
\end{document}
  • Have you tried escaping it? – Azor Ahai Feb 19 '16 at 3:52
  • Yeah, no dice, @Azor-Ahai – Michael Davidson Feb 19 '16 at 3:54
  • I don't understand why changing the file path would be a big deal. Depending on the nature of the deal and its bigness, you could use a symbolic link which TeX will be quite happy with. Assuming you are on a file system which supports such things (i.e. probably not Windows). – cfr Feb 19 '16 at 4:06
  • Its a non-negligible hassle because I have other code related to data cleaning and analysis which export figures and tables in the tex directory and I would rather not change all of that code if I don't have to. Its fine if I do, I am just hoping there is a simpler solution. – Michael Davidson Feb 19 '16 at 4:40
3
\documentclass[a4paper,12pt]{article}
\begin{document}
\begingroup\catcode`\#=12
\newcommand\hashchar{}%check that is doesn't exist
\gdef\hashchar{#}
\endgroup

\input{paper\hashchar 1/test}


%or change the catcode locally:
\begingroup
\catcode`\#=12
\input{paper#1/test}
\endgroup


\end{document}
4

If your calls of \includepdf are never in the argument to another command, you can do it by absorbing the file name as a verbatim argument:

\documentclass[a4paper,12pt]{article}
\usepackage{pdfpages,xparse,letltxmacro}

\LetLtxMacro\originalincludepdf\includepdf
\RenewDocumentCommand\includepdf{O{}v}{\originalincludepdf[#1]{#2}}

\begin{document}
\includepdf[pages=-]{../../Paper#1/2016-02-14/paper1_2016-02-14.pdf}
\end{document}

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.