如何在同一个乳胶文件中包含 Agda 和 Isabelle 代码?

How to include both Agda and Isabelle code in the same latex file?

我正在使用 beamer 创建演示幻灯片,我想在幻灯片上包含来自 Agda 和 Isabelle 标准库的代码片段。我在网上只能找到从 Agda (lagda) 或 Isabelle (文档准备) 生成乳胶。我想走另一条路,因为我的幻灯片将包含来自不同系统的代码。 我仍然可以使用 lstlisting 或 verbatim,但我不想复制粘贴和重新格式化代码。

我更喜欢包含文件中的行号,或者标签之间的代码

使用 listings 包中的 \lstinputlisting,您可以直接包含源文件中的代码。您可以选择指定开始和结束行号

\documentclass{beamer}
\usepackage{listings}
\lstset{basicstyle=\ttfamily}

\begin{document}

\begin{frame}[fragile]
\lstinputlisting[firstline=1,lastline=7,language=C]{duck.C}
\end{frame}

\begin{frame}[fragile]
\lstinputlisting[firstline=1,lastline=7]{test.agada}
\end{frame}

\begin{frame}[fragile]
\lstinputlisting[firstline=1,lastline=7]{test.isabelle}
\end{frame}

\end{document}

至少对于 Agda,您可以将单个 .lagda 模块渲染到 LaTeX 中。如果你能用 Isabelle 的 pretty-printer 做同样的事情,那么你应该能够手工编写顶级 LaTeX,然后在适当的地方导入(部分)Agda 和 Isabelle-generated LaTeX。

你最好的选择是使用 catchfilebetweentags 包:给定由每种语言各自的 LaTeX 后端生成的两个文件 IsabelleCode.texAgdaCode.tex,你可以捕获一个使用适当的指令在任一文件中打开标记 %<*TAGNAME> 和结束标记 %</TAGNAME>,例如:

\ExecuteMetaData[IsabelleCode.tex]{TAGNAME}
\ExecuteMetaData[AgdaCode.tex]{TAGNAME}