假设A.tex中有如下几个段落:
para1:卡尔曼滤波器是一种高效的递归滤波器,它根据一系列噪声测量估计线性动态系统的内部状态。它广泛应用于从雷达和计算机视觉到结构宏观经济模型估计等工程和计量经济学领域,是控制理论和控制系统工程中的一个重要课题。
para2:卡尔曼滤波器与线性二次调节器(LQR)一起解决线性二次高斯控制问题(LQG)。卡尔曼滤波器、线性二次调节器和线性二次高斯控制器可以说是控制理论中最基本的问题的解决方案。
第3段:在大多数应用中,内部状态比测量的几个“可观察”参数要大得多(自由度更大)。然而,通过结合一系列测量值,卡尔曼滤波器可以估计整个内部状态。
我要做的是自动复制B.tex中用粗体字母标记的句子(注意,句子用粗体字母标记只是为了指示,即粗体字母不应该成为复制的条件),使得B.tex中包含:
卡尔曼滤波器、线性二次调节器和线性二次高斯控制器可以说是控制理论中最基本的问题的解决方案。
在大多数应用中,内部状态比测量的几个“可观察”参数要大得多(自由度更大)。
如果这些句子在 A.tex 中被修改,它们也会发生变化。
我想说的是,有没有什么方法可以引用这些句子,类似于交叉引用,比如引文和方程式(例如,使用 \label{})?
2020 年 11 月 30 日编辑:
另一件事是,我可能需要在上下文中包含一些特殊符号,例如数学符号$\alpha$。
答案1
包裹参考值可能是你的朋友:
通过参考值你可以实现自己的\label
交叉\ref
引用机制,例如,用于检索和存储句子。通过参考值的模块 xr 您可以从其他 .tex 文档中检索 zref 交叉引用标签,只要这些文档的 .aux 文件可用。
我建议使用 zref-route,因为使用 zref 你可以
- 如果存在多重定义标签,则在终端/.log 文件中获取有关该标签的警告。
- 如果与标签相关的数据/与已保存内容相关的数据发生了变化,则通过终端/.log 文件告知需要重新运行 LaTeX。
以下文件A.tex
使用参考值用于提供宏\StoreSentence
并使\RetrieveSentence
句子可通过 zref-cross-referencing-label 访问。
以下文件B.tex
使用相同的内容,并额外加载参考值的 xr 模块用于在编译期间提供A.tex
/的 zref 交叉引用数据。A.aux
B.tex
A.tex
:
\documentclass{article}
\usepackage{zref}
\makeatletter
\@ifpackageloaded{hyperref}{%
\@ifdefinable\RetrieveSentence@RefUndefText{%
\DeclareRobustCommand\RetrieveSentence@RefUndefText{%
\texorpdfstring{\nfss@text{\reset@font\bfseries ??}}{??}%
}%
}%
\@ifdefinable\RetrieveSentence{%
\DeclareRobustCommand\RetrieveSentence[1]{%
\texorpdfstring{\zref@refused{#1}}{}%
\zref@extractdefault{#1}{storedsentence}{\RetrieveSentence@RefUndefText}%
}%
}%
}{%
\@ifdefinable\RetrieveSentence@RefUndefText{%
\DeclareRobustCommand\RetrieveSentence@RefUndefText{%
\nfss@text{\reset@font\bfseries ??}%
}%
}%
\@ifdefinable\RetrieveSentence{%
\DeclareRobustCommand\RetrieveSentence[1]{%
\zref@refused{#1}%
\zref@extractdefault{#1}{storedsentence}{\RetrieveSentence@RefUndefText}%
}%
}%
}%
%
\zref@newprop{storedsentence}[\RetrieveSentence@RefUndefText]{}%
\@ifdefinable\StoreSentence{%
\DeclareRobustCommand\StoreSentence[2]{%
\begingroup
\zref@setcurrent{storedsentence}{#2}%
\zref@labelbyprops{#1}{storedsentence}%
\endgroup
#2%
}%
}%
\makeatother
\begin{document}
Let's retrieve the sentence associated to the label FirstSentence in A.tex:
\RetrieveSentence{FirstSentence}
\bigskip
Let's retrieve the sentence associated to the label SecondSentence in A.tex:
\RetrieveSentence{SecondSentence}
\bigskip\noindent\hrule\bigskip
Let's create the labels:
\vfill
This is some text which does not go to a label.
%\textbf{%
\StoreSentence{FirstSentence}{This is some text which in A.tex went to the label FirstSentence.}%
%}
\vfill
This is some text which does not go to a label.
%\textbf{%
\StoreSentence{SecondSentence}{This is some text which in A.tex went to the label SecondSentence.}%
%}
\vfill
\end{document}
重复编译A.tex
而不删除 .aux 文件,直到出现类似以下消息
Package rerunfilecheck Warning: File `A.out' has changed.
(rerunfilecheck) Rerun to get outlines right
(rerunfilecheck) or use package `bookmark'.
和
LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right.
终端上不再显示收益A.pdf
:
B.tex
:
\documentclass{article}
% This time let's load zref's module xr for importing labels from the .aux-files of other documents:
\usepackage[xr]{zref}
% Let's import the zref-cross-referencing-labels from A.tex/A.aux:
%\zexternaldocument[<prefix to add to names of imported labels>]{<external document>}[<url>]
\zexternaldocument[FromA:]{A}
\makeatletter
\@ifpackageloaded{hyperref}{%
\@ifdefinable\RetrieveSentence@RefUndefText{%
\DeclareRobustCommand\RetrieveSentence@RefUndefText{%
\texorpdfstring{\nfss@text{\reset@font\bfseries ??}}{??}%
}%
}%
\@ifdefinable\RetrieveSentence{%
\DeclareRobustCommand\RetrieveSentence[1]{%
\texorpdfstring{\zref@refused{#1}}{}%
\zref@extractdefault{#1}{storedsentence}{\RetrieveSentence@RefUndefText}%
}%
}%
}{%
\@ifdefinable\RetrieveSentence@RefUndefText{%
\DeclareRobustCommand\RetrieveSentence@RefUndefText{%
\nfss@text{\reset@font\bfseries ??}%
}%
}%
\@ifdefinable\RetrieveSentence{%
\DeclareRobustCommand\RetrieveSentence[1]{%
\zref@refused{#1}%
\zref@extractdefault{#1}{storedsentence}{\RetrieveSentence@RefUndefText}%
}%
}%
}%
%
%\zref@newprop{storedsentence}[\RetrieveSentence@RefUndefText]{}%
%\@ifdefinable\StoreSentence{%
% \DeclareRobustCommand\StoreSentence[2]{%
% \begingroup
% \zref@setcurrent{storedsentence}{#2}%
% \zref@labelbyprops{#1}{storedsentence}%
% \endgroup
% #2%
% }%
%}%
\makeatother
\begin{document}
Let's retrieve the sentence associated to the label FirstSentence in A.tex:
\RetrieveSentence{FromA:FirstSentence}
\bigskip
Let's retrieve the sentence associated to the label SecondSentence in A.tex:
\RetrieveSentence{FromA:SecondSentence}
\end{document}
只要A.tex
和A.aux
的重复编译A.tex
可用,就会重复编译B.tex
而不删除编译之间的 .aux 文件,直到出现类似以下消息
Package rerunfilecheck Warning: File `B.out' has changed.
(rerunfilecheck) Rerun to get outlines right
(rerunfilecheck) or use package `bookmark'.
和
LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right.
终端上不再显示收益B.pdf
:
注意事项和可能的陷阱:
当您更改时
A.tex
,您需要A.tex
重复编译以创建A.aux
和A.pdf
以反映更改,然后B.tex
重复编译以创建也B.pdf
反映更改的A.tex
。在将相应数据写入 .aux 文件时,跨文档交叉引用的文本中出现的命令/控制序列将不会被扩展:
A.tex
如果在要复制的地方使用命令/控制序列(例如表示数学符号) ,则必须确保这些命令/控制序列B.tex
也在中定义。例如,如果中的数学符号A.tex
来自 amssymb 包,那么B.tex
也需要加载该包。由底层命令/控制序列表示的编号部分,如
\section{...}
或\begin{equation}
也将是一个问题,因为底层控制序列也不会扩展。为了解决这个问题,你可能需要将一个放入
\label
其中,使每个编号的东西都可以交叉引用。然后你就可以通过包A.tex
检索其中的数据B.tex
負責/xr-hyper。如果你还想复制编号的项目,保留编号,那么可能包文档条是更好的选择。
在上述示例中,B.pdf
您有来自A.tex
/ 的文本短语A.aux
。但是您没有B.pdf
指向 中相应位置的超链接A.pdf
。
如果你需要超链接,你可以加载超链接-package 并\StoreSentence
创建一个命名的目的地/锚点,并将该目的地/锚点的名称存储在 zref-label 中。然后\RetrieveSentence
可以检索该信息以将所有内容包装到超链接中。在下面的示例中,计数器SentenceCounter
用于自动生成命名目的地/锚点的唯一名称。在下面的示例中,宏\RetrieveSentence
带有一个“带星号的变体”,它不会创建超链接。
A.tex
:
\documentclass{article}
\usepackage[unicode=true, pdfnewwindow]{hyperref}
% The code between \makeatletter..\makeatother can go into a package/a .sty-file
% of its own. If the hyperref-package shall be used, then that .sty-file must
% be loaded _after_ the hyperref-package.
\makeatletter
\RequirePackage[xr]{zref}%
\zref@newlist{StoreAndRetrieveSentence}%
\zref@newprop{storedsentence}[\RetrieveSentence@RefUndefText]{}%
\zref@addprop{StoreAndRetrieveSentence}{storedsentence}%
\newcounter{SentenceCounter}%
\@ifpackageloaded{hyperref}{%
\zref@newprop{NameOfDestination}[]{}%
\zref@addprop{StoreAndRetrieveSentence}{NameOfDestination}%
\@ifdefinable\@hashchar{\edef\@hashchar{\string#}}%
\@ifdefinable\RetrieveSentence@RefUndefText{%
\DeclareRobustCommand\RetrieveSentence@RefUndefText{%
\texorpdfstring{\nfss@text{\reset@font\bfseries ??}}{??}%
}%
}%
\@ifdefinable\RetrieveSentence{%
\DeclareRobustCommand\RetrieveSentence{%
\@ifstar\RetrieveSentenceAtStar\RetrieveSentenceAtNoStar
}%
}%
\newcommand\RetrieveSentenceAtNoStar[1]{%
\texorpdfstring{%
\zref@refused{#1}%
\zref@ifrefundefined{#1}{\@firstofone}{%
\zref@ifrefcontainsprop{#1}{NameOfDestination}{%
\zref@ifrefcontainsprop{#1}{externaldocument}{%
\href[pdfnewwindow=true]{%
\zref@extractdefault{#1}{externaldocument}{}%
\@hashchar
\zref@extractdefault{#1}{NameOfDestination}{}%
}%
}{%
\hyperlink{\zref@extractdefault{#1}{NameOfDestination}{}}%
}%
}{\@firstofone}%
}%
}{\@firstofone}%
{%
\zref@extractdefault{#1}{storedsentence}{\RetrieveSentence@RefUndefText}%
}%
}%
\newcommand\RetrieveSentenceAtStar[1]{%
\texorpdfstring{\zref@refused{#1}}{}%
\zref@extractdefault{#1}{storedsentence}{\RetrieveSentence@RefUndefText}%
}%
\@ifdefinable\StoreSentence{%
\DeclareRobustCommand\StoreSentence[2]{%
\texorpdfstring{%
\stepcounter{SentenceCounter}%
\hypertarget{SentenceDestination.\arabic{SentenceCounter}}{#2}%
\begingroup
\zref@setcurrent{storedsentence}{#2}%
\zref@setcurrent{NameOfDestination}{SentenceDestination.\arabic{SentenceCounter}}%
\zref@labelbylist{#1}{StoreAndRetrieveSentence}%
\endgroup
}{%
\zref@extractdefault{#1}{storedsentence}{\RetrieveSentence@RefUndefText}%
}%
}%
}%
}{%
\@ifdefinable\RetrieveSentence@RefUndefText{%
\DeclareRobustCommand\RetrieveSentence@RefUndefText{%
\nfss@text{\reset@font\bfseries ??}%
}%
}%
\@ifdefinable\RetrieveSentence{%
\DeclareRobustCommand\RetrieveSentence{%
\@ifstar\RetrieveSentenceAtStar\RetrieveSentenceAtNoStar
}%
}%
\newcommand\RetrieveSentenceAtStar[1]{%
\zref@refused{#1}%
\zref@extractdefault{#1}{storedsentence}{\RetrieveNumber@RefUndefText}%
}%
\newcommand\RetrieveSentenceAtNoStar[1]{%
\zref@refused{#1}%
\zref@extractdefault{#1}{storedsentence}{\RetrieveNumber@RefUndefText}%
}%
\@ifdefinable\StoreSentence{%
\DeclareRobustCommand\StoreSentence[2]{%
\stepcounter{SentenceCounter}%
#2%
\begingroup
\zref@setcurrent{storedsentence}{#2}%
\zref@labelbylist{#1}{StoreAndRetrieveSentence}%
\endgroup
}%
}%
}%
\makeatother
\begin{document}
Let's retrieve the sentence associated to the label FirstSentence in A.tex with hyperlink:
\RetrieveSentence{FirstSentence}
\bigskip
Let's retrieve the sentence associated to the label SecondSentence in A.tex with hyperlink:
\RetrieveSentence{SecondSentence}
\bigskip
Let's retrieve the sentence associated to the label FirstSentence in A.tex without hyperlink:
\RetrieveSentence*{FirstSentence}
\bigskip
Let's retrieve the sentence associated to the label SecondSentence in A.tex without hyperlink:
\RetrieveSentence*{SecondSentence}
\bigskip\noindent\hrule\bigskip
Let's create the labels:
\vfill
This is some text which does not go to a label.
%\textbf{%
\StoreSentence{FirstSentence}{This is some text which in A.tex went to the label FirstSentence.}%
%}
\vfill
This is some text which does not go to a label.
%\textbf{%
\StoreSentence{SecondSentence}{This is some text which in A.tex went to the label SecondSentence.}%
%}
\vfill
\end{document}
A.pdf
:
B.tex
:
\documentclass{article}
\usepackage[unicode=true, pdfnewwindow]{hyperref}
% The code between \makeatletter..\makeatother can go into a package/a .sty-file
% of its own. If the hyperref-package shall be used, then that .sty-file must
% be loaded _after_ the hyperref-package.
\makeatletter
\RequirePackage[xr]{zref}%
\zref@newlist{StoreAndRetrieveSentence}%
\zref@newprop{storedsentence}[\RetrieveSentence@RefUndefText]{}%
\zref@addprop{StoreAndRetrieveSentence}{storedsentence}%
\newcounter{SentenceCounter}%
\@ifpackageloaded{hyperref}{%
\zref@newprop{NameOfDestination}[]{}%
\zref@addprop{StoreAndRetrieveSentence}{NameOfDestination}%
\@ifdefinable\@hashchar{\edef\@hashchar{\string#}}%
\@ifdefinable\RetrieveSentence@RefUndefText{%
\DeclareRobustCommand\RetrieveSentence@RefUndefText{%
\texorpdfstring{\nfss@text{\reset@font\bfseries ??}}{??}%
}%
}%
\@ifdefinable\RetrieveSentence{%
\DeclareRobustCommand\RetrieveSentence{%
\@ifstar\RetrieveSentenceAtStar\RetrieveSentenceAtNoStar
}%
}%
\newcommand\RetrieveSentenceAtNoStar[1]{%
\texorpdfstring{%
\zref@refused{#1}%
\zref@ifrefundefined{#1}{\@firstofone}{%
\zref@ifrefcontainsprop{#1}{NameOfDestination}{%
\zref@ifrefcontainsprop{#1}{externaldocument}{%
\href[pdfnewwindow=true]{%
\zref@extractdefault{#1}{externaldocument}{}%
\@hashchar
\zref@extractdefault{#1}{NameOfDestination}{}%
}%
}{%
\hyperlink{\zref@extractdefault{#1}{NameOfDestination}{}}%
}%
}{\@firstofone}%
}%
}{\@firstofone}%
{%
\zref@extractdefault{#1}{storedsentence}{\RetrieveSentence@RefUndefText}%
}%
}%
\newcommand\RetrieveSentenceAtStar[1]{%
\texorpdfstring{\zref@refused{#1}}{}%
\zref@extractdefault{#1}{storedsentence}{\RetrieveSentence@RefUndefText}%
}%
\@ifdefinable\StoreSentence{%
\DeclareRobustCommand\StoreSentence[2]{%
\texorpdfstring{%
\stepcounter{SentenceCounter}%
\hypertarget{SentenceDestination.\arabic{SentenceCounter}}{#2}%
\begingroup
\zref@setcurrent{storedsentence}{#2}%
\zref@setcurrent{NameOfDestination}{SentenceDestination.\arabic{SentenceCounter}}%
\zref@labelbylist{#1}{StoreAndRetrieveSentence}%
\endgroup
}{%
\zref@extractdefault{#1}{storedsentence}{\RetrieveSentence@RefUndefText}%
}%
}%
}%
}{%
\@ifdefinable\RetrieveSentence@RefUndefText{%
\DeclareRobustCommand\RetrieveSentence@RefUndefText{%
\nfss@text{\reset@font\bfseries ??}%
}%
}%
\@ifdefinable\RetrieveSentence{%
\DeclareRobustCommand\RetrieveSentence{%
\@ifstar\RetrieveSentenceAtStar\RetrieveSentenceAtNoStar
}%
}%
\newcommand\RetrieveSentenceAtStar[1]{%
\zref@refused{#1}%
\zref@extractdefault{#1}{storedsentence}{\RetrieveNumber@RefUndefText}%
}%
\newcommand\RetrieveSentenceAtNoStar[1]{%
\zref@refused{#1}%
\zref@extractdefault{#1}{storedsentence}{\RetrieveNumber@RefUndefText}%
}%
\@ifdefinable\StoreSentence{%
\DeclareRobustCommand\StoreSentence[2]{%
\stepcounter{SentenceCounter}%
#2%
\begingroup
\zref@setcurrent{storedsentence}{#2}%
\zref@labelbylist{#1}{StoreAndRetrieveSentence}%
\endgroup
}%
}%
}%
\makeatother
% Let's import the zref-cross-referencing-labels from A.tex/A.aux:
%\zexternaldocument[<prefix to add to names of imported labels>]{<external document>}[<url>]
\zexternaldocument[FromA:]{A}[./A.pdf] %<- hyperlinks must go to A.pdf !!!
\begin{document}
Let's retrieve the sentence associated to the label FirstSentence in A.tex with hyperlink:
\RetrieveSentence{FromA:FirstSentence}
\bigskip
Let's retrieve the sentence associated to the label SecondSentence in A.tex with hyperlink:
\RetrieveSentence{FromA:SecondSentence}
\bigskip
Let's retrieve the sentence associated to the label FirstSentence in A.tex without hyperlink:
\RetrieveSentence*{FromA:FirstSentence}
\bigskip
Let's retrieve the sentence associated to the label SecondSentence in A.tex without hyperlink:
\RetrieveSentence*{FromA:SecondSentence}
\end{document}
B.pdf
:
注意事项和可能的陷阱:
当您更改时
A.tex
,您需要A.tex
重复编译以创建A.aux
和A.pdf
以反映更改,然后B.tex
重复编译以创建也B.pdf
反映更改的A.tex
。在将相应数据写入 .aux 文件时,跨文档交叉引用的文本中出现的命令/控制序列将不会被扩展:
A.tex
如果在要复制的地方使用命令/控制序列(例如表示数学符号) ,则必须确保这些命令/控制序列B.tex
也在中定义。例如,如果中的数学符号A.tex
来自 amssymb 包,那么B.tex
也需要加载该包。由底层命令/控制序列表示的编号部分,如
\section{...}
或\begin{equation}
也将是一个问题,因为底层控制序列也不会扩展。为了解决这个问题,你可能需要将一个放入
\label
其中,使每个编号的东西都可以交叉引用。然后你就可以通过包A.tex
检索其中的数据B.tex
負責/xr-hyper。如果你还想复制编号的项目,保留编号,那么可能包文档条是更好的选择。
答案2
textref.sty
创建一个包含以下内容的文件:
\newcommand\save[2]{%
\@bsphack\protected@write\@auxout{}{\string\newtext{#1}{#2}}\@esphack
\newtext{#1}{#2}%
}
\newcommand\newtext[2]{\global\@namedef{text:#1}{#2}}
\newcommand\recall[1]{%
\ifcsname text:#1\endcsname
\@nameuse{text:#1}%
\else
\textbf{??? Unknown Text ???}%
\fi
}
\newcommand\saveAndRecall[2]{\save{#1}{#2}\recall{#1}}
\DeclareOption*{\PassOptionsToPackage{\CurrentOption}{xr}}
\ProcessOptions\relax
\RequirePackage{xr}
\RequirePackage{xpatch}
\xpatchcmd\XR@test{\fi\fi\fi}{\else\ifx#1\newtext\let\XR@tempa\@firstoftwo\fi\fi\fi\fi}{}{}
textref.sty
定义三个命令:
\save{label}{text}
... 可text
通过以下方式访问label
\recall{label}
...替换label
为相应的已保存text
\saveAndRecall{label}{text}
... 结合上面两个命令,即保存text
和label
打印text
此外,该包会加载该xr
包;传递给的任何选项textref
都会转发给该xr
包,以便其全部功能也可用。
在文档的序言中,使用以下命令加载软件包
\usepackage{textref}
与 和\label
一样\ref
,您必须运行 (pdf/xe/lua)latex 两次来传播信息。
这也适用于跨文件边界。你只需要.aux
使用以下方式在序言中包含外部文件:
\externaldocument{A}
以下是一个例子:
% A.tex
\documentclass{article}
\usepackage{textref}
\begin{document}
\section*{A.tex}
William Shakespeare once wrote: ``\saveAndRecall{hamlet}{Two beer or not two beer!}''.
Or did he?
\end{document}
% B.tex
\documentclass{article}
\usepackage{textref}
\externaldocument{A}
\begin{document}
\section*{B.tex}
\recall{hamlet}
\end{document}
先排版A.tex
,然后B.tex
。
答案3
如果您希望使用或多或少相同的“骨架”/框架A.tex
,B.tex
那么包文档条可能是你的朋友:
包裹文档条可以将标签放入以注释开头的 .tex 源文件中%
,因此通常看起来像注释,并申请docstrip.tex
读取该 .tex 源文件并通过命令\generate
提取/复制嵌套在标签之间的部分到其他/新创建的 .tex 文件。
您可以使用它来生成大致相同文档的不同变体。
如果您编译下面的示例both.tex
,则不会创建任何 .pdf 文件,但会创建一个文件A.tex
和一个内容略有不同的文件。B.tex
以下面的例子为例both.tex
,标记为
%<*A,B>
...
%</A,B>
A.tex
在生成时和生成时都会被处理B.tex
。
标记为的事物
%<*A>
...
%</A>
仅在生成时才会被处理A.tex
。
标记为的事物
%<*B>
...
%</B>
仅在生成时才会被处理B.tex
。
标签的嵌套很重要:
如果你
%<*A,B>
This (first) phrase winds up both in A.tex and in B.tex
%<*A>
This (second) phrase winds up in A.tex only.
%</A>
%<*B>
This (third) phrase winds up in B.tex only.
%</B>
%</A,B>
,那么短语提供的陈述就是正确的。
如果你
%<*A>
This (first) phrase winds up in A.tex only.
%<*A,B>
This (second) phrase winds up both in A.tex and in B.tex
%</A,B>
%<*B>
This (third) phrase winds up in B.tex only.
%</B>
%</A>
, 然后
- 第一个短语形成的陈述是正确的。
- 第二个短语形成的陈述是错误的,因为该短语也将以 only 结尾
A.tex
。 - 第三个短语形成的陈述是错误的,因为该短语既不会以 结束,
A.tex
也不会以 结束B.tex
。
both.tex
:
%<*ignore>
% Section with docstrip directives for generating different
% .tex-input-files:
\input docstrip
\declarepreamble\DocumentA
____________________________
Information relevant to A.tex.
\endpreamble
\declarepreamble\DocumentB
____________________________
Information relevant to B.tex.
\endpreamble
\generate{%
\nopostamble
%
\usepreamble\DocumentA
\file{A.tex}{\from{\jobname.tex}{A}}%
%
\usepreamble\DocumentB
\file{B.tex}{\from{\jobname.tex}{B}}%
}%
% If you can take the risk of compiling both.tex
% with option "--enable-write18", then here you can probably insert
% \write18-calls suitable for your platform for calling pdflatex
% from console for compiling the files just generated -- something like:
%
% \immediate\write18{pdflatex A.tex}
% \immediate\write18{pdflatex B.tex}
%
% or:
%
% \immediate\write18{pdftexify A.tex}
% \immediate\write18{pdftexify B.tex}
%
% or:
%
% \immediate\write18{latexmk -pdf A.tex}
% \immediate\write18{latexmk -pdf B.tex}
%
% If LuaTeX-based LaTeX-engines might also be in use, where no "native"
% `\write18` is available:
%
% \RequirePackage{shellesc} % See: https://ctan.org/pkg/shellesc
% %
% \ShellEscape{latexmk -pdflatex=lualatex -pdf A.tex}
% \ShellEscape{latexmk -pdflatex=lualatex -pdf B.tex}
% ...
\csname stop\endcsname % <- end this TeX-run in case you used (pdf)LaTeX
% for generating the files.
%
\bye % <- end this TeX-run in case you used (pdf)TeX for generating the
% % files.
%
%</ignore>
% Section containing the actual LaTeX document, with tags for
% generating different variants
%
%<*A,B>
\documentclass{article}
\makeatletter
\newcommand\FirstOfOne[1]{#1}
\makeatother
\usepackage{amssymb}
\newtheorem{para}{para}[section]
\begin{document}
\section{A section about paras}
%<*A>
\begin{para}
The Kalman filter is an efficient recursive filter that estimates the
internal state of a linear dynamic system from a series of noisy
measurements. It is used in a wide range of engineering and econometric
applications from radar and computer vision to estimation of structural
macroeconomic models, and is an important topic in control theory and
control systems engineering.
\end{para}
%</A>
%<*B>
\stepcounter{para}%
%</B>
\begin{para}
%<*A>
Together with the linear-quadratic regulator (LQR), the Kalman filter
solves the linear–quadratic–Gaussian control problem (LQG).
%</A>
The Kalman filter, the linear-quadratic regulator, and the linear–
quadratic–Gaussian controller are solutions to what arguably are the
most fundamental problems in control theory.
\end{para}
\begin{para}
In most applications, the internal state is much larger (more degrees of
freedom) than the few "observable" parameters which are measured.
%<*A>
However, by combining a series of measurements, the Kalman filter can
estimate the entire internal state.
%</A>
\end{para}
\begin{para}
The symbol \FirstOfOne{\checkmark} comes from amssymb.
\end{para}
\end{document}
%</A,B>
编译both.tex
交付
A.tex
内容如下:
%%
%% This is file `A.tex',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% both.tex (with options: `A')
%% ____________________________
%%
%% Information relevant to A.tex.
%%
\documentclass{article}
\makeatletter
\newcommand\FirstOfOne[1]{#1}
\makeatother
\usepackage{amssymb}
\newtheorem{para}{para}[section]
\begin{document}
\section{A section about paras}
\begin{para}
The Kalman filter is an efficient recursive filter that estimates the
internal state of a linear dynamic system from a series of noisy
measurements. It is used in a wide range of engineering and econometric
applications from radar and computer vision to estimation of structural
macroeconomic models, and is an important topic in control theory and
control systems engineering.
\end{para}
\begin{para}
Together with the linear-quadratic regulator (LQR), the Kalman filter
solves the linear–quadratic–Gaussian control problem (LQG).
The Kalman filter, the linear-quadratic regulator, and the linear–
quadratic–Gaussian controller are solutions to what arguably are the
most fundamental problems in control theory.
\end{para}
\begin{para}
In most applications, the internal state is much larger (more degrees of
freedom) than the few "observable" parameters which are measured.
However, by combining a series of measurements, the Kalman filter can
estimate the entire internal state.
\end{para}
\begin{para}
The symbol \FirstOfOne{\checkmark} comes from amssymb.
\end{para}
\end{document}
B.tex
内容如下:
%%
%% This is file `B.tex',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% both.tex (with options: `B')
%% ____________________________
%%
%% Information relevant to B.tex.
%%
\documentclass{article}
\makeatletter
\newcommand\FirstOfOne[1]{#1}
\makeatother
\usepackage{amssymb}
\newtheorem{para}{para}[section]
\begin{document}
\section{A section about paras}
\stepcounter{para}%
\begin{para}
The Kalman filter, the linear-quadratic regulator, and the linear–
quadratic–Gaussian controller are solutions to what arguably are the
most fundamental problems in control theory.
\end{para}
\begin{para}
In most applications, the internal state is much larger (more degrees of
freedom) than the few "observable" parameters which are measured.
\end{para}
\begin{para}
The symbol \FirstOfOne{\checkmark} comes from amssymb.
\end{para}
\end{document}
编译A.tex
结果A.pdf
:
编译B.tex
结果B.pdf
:
A.tex
如果你希望在和中出现的短语B.tex
成为从一个文件指向另一个文件的超链接,那么你可以加载包 xr-hyper 和 hyperref 以及
- 有
A.tex
一个用于从和\externaldocument
导入交叉引用标签的命令B.tex
- 有
B.tex
一个用于从和\externaldocument
导入交叉引用标签的命令A.tex
- wih
A.tex
和 withB.tex
都有一个命令 ,它将两者转变为命名的目的地/超目标(可以在另一个文件的超链接中表示)并转变为超链接(指向另一个文件相应的命名目的地)。
\InterLink{⟨referencing-label⟩}{⟨text⟩}
⟨text⟩
both.tex
:
(这次我添加了一些内容\vfill
,因此当以较大的缩放比例查看时,您可以测试超链接/导航。)
%<*ignore>
% Section with docstrip directives for generating different
% .tex-input-files:
\input docstrip
\declarepreamble\DocumentA
____________________________
Information relevant to A.tex.
\endpreamble
\declarepreamble\DocumentB
____________________________
Information relevant to B.tex.
\endpreamble
\generate{%
\nopostamble
%
\usepreamble\DocumentA
\file{A.tex}{\from{\jobname.tex}{A}}%
%
\usepreamble\DocumentB
\file{B.tex}{\from{\jobname.tex}{B}}%
}%
% If you can take the risk of compiling both.tex
% with option "--enable-write18", then here you can probably insert
% \write18-calls suitable for your platform for calling pdflatex
% from console for compiling the files just generated -- something like:
%
% \immediate\write18{pdflatex A.tex}
% \immediate\write18{pdflatex B.tex}
%
% or:
%
% \immediate\write18{pdftexify A.tex}
% \immediate\write18{pdftexify B.tex}
%
% or:
%
% \immediate\write18{latexmk -pdf A.tex}
% \immediate\write18{latexmk -pdf B.tex}
%
% If LuaTeX-based LaTeX-engines might also be in use, where no "native"
% `\write18` is available:
%
% \RequirePackage{shellesc} % See: https://ctan.org/pkg/shellesc
% %
% \ShellEscape{latexmk -pdflatex=lualatex -pdf A.tex}
% \ShellEscape{latexmk -pdflatex=lualatex -pdf B.tex}
% \ShellEscape{latexmk -pdflatex=lualatex -pdf A.tex}
% \ShellEscape{latexmk -pdflatex=lualatex -pdf B.tex}
% ...
\csname stop\endcsname % <- end this TeX-run in case you used (pdf)LaTeX
% for generating the files.
%
\bye % <- end this TeX-run in case you used (pdf)TeX for generating the
% % files.
%
%</ignore>
% Section containing the actual LaTeX document, with tags for
% generating different variants
%
%<*A,B>
\documentclass{article}
\makeatletter
\newcommand\FirstOfOne[1]{#1}
\newcommand*\InterLink[2]{%
\texorpdfstring{%
\hypertarget{\@currentHref.label.#1}{%
%<A> \hyperref[{FromB:#1}]% If A.pdf shall not contain hyperlinks to B.pdf, do instead: \@firstofone
%<B> \hyperref[{FromA:#1}]% If B.pdf shall not contain hyperlinks to A.pdf, do instead: \@firstofone
{#2}%
}%
\begingroup
\expandafter\def\expandafter\@currentHref\expandafter{\@currentHref.label.#1}%
\label{#1}%
\endgroup
}{#2}%
}%
\makeatother
\usepackage{xr-hyper}
\usepackage[unicode=true, pdfnewwindow]{hyperref}
%<A>\externaldocument[FromB:]{B}[./B.pdf]
%<B>\externaldocument[FromA:]{A}[./A.pdf]
\usepackage{amssymb}
\newtheorem{para}{para}[section]
\begin{document}
\section{A section about paras}
%<*A>
\begin{para}
The Kalman filter is an efficient recursive filter that estimates the
internal state of a linear dynamic system from a series of noisy
measurements. It is used in a wide range of engineering and econometric
applications from radar and computer vision to estimation of structural
macroeconomic models, and is an important topic in control theory and
control systems engineering.
\end{para}
\vfill
%</A>
%<*B>
\stepcounter{para}%
%</B>
\begin{para}
%<*A>
Together with the linear-quadratic regulator (LQR), the Kalman filter
solves the linear–quadratic–Gaussian control problem (LQG).
%</A>
\InterLink{para1.2}{%
The Kalman filter, the linear-quadratic regulator, and the linear–
quadratic–Gaussian controller are solutions to what arguably are the
most fundamental problems in control theory.%
}%
\end{para}
\vfill
\begin{para}
\InterLink{para1.3}{%
In most applications, the internal state is much larger (more degrees of
freedom) than the few "observable" parameters which are measured.%
}%
%<*A>
However, by combining a series of measurements, the Kalman filter can
estimate the entire internal state.
%</A>
\end{para}
\vfill
\begin{para}
\InterLink{para1.4}{%
The symbol \FirstOfOne{\checkmark} comes from amssymb.%
}%
\end{para}
\end{document}
%</A,B>
编译both.tex
收益
A.tex
:
%%
%% This is file `A.tex',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% both.tex (with options: `A')
%% ____________________________
%%
%% Information relevant to A.tex.
%%
\documentclass{article}
\makeatletter
\newcommand\FirstOfOne[1]{#1}
\newcommand*\InterLink[2]{%
\texorpdfstring{%
\hypertarget{\@currentHref.label.#1}{%
\hyperref[{FromB:#1}]% If A.pdf shall not contain hyperlinks to B.pdf, do instead: \@firstofone
{#2}%
}%
\begingroup
\expandafter\def\expandafter\@currentHref\expandafter{\@currentHref.label.#1}%
\label{#1}%
\endgroup
}{#2}%
}%
\makeatother
\usepackage{xr-hyper}
\usepackage[unicode=true, pdfnewwindow]{hyperref}
\externaldocument[FromB:]{B}[./B.pdf]
\usepackage{amssymb}
\newtheorem{para}{para}[section]
\begin{document}
\section{A section about paras}
\begin{para}
The Kalman filter is an efficient recursive filter that estimates the
internal state of a linear dynamic system from a series of noisy
measurements. It is used in a wide range of engineering and econometric
applications from radar and computer vision to estimation of structural
macroeconomic models, and is an important topic in control theory and
control systems engineering.
\end{para}
\vfill
\begin{para}
Together with the linear-quadratic regulator (LQR), the Kalman filter
solves the linear–quadratic–Gaussian control problem (LQG).
\InterLink{para1.2}{%
The Kalman filter, the linear-quadratic regulator, and the linear–
quadratic–Gaussian controller are solutions to what arguably are the
most fundamental problems in control theory.%
}%
\end{para}
\vfill
\begin{para}
\InterLink{para1.3}{%
In most applications, the internal state is much larger (more degrees of
freedom) than the few "observable" parameters which are measured.%
}%
However, by combining a series of measurements, the Kalman filter can
estimate the entire internal state.
\end{para}
\vfill
\begin{para}
\InterLink{para1.4}{%
The symbol \FirstOfOne{\checkmark} comes from amssymb.%
}%
\end{para}
\end{document}
B.tex
:
%%
%% This is file `B.tex',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% both.tex (with options: `B')
%% ____________________________
%%
%% Information relevant to B.tex.
%%
\documentclass{article}
\makeatletter
\newcommand\FirstOfOne[1]{#1}
\newcommand*\InterLink[2]{%
\texorpdfstring{%
\hypertarget{\@currentHref.label.#1}{%
\hyperref[{FromA:#1}]% If B.pdf shall not contain hyperlinks to A.pdf, do instead: \@firstofone
{#2}%
}%
\begingroup
\expandafter\def\expandafter\@currentHref\expandafter{\@currentHref.label.#1}%
\label{#1}%
\endgroup
}{#2}%
}%
\makeatother
\usepackage{xr-hyper}
\usepackage[unicode=true, pdfnewwindow]{hyperref}
\externaldocument[FromA:]{A}[./A.pdf]
\usepackage{amssymb}
\newtheorem{para}{para}[section]
\begin{document}
\section{A section about paras}
\stepcounter{para}%
\begin{para}
\InterLink{para1.2}{%
The Kalman filter, the linear-quadratic regulator, and the linear–
quadratic–Gaussian controller are solutions to what arguably are the
most fundamental problems in control theory.%
}%
\end{para}
\vfill
\begin{para}
\InterLink{para1.3}{%
In most applications, the internal state is much larger (more degrees of
freedom) than the few "observable" parameters which are measured.%
}%
\end{para}
\vfill
\begin{para}
\InterLink{para1.4}{%
The symbol \FirstOfOne{\checkmark} comes from amssymb.%
}%
\end{para}
\end{document}
编译说明:
A.tex
重复编译。(由于B.tex
尚未编译,因此没有B.aux
,因此有关B
未导入标签的消息不会消失。)- 重复编译
B.tex
。 - 重复编译
A.tex
。(这次B
不会弹出有关未导入标签的消息。A.aux
可能会改变。) - 重复编译
B.tex
。(以确保A.aux
在导入交叉引用标签时考虑到更改。)
你得到A.pdf
:
你得到B.pdf
:
答案4
我能想到的最接近您要求的方法是将粗体文本连接到单个宏 - 这仅在您想在同一个项目中包含 A.tex 和 B.tex 时才会对您有帮助。
请注意,这不会创建一个包含所有粗体文本的文件 B.tex,但您可以使用宏\我的粗体文本在文档的任意位置以显示内容。
% ## In the header:
% Create an empty macro:
\def\myBoldText{}
% Define how text shall be separated in B.tex
\def\mySeparator{\newline}
% Create a command which appends input text to the macro
\newcommand{\addToMyBoldText}[1]{#1% <- you can modify here to always display bold
\expandafter\def\expandafter\myBoldText\expandafter{\myBoldText\mySeparator #1}}
% ## In A.tex
... \addToMyBoldText{The Kalman filter ... in control theory} ...
... \addToMyBoldText{In most applications ... are measured} ...
% ## In B.tex
\myBoldText