是否可以让 LaTeX 反向读取切片?

是否可以让 LaTeX 反向读取切片?

我想在读书时做笔记(仅供内部使用)。为了方便起见,我想在 PDF 输出的第一页上写下我正在阅读的当前主题的笔记,以避免按 END 按钮转到最后一页。对不起。我有点懒得使用单独的文件进行分段。这是我的真实情况。因此,必须按如下方式反转标题结构。

\documentclass{book}
\usepackage{tipa}
\begin{document}

\chapter{Book Printing versus Ordinary Typing}


% end of chapter 1
\ldots
\section{Pronounction of \TeX}
    \TeX\ is often pronounced \textipa{/\textprimstress t\textepsilon k/} in English.

\section{Root of the name \TeX}
\TeX\ is the upper case of $\tau\epsilon\chi$ which is a Greek word that means art as well as technology.

\chapter{The Name of the Game}
\end{document}

写完这本书后,我想将标题结构反转为正常顺序。但手动操作似乎很繁琐和麻烦。

简单来说,LaTeX 是否可以反向读取标题结构?我的意思是,我希望 LaTeX 能够像下面这样读取上面的代码。

\documentclass{book}
\usepackage{tipa}
\begin{document}
\chapter{The Name of the Game}

\section{Root of the name \TeX}
\TeX\ is the upper case of $\tau\epsilon\chi$ which is a Greek word that means art as well as technology.

\section{Pronounction of \TeX}
    \TeX\ is often pronounced \textipa{/\textprimstress t\textepsilon k/} in English.

\ldots


% end of chapter 1

\chapter{Book Printing versus Ordinary Typing}
\end{document}

编辑:

我认为我可以采用的最方便的标记如下。

% begin
\section{Root of the name \TeX}
\TeX\ is the upper case of $\tau\epsilon\chi$ which is a Greek word that means art as well as technology.
% end

答案1

在此处输入图片描述

此版本设置了章节/部分计数,您可以扩展它以使用label/来获取这些ref计数并进行多次传递,但在任何实际情况下可能不值得。

\documentclass{book}
\usepackage{tipa}

\let\oldchapter\chapter
\let\oldsection\section
\makeatletter
\setcounter{chapter}{3}
\def\chapter#1{\egroup
\addtocounter{chapter}{-2}%
\setbox\z@\vbox{\unvbox\tw@\unvbox\z@}\setbox\tw@\vbox\bgroup\oldchapter{#1}%
\setcounter{section}{3}}
\def\section{\egroup
\addtocounter{section}{-2}%
\setbox\z@\vbox{\unvbox\tw@\unvbox\z@}\setbox\tw@\vbox\bgroup\oldsection}

\AtBeginDocument{\setbox\z@\vbox{}\setbox\tw@\vbox\bgroup}
\AtEndDocument{\egroup
\unvbox\tw@
\unvbox\z@}


\begin{document}

\chapter{Book Printing versus Ordinary Typing}


% end of chapter 1
\ldots
\section{Pronounction of \TeX}
    \TeX\ is often pronounced \textipa{/\textprimstress t\textepsilon k/} in English.

\section{Root of the name \TeX}
\TeX\ is the upper case of $\tau\epsilon\chi$ which is a Greek word that means art as well as technology.

\chapter{The Name of the Game}
\end{document}

相关内容