包括示例输出作为整页

包括示例输出作为整页

将示例 LaTeX 输出(以(缩小的)整页形式)包含到讨论其排版的另一个文档中的最佳方法是什么?

我正在考虑创建一个(“例子”) 文档中的所有示例,并为每个示例添加标签\label主要的文档,我将借助負責打包并包含适当的页面范围pdf页面。第一个问题:我可以预期知道每个示例要包含的页数,但我如何知道pdfpages要包含从\pageref{exampleA}\pageref{exampleA}+1?(大概有一些包可以以\pageref{exampleA}+1我可以传递给的形式进行计算pdfpages。但是哪一个呢?)

到目前为止一切顺利。这样做的好处是,示例文档可以很容易地使用与文档不同的样式;但我需要手动确保示例是使用我在主文档中描述的相同代码生成的。这是不是必需的,但可能很方便。也许我还可以以某种方式检索行范围(如何?)并将它们传递给\lstinputlisting列表包裹),但我预计这会带来比它本身更多的麻烦。

有人能推荐更好的工作流程吗?有没有我不知道的更适合的软件包?

总结一下:我对在讨论排版的文档中将整个页面作为示例输出显示的最佳方式感兴趣。包括来自另一个文档的 PDF 页面,以及包括来自另一个 TeX 文件的源代码行,都是可行的方法,但不是一定最好的:我愿意接受其他选择。

答案1

好的,首先我需要一个要插入的多页文档。为了让其他人可以编译它,我从有没有 `\mathrule` 这样的东西?(圆形端盖),这将创建一个 2 页的输出(将此源命名为 useroundrule.tex):

\pdfcompresslevel=0 %%% to see how it works in the pdf code
\documentclass{article}
\usepackage{graphicx}
\usepackage{stackengine}% Used for testing; not needed for \math(v)rule's
\parindent=0pt
\makeatletter

\newcommand\mathrule[3][0pt]{%
  \ifdim#2>#3\math@hrule[#1]{#2}{#3}\else\math@vrule[#1]{#2}{#3}\fi}

\newcommand\math@hrule[3][0pt]{%
  \gdef\mystery@factor{0.07}%
 \@tempdima=#3%
  \rule[#1]{0pt}{#3}% Needed to account for .5\@tempdima vertical offset of rounded rule
  \raisebox{.5\@tempdima+#1}{%
    \makebox[#2][l]{\kern-.5\@tempdima\@@mathrule{#2}{#3}}}%
}

\newcommand\math@vrule[3][0pt]{%
  \gdef\mystery@factor{0.0}%
 \@tempdima=#2%
  \rule[#1]{0pt}{#3}% Needed to account for .5\@tempdima vertical offset of rounded rule
  \raisebox{-.0\@tempdima+#1}{%
    \kern0.5\@tempdima%
    \rotatebox{90}{\kern-0.5\@tempdima\makebox[#3][l]{\@@mathrule{#3}{#2}}}%
    \kern0.5\@tempdima}%
}

\def\@@mathrule#1#2{%
  \@tempdimb=#2%
  \@tempdima=\dimexpr#1-\mystery@factor\@tempdimb%Why 0.07 for \math@hrule?
  \pdfliteral{%
    q []0 d %
    1 J %  set line cap to rounded ends
    \strip@pt\@tempdimb\space w \strip@pt\@tempdimb\space 0 m %
    \strip@pt\@tempdima\space 0 l S Q }}
\makeatother
\begin{document}
\mathrule{60bp}{1bp}\par
\rule{60bp}{1bp}\par
x\mathrule[-1pt]{20bp}{1bp}x\mathrule{20bp}{1bp}x\par
x\rule[-1pt]{20bp}{1bp}x\rule{20bp}{1bp}x\par
\stackunder[2pt]{\rule{60bp}{3bp}}{\mathrule{60bp}{3bp}}\par
\fbox{\mathrule[-1ex]{4ex}{.5ex}}\fbox{\rule[-1ex]{4ex}{.5ex}}\par
\fbox{\mathrule[+1ex]{4ex}{.5ex}}\fbox{\rule[+1ex]{4ex}{.5ex}}\par
\clearpage
\mathrule{1bp}{60bp} \rule{1bp}{60bp}\par
x\mathrule[-1pt]{1bp}{20bp}x\mathrule{1bp}{20bp}x%
  \rule[-1pt]{1bp}{20bp}x\rule{1bp}{20bp}x\par
x\rule[-1pt]{1bp}{20bp}x\rule{1bp}{20bp}x\par
\stackunder[2pt]{\rule{3bp}{10bp}\mathrule{3bp}{10bp}}%
  {\mathrule{3bp}{10bp}\rule{3bp}{10bp}}\par
\fbox{\mathrule[-1ex]{.5ex}{4ex}}\fbox{\rule[-1ex]{.5ex}{4ex}}\par
\fbox{\mathrule[+1ex]{.5ex}{4ex}}\fbox{\rule[+1ex]{.5ex}{4ex}}\par
\end{document}

因此,编译它以生成一个两页文档 (useroundrule.pdf),其中绘制了一些圆形规则图形。现在运行此程序,从 useroundrule.pdf 中抓取两页并将它们插入为整页(带标题)图形:

\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{graphicx}
\usepackage{ifthen}
\newcounter{fnum}\newcounter{countindex}

\def\blahblah{, from my other document}
\begin{document}
\setcounter{fnum}{\thefigure}\addtocounter{fnum}{0}% can use as offset
\fboxsep=0pt
\whiledo{\value{countindex} < 2}{
  \stepcounter{countindex}
  \stepcounter{fnum}
  \begin{figure}[p]
  \fbox{\includegraphics[scale=0.89,trim=48 36 46 60,page=\thefnum]{useroundrule.pdf}}
  \caption{Page \thefnum\blahblah}
  \end{figure}
}
\end{document}

这是插入的第二页的图像:

在此处输入图片描述

在上面的 MWE 中,我缩放和剪切以占据整个文本宽度/文本高度。但是,没有理由不能缩放和剪切到较小尺寸的图像,使用[ht]数字而不是[p]图形等。

这种方法基于我的回答的第二部分将整篇论文放在一张 A0 海报上?

相关内容