如何IfFileExists
在内使用\newcommand
?
如果C.jpg
没有找到,则显示B.jpg
如果C.jpg
找到,则显示A.jpg
最小代码:
\documentclass{article}
\usepackage[pdftex]{graphicx}
\begin{document}
\begin{center}
\IfFileExists{Image/C.jpg}{\includegraphics[width=8cm]{Image/A.jpg}}{\includegraphics[width=8cm]{Image/B.jpg}}
\end{center}
\end{document}
答案1
不确定这有什么用,但是……
\documentclass{article}
\usepackage{graphicx}
\newcommand{\conditionalincludegraphics}[4][]{%
\IfFileExists{#2}
{\includegraphics[#1]{#3}}
{\includegraphics[#1]{#4}}%
}
\begin{document}
\conditionalincludegraphics[width=8cm]{example-image-c.jpg}{example-image-a}{example-image-b}
\bigskip
\conditionalincludegraphics[width=8cm]{doesnotexist.jpg}{example-image-a}{example-image-b}
\end{document}