例如,在教程中显示 .tex 源及其 .pdf 输出的列表

例如,在教程中显示 .tex 源及其 .pdf 输出的列表

假设以下 MWE 是一个教程,我希望在其中讨论另一个文档 SomeTexSource.tex,并希望 (1) 显示其 .tex 源代码列表,以及 (2) 显示由其生成的 .pdf 文档或其部分。列表看起来符合预期,但显示 .pdf 的图形并不完全符合我的期望。大概键值includegraphics pageboxmediaboxcropbox、等是这里成功的关键,但我已经放弃尝试让它们为我工作了。有没有办法 (a) 将 .pdf 显示从整个页面(或页面)修剪为仅包含内容的部分,即修剪空白部分,bleedbox以及(b) 有没有办法有选择地只显示整个文档的部分,例如第 2 节。trimboxartbox

教程:

\documentclass{article}
% RN. 31 March 2019
%=======================
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{listings}
\definecolor{macroscolor}{rgb}{0.8,0.85,1}  % light-blue
\lstset
    {
        breaklines=true
    }

%-----------------------
\begin{document}

\lstset{language=[LaTeX]TeX}
\begin{lstlisting}[basicstyle=\small,backgroundcolor=\color{macroscolor},commentstyle=    \color{red},
caption={SomeTexSource.tex},
label=SomeTexSource.tex]
\documentclass{article}
\begin{document}
If I were to discuss this short document, SomeTexSource.tex, in a tutorial and I would wish to show its listing followed by the .pdf output produced from it, how can something better be achieved than is achieved in my MWE?

\section{First Section}\label{First Section}
Wishing to demonstrate the .pdf generated by SomeTexSource.tex. The whole page is shown, inluding the page number. Is there a way to just show the bits that have content?

\section{Second Section}\label{Second Section}
Is there a way to show just Section \ref{Second Section} and not Section \ref{First Section}, for example?

    Not the world formula: $\prod_{n=1}^{\infty}\frac{4n^2}{4n^2-1}=\frac{\pi}{2}$

\end{document}
\end{lstlisting}

\includegraphics[angle=0,width=1.0\linewidth]{SomeTexSource.pdf}
\end{document}

其中谈到的.tex 源代码:

\documentclass{article}
\begin{document}
If I were to discuss this short document, SomeTexSource.tex, in a tutorial and I would wish to show its listing followed by the .pdf output produced from it, how can something better be achieved than is achieved in my MWE?

\section{First Section}\label{First Section}
Wishing to demonstrate the .pdf generated by SomeTexSource.tex. The whole page is shown, inluding the page number. Is there a way to just show the bits that have content?

\section{Second Section}\label{Second Section}
Is there a way to show just Section \ref{Second Section} and not Section \ref{First Section}, for example?

    Not the world formula: $\prod_{n=1}^{\infty}\frac{4n^2}{4n^2-1}=\frac{\pi}{2}$

\end{document}

相关内容