
私はカードのデッキを生成するためのドキュメントを書いています。カードの値は、一般的なリストに保存されます。各カードの色/スーツには、一般的なリストで定義された独自のグラフィック ファイル セットがあります。つまり、値とファイル名は任意ですが、デバッグの目的で、ファイル名は以下のコードで体系化されています。
アイデアは、for ループでインデックスを実行し、ループ内の各カードの値とグラフィック ファイル名の両方を生成することです。実行中のインデックスは、どちらのリストの長さよりも長く、より多くのカードを生成できるため、MyModulo 関数を使用します。
GetListMember 関数/マクロを使用してテキスト出力を生成すると、ファイル名が正しく生成されます。
ファイル名に includegraphis とともに GetListMember 関数/マクロを使用すると、コンパイルが失敗します。
! 不完全 \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}