3

I would like to include a chapter two times, a short version in the main part and a long version in the appendix. Everything works fine except the labels and references. Is there a way to redefine labels in a local context? I could us a \IFDEFINE statement around every label or ref but that is not very convenient.

Any suggestions welcome, Thx!!

==================== 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
8
  • Crosspost to goLaTeX and TeXwelt.
    – Johannes_B
    Mar 29, 2015 at 11:35
  • Great solution, thanks for your expertise. However the soution adresses two different topics. 1.) replacing my construction "\ifdefined" with "\iftoggle" (nice but not strictly necessary) 2.) Main point is using input instead of include in one instance and the self defined prefix addon. GREAT HELP!!
    – MW2015
    Mar 29, 2015 at 12:45
  • @MW2015: So what does my solution mean? Is it good,is it bad? It was a quick solution, due to lack of time
    – user31729
    Mar 29, 2015 at 15:21
  • @MW2015: Es ist nicht ok, wenn eine Lösung hier angeboten und dann einfach in einem anderen Forum übernommen wird. Böses Foul ;-)
    – user31729
    Mar 29, 2015 at 15:27
  • No offense intended. Added references. THX!!
    – MW2015
    Mar 29, 2015 at 18:24

1 Answer 1

2

One possibility is to use a \labelprefix which is changed according to the toggle switch longversion (I used etoolbox macros for this) and a predefined \shortlabelprefix and \longlabelprefix.

However, this does not work, if the short version of the chapter is input via \include twice, since each input overwrites the old label values.

main.tex

\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}

kapitel.tex

\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.
}

short variant

enter image description here long variant

enter image description here

10
  • There is a comment to the question, i think it is addressed to you?
    – Johannes_B
    Mar 29, 2015 at 12:47
  • definitely not me.
    – Johannes_B
    Mar 29, 2015 at 12:47
  • @Johannes_B: ??? Definitely not you?
    – user31729
    Mar 29, 2015 at 13:37
  • Definitely not addresssed to me.
    – Johannes_B
    Mar 29, 2015 at 13:46
  • @Johannes_B: Yes, and my solution is obviously not correct ;-)
    – user31729
    Mar 29, 2015 at 15:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .