如何在邮件合并中创建交叉引用

如何在邮件合并中创建交叉引用

当我想进行邮件合并时,\label{}\footref{}收到了警告There were multiply-defined labels,并且引用指向具有相同名称的最后一个标签。

我搜索了解决方案,但没有找到任何解决方案。这是我的代码:

\documentclass[english]{scrartcl}

\usepackage[colorlinks]{hyperref}
\usepackage{xspace}
\usepackage[paperheight=5cm,paperwidth=10cm, margin=0.5cm]{geometry}

\parindent 0pt                  % no space for the first line of a paragraph

% ---------- informations to read from the file ---------
\def\chopline#1,#2,#3 \\{       % number of arguments per line
    \def\salutation{#1}         % Sir/Mrs
    \def\firstname{#2\xspace}
    \def\lastname{#3\xspace}
}

\newif\ifmore                   % defines a new "if" of the name "more"
\moretrue                       % sets more to true

\begin{document}

\newread\source                 % creates a new variable "source"
\openin\source=path/datas.csv   % opens a data file

\loop                           % runs until the end of file (EOF)
    \read\source to \line       % reads every line
    \ifeof\source               % in the case the EOF is reached
        \global\morefalse       % setzt more auf false
    \else
        \expandafter\chopline\line\\    % breaks datas into lines

        Dear \salutation \lastname,

        \bigskip
        here is the first Information\footnote{\label{fn:informations}special informations} and then we want to show another one\footnote{another information}.
        \newpage        
        After that we reference back to the first one\footref{fn:informations}.

        \setcounter{footnote}{0}% resets counter for footnotes to zero
    \fi                         % end of if-else
\ifmore\newpage\repeat          % creates a new site and goes back to loop
\closein\source                 % closes data file

\end{document}

datas.csv内容如下:

Mr., James, Bond
Mrs., Ada, Lovelace

问题是,\footref{fn:informations}詹姆斯邮件中第一个脚注的第二次调用指向艾达邮件的引用。

答案1

因此,我想到不仅要给每个标签赋予名称,还要赋予一个数字,并且每次都会增加该数字。

\documentclass[english]{scrartcl}

\usepackage[colorlinks]{hyperref}
\usepackage{xspace}
\usepackage[paperheight=5cm,paperwidth=10cm, margin=0.5cm]{geometry}

\newcommand{\Label}[1]{\label{#1\number\PersonNo}}
\newcommand{\Footref}[1]{\footref{#1\number\PersonNo}}

\parindent 0pt                  % no space for the first line of a paragraph

% ---------- informations to read from the file ---------
\def\chopline#1,#2,#3 \\{       % number of arguments per line
    \def\salutation{#1}         % Sir/Mrs
    \def\firstname{#2\xspace}
    \def\lastname{#3\xspace}
}

\newcount\PersonNo              % counter for each person, it is necessary, that no label is created twice
\PersonNo=0                     % starts with zero

\newif\ifmore                   % defines a new "if" of the name "more"
\moretrue                       % sets more to true

\begin{document}

\newread\source                 % creates a new variable "source"
\openin\source=path/datas.csv   % opens a data file

\loop                           % runs until the end of file (EOF)
    \read\source to \line       % reads every line
    \ifeof\source               % in the case the EOF is reached
        \global\morefalse       % setzt more auf false
    \else
        \expandafter\chopline\line\\    % breaks datas into lines

        Dear \salutation \lastname,

        \bigskip
        here is the first Information\footnote{\Label{fn:informations}special informations} and then we want to show another one\footnote{another information}.
        \newpage        
        After that we reference back to the first one\Footref{fn:informations}.

        \setcounter{footnote}{0}% resets counter for footnotes to zero
        \advance\PersonNo by 1  % increases person counter by 1
    \fi                         % end of if-else
\ifmore\newpage\repeat          % creates a new site and goes back to loop
\closein\source                 % closes data file

\end{document}

现在每个标签都是唯一的,因为名称和编号的组合。您只需通过以下方式创建和引用标签:\Label{name}\Footref{name}

相关内容