
카드 한 벌을 생성하기 위한 문서를 작성 중입니다. 카드의 가치는 일반 목록에 저장됩니다. 각 카드 색상/세트에는 일반 목록에도 정의된 자체 그래픽 파일 세트가 있습니다. 즉, 값과 파일 이름은 임의적이지만 디버깅을 위해 파일 이름은 아래 코드에서 체계화되었습니다.
아이디어는 for 루프에서 인덱스를 실행하고 루프의 각 카드에 대한 값과 그래픽 파일 이름을 모두 생성하는 것입니다. 실행 중인 인덱스는 더 많은 카드를 생성하기 위해 두 목록의 길이보다 더 길어질 수 있으므로 MyModulo 기능을 사용합니다.
GetListMember 함수/매크로를 사용하여 텍스트 출력을 생성하면 파일 이름이 올바르게 생성됩니다.
파일 이름에 대해 GetListMember 함수/매크로를 includegraphis와 함께 사용하면 컴파일이 실패합니다.
! 불완전함 \iffalse; 64행 이후의 모든 텍스트는 무시되었습니다.
삽입된 텍스트
\fi
이유를 알 수 없습니다.
저는 파일 이름을 임의로 지정할 수 있는 일반화된 솔루션을 갖고 싶습니다. (다른 목록의 길이는 소수이므로 튜플릿을 사용하는 솔루션은 아마도 가장 효과적이지 않을 것입니다.)
\documentclass{article}
\usepackage{ifthen}
\usepackage{pgffor}
\usepackage{graphicx}
\usepackage{intcalc}
\usepackage{xstring}
\graphicspath{{../images/}}
% Define card values and graphics
\newcommand{\MyValues}{10,Kn,D,K,E}% Values of the cards
\newcommand{\MyValuesN}{5}
\newcommand{\MyCard}{temp1,temp2,temp3}% Card images in one color
\newcommand{\MyCardN}{3}
\newcommand{\MyCardA}{tempA,tempB,tempC}% Card images in second color
\newcommand{\MyCardAN}{3}
% Define wrap around index function.
\newcommand{\MyModulo}[2]{%
\intcalcInc{\intcalcMod{\intcalcDec{#1}}{#2}}%
}
% From http://tex.stackexchange.com/questions/21559/macro-to-access-a-specific-member-of-a-list
% This works both with inline lists and with macros containing lists
\newcommand*{\GetListMember}[2]{%
\edef\dotheloop{%
\noexpand\foreach \noexpand\a [count=\noexpand\i] in {#1} {%
\noexpand\IfEq{\noexpand\i}{#2}{\noexpand\a\noexpand\breakforeach}{}%
}}%
\dotheloop%
}%
%Stand in function generating the cards, the real function is more elaborated.
\newcommand{\docard}[2]{%
!#1! % Value
\includegraphics[width=2cm]{#2} %graphics
}
\begin{document}
\foreach \n in {1,...,7} {%
%
%This works, shows the values.
%\GetListMember{\MyValues}{\MyModulo{\n}{\MyValuesN}}
%
%This works, produces the correct image file names.
%\GetListMember{\MyCard}{\MyModulo{\n}{\MyCardN}}.png
%
%This works, includes the images.
%\includegraphics[width=2cm]{temp\MyModulo{\n}{\MyCardN}.png}
%
%This does not work.
%\includegraphics[width=2cm]{\GetListMember{\MyCard}{\MyModulo{\n}{\MyCardN}}.png}
%
%This works, calls the card macro correctly.
%\docard{\GetListMember{\MyValues}{\MyModulo{\n}{\MyValuesN}}}{temp\MyModulo{\n}{\MyCardN}.png}
%
%This does not work.
\docard{\GetListMember{\MyValues}{\MyModulo{\n}{\MyValuesN}}}
{\GetListMember{\MyCard}{\MyModulo{\n}{\MyCardN}}.png}
\par
}
% Second color of cards
%\foreach \n in {1,...,7} {
% \docard{\GetListMember{\MyValues}{\MyModulo{\n}{\MyValuesN}}}
% {\GetListMember{\MyCardA}{\MyModulo{\n}{\MyCardNA}}.png}
% \par
%}
% Third colors of cards
%\foreach ...
\end{document}