newcommand 计数器扩展问题

newcommand 计数器扩展问题

我正在尝试编写一个宏来支持为两列 IEEE 论文中的附录制作一系列情节提要。

计数器的值是否可以立即扩展为宏?目前 \theboardnumber 的值仅扩展为最终值。请参阅注释 % <- PROBLEM 的行。

% #1 is the storyboard title
% #2 is the image filename
% #3 is the image reference name
% #4 is the image caption
% #5 is the story to go with the image
\newcommand\boardset[2]{\csdef{board:#1}{#2}}
\newcommand\boardget[1]{\csuse{board:#1}}
\newcounter{boardnumber}
\newcommand{\storyboard}[6]{ %
    \stepcounter{boardnumber} %
    \boardset{#3}{storyboard \theboardnumber} % <- PROBLEM
    \begin{table*}[h!] %
        \begin{tabular}{|l|r|} %
        \hline %
        \begin{minipage}[t]{0.70\linewidth} %
            \vspace{0.1mm} %
            \begin{center} %
                \underline{\textbf{\boardget{#3}: #1}}\\ %
            \end{center} %
            #5 %
        \end{minipage} & %
        \begin{minipage}[t]{0.25\linewidth} %
            \raisebox{-\height}
                {\includegraphics[width=\textwidth]{#2}} %
            \captionof{figure}{#4}\label{#3} %
        \end{minipage} \\ \\ %
        \hline %
        \end{tabular} %
    \end{table*} %
}

此代码:

\storyboard{Appearance of 5 RGB white point sources}
{MagnifiedQuincunx_source}{fig:Quincunx_source}{Source image}
{Five point sources are presented to the subject.}

\storyboard{Appearance of 5 RGB white point sources centered on retina}
{MagnifiedQuincunx_target}{fig:Quincunx_target}{Target image}
{
    If the center white point is on the optic axis,
    this is how refraction and diffraction modify the image.
}

Fig.~\ref{fig:Quincunx_target} in \boardget{fig:Quincunx_target}
is the image formed on the retina when
Fig.~\ref{fig:Quincunx_source} in \boardget{fig:Quincunx_source}
is centered on the optic axis of a human retina.

扩展为:

Fig. 2 in storyboard 2 is the image formed on the retina when Fig. 1 in 
storyboard 2 is centered on the optic axis of a
human retina.

正确的结果应该是:

Fig. 2 in storyboard 2 is the image formed on the retina when Fig. 1 in 
storyboard 1 is centered on the optic axis of a
human retina.

注意,第二次引用storyboard的次数应该是1。

我花了几个小时寻找解决方案并尝试了许多方法,包括 \immediate\write、\edef、\xdef 和许多其他方法。

我可能做错了什么所以我寻求帮助。

答案1

这是使用 David Carlisle 的评论的更正版本。将源代码复制到 .tex 文件中,pdflatex 会按照我的要求对其进行解释。您必须将“MagnifiedQuincunx_.*”文件和名称替换为您机器本地的文件和名称。

再次感谢你。

\documentclass[10pt,twoside]{IEEEtran}

\usepackage[export]{adjustbox} % includes graphicx
\usepackage{caption}
\usepackage{etoolbox}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% #1 is the storyboard title
% #2 is the image filename
% #3 is the image reference name
% #4 is the image caption
% #5 is the story to go with the image
\newcommand\boardset[2]{\csxdef{board:#1}{#2}}
\newcommand\boardget[1]{\csuse{board:#1}}
\newcounter{boardnumber}
\newcommand{\storyboard}[6]{%
    \stepcounter{boardnumber}%
    \boardset{#3}{storyboard \theboardnumber}%
    \vspace{-7pt}%
    \begin{table*}[h!]%
        \begin{tabular}{|l|r|}%
        \hline%
        \begin{minipage}[t]{0.70\linewidth}%
            \vspace{0.1mm}%
            \begin{center}%
                \underline{\textbf{\boardget{#3}: #1}}\\%
            \end{center}%
            #5%
        \end{minipage} &%
        \begin{minipage}[t]{0.25\linewidth}%
            \raisebox{-\height}
                {\includegraphics[width=\textwidth]{#2}}%
            \captionof{figure}{#4}\label{#3}%
        \end{minipage} \\ \\%
        \hline%
        \end{tabular}%
    \end{table*}%
    \vspace{-7pt}%
}

\begin{document}

\onecolumn

\section{Optics Storyboards}

\storyboard{Appearance of 5 RGB white point sources}
{img/MagnifiedQuincunx_source}{fig:Quincunx_source}{Source image}
{Five point sources are presented to the subject.}

\storyboard{Appearance of 5 RGB white point sources centered on retina}
{img/MagnifiedQuincunx_target}{fig:Quincunx_target}{Target image}
{
    If the center white point is on the optic axis,
    this is how refraction and diffraction modify the image.
}

Fig.~\ref{fig:Quincunx_target} in \boardget{fig:Quincunx_target}
is the image formed on the retina when
Fig.~\ref{fig:Quincunx_source} in \boardget{fig:Quincunx_source}
is centered on the optic axis of a human retina.

\twocolumn

\end{document}

相关内容