2

I'm wondering if there's a way to tell (Xe)LaTeX to handle \chapter as \section, \section as \subsection and so on when inputting a document via \input into another document.

The setting is: I have a text with minimal LaTeX Markup. I need to use this text in two different environments / two different root files.

One produces my "standalone" Version of this text where I need big headings and the other one is a thesis referring to this text where I need to level-down the headings, because it's part of a \chapter. Any ideas?


text file "text.tex"

\chapter*{Introduction}
Bla Bla
\section*{Point 1}
...

root file #1:

\begin{document}
\input{text}
\end{document}

root file #2:

\begin{document}
\chapter{First ideas to my text}
...
\chapter{My way to my text}
...
\chapter{The final text}
\input{text}
\end{document}
  • 1
    This should be possible. Welcome to TeX.SX! Please help us to help you and add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. –  Apr 24 '15 at 11:56
  • Related: http://tex.stackexchange.com/questions/26181/create-context-sensitive-headings – musarithmia Apr 24 '15 at 12:10
  • Thank you @egreg for pointing this out, i didn't find that. – Johannes Heck Apr 24 '15 at 12:56

1 Answers1

2

A quick trial, but I have to think about the numbering

\documentclass{book}



\usepackage{etoolbox}

\let\latexchapter\chapter
\let\latexsection\section

\newcommand{\OneLevelDeeper}{%
  \let\chapter\section
  \let\section\subsection
}

\begin{document}
\tableofcontents

\chapter{First}
\section{Section}
\subsection{Subsection}

\OneLevelDeeper
\chapter{First Fake}
\section{Section Fake}
\subsection{Subsection Fake}


\end{document}
  • You might also want a \OneLevelHigher or, better still, to wrap this into an environment. –  Apr 24 '15 at 12:03
  • @Andrew: Yes, but I saw, it's a duplicate ... I will come to it later on, perhaps showing another approach –  Apr 24 '15 at 12:09
  • @Andrew there is no need, just grouping does the job. – touhami Apr 24 '15 at 13:11
  • 1
    @touhami Of course, but environments are how one does grouping in latex. –  Apr 24 '15 at 14:03
  • Thanks for your very fast answer, @ChristianHupfer, I'll think it's the same approach as suggested in the dublicate thread under link that I didn't find due to my small english vocabulary. – Johannes Heck Apr 24 '15 at 15:19
  • @JohannesHeck: No problem at all. I had no idea too about the already existing solution. I will come back from time to time to improve, I think –  Apr 24 '15 at 15:20