0

I am trying to redefine \includegraphics to both auto-label the included figure and to restrict the maximum width. The auto-labeling is done by transforming the base filename to camelcase using the stringstrings package. This is what I have:

\usepackage{stringstrings}
\usepackage[export]{adjustbox}
\usepackage{graphicx}

\let\origincludegraphics=\includegraphics
\renewcommand{\includegraphics}[1]{
  \makeatletter
  \filename@parse{#1}
  \convertchar[q]{\filename@base}{\textunderscore}{\blankspace}
  \capitalizewords[q]{\thestring}
  \noblanks[q]{\thestring}
  \origincludegraphics[max width=\linewidth]{\thestring}
}

It fails with an

**undefined control sequence**

error; this seems to be coming from the file parsing commands, because this doesn't work:

\documentclass[11pt]{report}
\usepackage{amsmath}
\begin{document}

\newcommand\testcmd[1]{
  \makeatletter
  \filename@parse{#1}
  \filename@base
  \makeatother
}

\testcmd{path/to/stuff.png}


\end{document}
  • why doesn't file parsing work inside a command?
  • is there another way to achieve my goal of figure auto-labeling by a component of the path?
  • 1
    You need to move \makeatletter (and \makeatother) outside of the command. – Robert Nov 19 '13 at 06:24
  • @Robert Thanks, I did that and it worked. I'm now having another problem though-- in trying to camelcase the string, I am replacing underscores with spaces, capitalizing the words, then deleting the spaces. But I can't figure out how to replace the underscores with spaces, i.e. what to use as the third argument in \convertchar[q]{\filename@base}{\textunderscore}{ ??? }. I tried \blankspace, \quad, and \~ but none of them worked. – Sean Mackesey Nov 19 '13 at 06:52

0 Answers0