我想将一个章节包含两次,一个简短版本放在主要部分,一个长版本放在附录中。除了标签和引用之外,一切都很好。有没有办法在本地上下文中重新定义标签?我可以在每个标签或引用周围使用 \IFDEFINE 语句,但这不太方便。
欢迎任何建议,谢谢!!
==================== main.tex =================
\documentclass[12pt,a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage[german]{babel}
\begin{document}
\include{kapitel}
\begin{appendix}
\newcommand*{\LONGVERSION}{}
\include{kapitel}
\end{appendix}
\end{document}
==================== kapitel.tex =================
\chapter{This is a chapter}\label{chap:mychapter}
This is a test with a reference to my chapter \ref{chap:mychapter}
\ifdefined\LONGVERSION
\section{Variant LONG}
This is a long version of the chapter, which contains a lot of
additional information. This shall be placed in the appendix.
\else
\section{Variant SHORT}
This is the short version.
\fi
答案1
一种可能性是使用\labelprefix
根据切换开关而改变的longversion
(我etoolbox
为此使用了宏)和预定义的\shortlabelprefix
和\longlabelprefix
。
然而,如果两次输入章节的简短版本,则此方法不起作用,\include
因为每次输入都会覆盖旧的标签值。
主文本
\documentclass[12pt,a4paper]{book}
\usepackage{etoolbox}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}
\newcommand\shortlabelprefix{short}%
\newcommand\longlabelprefix{long}%
\newcommand\labelprefix{\shortlabelprefix}%
\newtoggle{longversion}
\togglefalse{longversion}
\begin{document}
\input{kapitel}
\begin{appendix}
\renewcommand{\labelprefix}{\longlabelprefix}
\toggletrue{longversion}
\include{kapitel}
\end{appendix}
\end{document}
卡皮泰尔
\chapter{This is a chapter}\label{\labelprefix::chap:mychapter}
This is a test with a reference to my chapter \ref{\labelprefix::chap:mychapter}
\iftoggle{longversion}{%
\section{Variant LONG}
This is a long version of the chapter, which contains a lot of
additional information. This shall be placed in the appendix.
}{%
\section{Variant SHORT}
This is the short version.
}
简短版本
长变体