I have been trying to write a simple new command to make a piece of code more flexible and readable (a MWE is below). In it I need to be able to pass a string to a new command that contains a hashtag #. I don't have any choice in the matter... I have to use a file that is auto produced and externally maintained which contains #1 or #2 in the file name.
Things I have tried that don't seem to be working:
- escaping the hashtag in the argument (i.e.
{a \#1.jpg} - \detokenize{} on the argument #1
- \detokenize{} on the string passed as an argument
MWE:
\documentclass{article}
\usepackage{graphicx,grffile}
\usepackage{hyperref}
\graphicspath{
{ABSOLUTE/PATH/TO/GRAPHICS}
}
\begin{document}
\newcommand{\Customjpg}[2]{\label{#2}\includegraphics[keepaspectratio,width=0.49\textwidth]{"#1"}}
\Customjpg{a \#1.jpg}{Fig:R1a}
\end{document}
a #1.jpg? (\string#probably works.) – David Carlisle Apr 02 '16 at 19:57\begingroup \catcode#=12and it helps keep the automation of my tex files cleaner than adding the\string`. I played around with the possibility of a verbatim command like that suggested in the alternate answer http://tex.stackexchange.com/a/294804/69378 but I think the local redefinition is the cleanest solution. I would be happy to accept this as an answer. Better yet, if it can be nested into it's own newcommand or environment (that doesn't propagate the same problem by still having to pass the # in a string) I would be most intrigued. – EngBIRD Apr 02 '16 at 20:23