3

It was a pleasant surprise for me to find out that it is possible to include image named “K_{2,3}.pdf” into TeX document using \includegraphics (and pdfLaTeX).

\documentclass{article}
\usepackage{graphicx}

\newcommand{\namedpicture}[1]{\begin{figure}\centering\includegraphics{#1}\caption{$#1$}\end{figure}}

\begin{document}
    \pagestyle{empty}
    \namedpicture{K_{2,3}}
\end{document}

Now I have a question, which doesn't seem to have practical meaning, but is still interesting:) Is it possible to include picture with name containing % or imbalanced figure brackets? I. e. I have files %.pdf, {.pdf and }.pdf. How to include any of them?

  • If you really have %.pdf, I'd say you have a peculiar taste for file name choices. ;-) – egreg Nov 12 '13 at 8:35
  • Imho you are generalizing your success to easily: Your code works on your OS with your current texsystem. I wouldn't accept bets that is works in all OS, for previous versions of a tex system and for other tex-engines. – Ulrike Fischer Nov 12 '13 at 10:54
  • I created %.pdf just for testing. :) But some name like Top 3%.pdf is not too weird. – Smylic Nov 12 '13 at 12:40
  • I do not generalize anything. I just say that it was possible under my constraints. Anything related to external files is OS-dependent. And even if now something is the same for all existing OSes some time new OS may appear and break the rule. – Smylic Nov 12 '13 at 12:44
3

If you are expecting only including such files, not automating such a process, the answer is YES. In the following we assume, that angle brackets do not appear in the names of the files and the captions are manually inserted.

\documentclass{article}
\usepackage{graphicx}

%\newcommand{\namedpicture}[1]{\begin{figure}\centering\includegraphics{#1}\caption{$#1$}\end{figure}}

\begin{document}
\pagestyle{empty}
 %   \namedpicture{K_{2,3}}
\begin{figure}\centering\includegraphics[width=20mm]{K_{2,3}}\caption{$K_{2,3}$}\end{figure}

\catcode`\%=12
\begin{figure}\centering\includegraphics[width=20mm]{%}\caption{\%}\end{figure}
\catcode`\%=14

\catcode`\<=1
\catcode`\>=2
\catcode`\{=12
\catcode`\}=12
\begin<figure>\centering\includegraphics[width=20mm]<{>\caption<\{>\end<figure>

\begin<figure>\centering\includegraphics[width=20mm]<}>\caption<\}>\end<figure>

\catcode`\<=12
\catcode`\>=12
\catcode`\{=1
\catcode`\}=2

\end{document}

enter image description here

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.