シンボルを含むファイルパスがエラーの原因となる

シンボルを含むファイルパスがエラーの原因となる

誤ってファイル パスに # (数字記号) を含めてしまいました。これを参照すると、次のエラーが発生します。

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

フォルダーの名前を変更し、その結果、フォルダー内のすべてのコードを変更してそれを反映するよりも簡単な解決策はありますか?

\documentclass[a4paper,12pt]{article}
\begin{document}
\includepdf[pages=-]{../../Paper#1/2016-02-14/paper1_2016-02-14.pdf}
\end{document}

答え1

\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}

答え2

の呼び出しが\includepdf別のコマンドの引数に含まれていない場合は、ファイル名をそのままの引数として取り込むことでこれを実行できます。

\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}

関連情報