重新標記標籤?

重新標記標籤?

我面臨一個問題,我需要「可靠」標籤。

我正在研究一種機制,使用兩個不同的參數對 tex 檔案的一部分運行兩次,以便寫出文本的不同部分。透過使用 \input 和之前設定的變數。在最終的 PDF 中,兩種排列方式應依序列印。

機制的工作原理如下:

...
\DefCurrentLanguage{DE}
\input{content.tex}
\DefCurrentLanguage{EN}
\input{content.tex}
...

當我使用標籤時,這給我帶來了一些問題。請參閱此處的簡化版本(沒有 \input,但帶有明文)

\documentclass{scrbook}
\usepackage{etoc}
\usepackage{hyperref}
\counterwithout{section}{chapter}

\begin{document}

% Usually this is input my \input{myfile.txt} with the first option
\chapter{GERMAN}
\etocsettocstyle{\section*{Inhalt}}{}
\etocsettocdepth.toc{subsection}
\localtableofcontents
\setcounter{section}{0}
\section{Eins}
Referenz auf zwei: \ref{mylabel}
\subsection{Ein.Eins}
\section{Zwei}\label{mylabel}


% Usually this is input my \input{myfile.txt} with the second option
\chapter{ENGLISH}
\etocsettocstyle{\section*{Content}}{}
\etocsettocdepth.toc{subsection}
\localtableofcontents
\setcounter{section}{0}
\section{One}
Refenence to two: \ref{mylabel}
\subsection{One.One}
\section{Two}\label{mylabel}
\end{document}

我需要將標籤 mylabel 在第一種情況下重新命名為 DE.mylabel,在第二種情況下將標籤重新命名為 EN.mylabel。

我想我需要以某種方式創建一個單獨的 \label 和 \ref 命令?有什麼提示嗎?按原樣使用它,當然會導致多個定義的標籤

格奧爾格

答案1

感謝@Teepeemm:

\documentclass{scrbook}
\usepackage{etoc}
\usepackage{hyperref}
\counterwithout{section}{chapter}

\begin{document}

% Usually this is input my \input{myfile.txt} with the first option
\def\lang {DE}
\chapter{GERMAN}
\etocsettocstyle{\section*{Inhalt}}{}
\etocsettocdepth.toc{subsection}
\localtableofcontents
\setcounter{section}{0}
\section{Eins}
Referenz auf zwei: \ref{\lang mylabel}
\subsection{Ein.Eins}
\section{Zwei}\label{\lang mylabel}


% Usually this is input my \input{myfile.txt} with the second option
\def\lang {EN}
\chapter{ENGLISH}
\etocsettocstyle{\section*{Content}}{}
\etocsettocdepth.toc{subsection}
\localtableofcontents
\setcounter{section}{0}
\section{One}
Refenence to two: \ref{\lang mylabel}
\subsection{One.One}
\section{Two}\label{\lang mylabel}
\end{document}

相關內容