
특정 디렉토리의 모든 이미지를 반복 \includegraphics
하고 MainInput.tex
. 배치 파일은 IterateFiles.bat
지정된 디렉터리에 이미지 이름 목록을 만드는 데 도움이 됩니다.
rem IterateFiles.bat
echo off
rem %1 represents the path (relative to the main input file) to the files to be iterated
rem %2 represents the output file name
rem the remaining args represent the extensio of file to be iterated
set curdir=%CD%
cd %1
shift
set output=%curdir%\%1.list
copy nul %output%
shift
:loop
if "%1"=="" goto :eof
dir /b *.%1 >> %output%
shift
goto :loop
현재 매크로 구현에는 \IterateFiles
3개의 인수가 사용됩니다. 처음 2개의 인수는 MainInput.tex
이미지가 저장되는 디렉터리에 대한 경로( 에 상대적)입니다 . 여기서 나쁜 점은 동일한 경로를 ..\dirsep Images\dirsep
와 2가지 형식으로 지정해야 한다는 것입니다 ../Images/
.
% MainInput.tex
\documentclass{article}
\usepackage{graphicx}
{
\catcode`\^0
\catcode`\\12
^gdef^dirsep{\}
}
\newread\myfile
\newcount\TotalFiles
\makeatletter
\newcommand{\IterateFiles}[3]{%
\immediate\write18{IterateFiles #1 \jobname\space #3}
\openin\myfile=\jobname.list\relax
\loop
\read\myfile to \mydata
\unless\ifeof\myfile
\filename@parse{\mydata}
\section*{\mydata}
\includegraphics[width=\textwidth,height=\textheight,keepaspectratio]{#2\filename@base}
\advance\TotalFiles1\relax
\repeat
\closein\myfile
}
\makeatother
\begin{document}
\IterateFiles{..\dirsep Images\dirsep}{../Images/}{jpg png pdf eps}
\section*{Summary}
There are \the\TotalFiles\ files in total.
\end{document}
../Images/
내 질문: 위 매크로에 단일 파일 경로 인수(두 인수와 반대)를 전달하는 방법은 무엇입니까 ?
답변1
s를 s로 xstring
바꾸려면 패키지를 사용하십시오 (또는 그 반대로)./
\
\StrSubstitute{../Images}{/}{\dirsep}}
답변2
아, 유령님, 분명히 Windows 명령 셸도 ../Images/
. 나는 이것을 몰랐다.
% MainInput.tex
\documentclass{article}
\usepackage{graphicx}
\newread\myfile
\newcount\TotalFiles
\makeatletter
\newcommand{\IterateFiles}[2]{%
\immediate\write18{IterateFiles #1 \jobname\space #2}
\openin\myfile=\jobname.list\relax
\loop
\read\myfile to \mydata
\unless\ifeof\myfile
\filename@parse{\mydata}
\section*{\mydata}
\includegraphics[width=\textwidth,height=\textheight,keepaspectratio]{#1\filename@base}
\advance\TotalFiles1\relax
\repeat
\closein\myfile
}
\makeatother
\begin{document}
\IterateFiles{../Images/}{jpg png pdf eps}
\section*{Summary}
There are \the\TotalFiles\ files in total.
\end{document}
\filenamb@base
경고: 대신 사용할 때 여기에 숨겨진 버그가 있습니다 \mydata
. 확장자가 다른 동일한 파일 이름이 있는 경우 해당 파일 중 하나만 포함됩니다. 자세한 해결 방법은 다음을 참조하세요.외부 파일에서 읽은 각 줄의 줄 끝 문자를 자르는 방법은 무엇입니까?.