
beamer
對於與該主題相關的演示(在 中)如何在論文中使用 LaTeX在我的大學,我想添加大量 LaTeX 程式碼片段並編譯它們。目前,我.tex
為每個範例都有一個單獨的文件,並單獨編譯每個文件。然後我包含必要的行(例如,沒有序言)lstlisting
並通過 包含已編譯的 PDF \includegraphics
。
這是相當麻煩的。當然,我可以自動編譯數十個文件,例如使用latexmk
,但我必須追蹤並打開這麼多文件。只需在演示文稿中輸入相同的代碼兩次,一次逐字,一次作為純代碼,以便讓 LaTeX 編譯此代碼片段,是最好的選擇,但隨後我必須將所有字體重置為標準article
而不是beamer
,和本地設定(例如與enumitem
) 可能與 中的其他設定衝突beamer
。
您知道最好的解決方案是什麼嗎?
答案1
tcblisting
從包裝上看一下tcolorbox
。它允許自動顯示來源和結果。
這是一個幫助您入門的簡短範例,但請查看文檔,因為它帶有大量用於自訂結果的選項:
% !TeX program = txs:///arara
% arara: pdflatex: {synctex: on, interaction: nonstopmode, shell: yes}
\documentclass{beamer}
\usepackage[most]{tcolorbox}
\begin{document}
\begin{frame}[fragile]
\begin{tcblisting}{before lower=\rmfamily}
\LaTeX\ example with serif font like in article
\end{tcblisting}
\end{frame}
\begin{frame}[fragile]
\begin{tcblisting}{
listing and comment,
pdf comment,
freeze pdf,
compilable listing,
run pdflatex,
}
\documentclass{article}
\usepackage{enumitem}
\begin{document}
\begin{enumerate}
\item test
\end{enumerate}
\end{document}
\end{tcblisting}
\end{frame}
\end{document}