导出tex文件源代码

导出tex文件源代码

作为作业的一部分,我必须为 Maple 创建一份培训指南。显然,我需要提交最终的 PDF 文档,但我还需要提交 LaTeX 源代码来证明我是使用 LaTeX 创建该文档的。有没有办法导出源代码,同时保留所有颜色、缩进等?

答案1

这是一种tcolorboxlistings文档本身输入到文件并显示代码的方法。

\documentclass{article}


\usepackage[most]{tcolorbox}

\begin{document}
This is my nice \LaTeXe{} file.

It shows the code of itself:

\tcbinputlisting{breakable,listing file=\jobname.tex,listing only,colback=white!40!yellow,sharp corners}
\end{document}

在此处输入图片描述

对于易碎的盒子:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage[most]{tcolorbox}

\begin{document}
This is my nice \LaTeXe{} file.

It shows the code of it self -- and here is some blind text to make the text longer


Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt. Cras dapibus. Vivamus elementum semper nisi. Aenean vulputate eleifend tellus. Aenean leo ligula, porttitor eu, consequat vitae, eleifend ac, enim. Aliquam lorem ante, dapibus in, viverra quis, feugiat a, tellus. Phasellus viverra nulla ut metus varius laoreet. Quisque rutrum. Aenean imperdiet. Etiam ultricies nisi vel augue. Curabitur ullamcorper ultricies nisi. Nam eget dui. Etiam rhoncus. Maecenas tempus, tellus eget condimentum rhoncus, sem quam semper libero, sit amet adipiscing sem neque sed ipsum. Nam quam nunc, blandit vel, luctus pulvinar, hendrerit id, lorem. Maecenas nec odio et ante tincidunt tempus. Donec vitae sapien ut libero venenatis faucibus. Nullam quis ante. Etiam sit amet orci eget eros faucibus tincidunt. Duis leo. Sed fringilla mauris sit amet nibh. Donec sodales sagittis magna. Sed consequat, leo eget bibendum sodales, augue velit cursus nunc, quis gravida magna mi a libero. Fusce vulputate eleifend sapien. Vestibulum purus quam, scelerisque ut, mollis sed, nonummy id, metus. Nullam accumsan lorem in dui. Cras ultricies mi eu turpis hendrerit fringilla. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; In ac dui quis mi consectetuer lacinia. Nam pretium turpis et arcu. Duis arcu tortor, suscipit eget, imperdiet nec, imperdiet iaculis, ipsum. Sed aliquam ultrices mauris. Integer ante arcu, accumsan a, consectetuer eget, posuere ut, mauris. Praesent adipiscing. Phasellus ullamcorper ipsum rutrum nunc. Nunc nonummy metus. Vestibulum volutpat pretium libero. Cras id dui. Aenean ut 

\tcbinputlisting{breakable,listing file=\jobname.tex,listing only,colback=white!40!yellow,sharp corners}
\end{document}

在此处输入图片描述 在此处输入图片描述

答案2

一种可能性是简单地在逐字环境中输入 TeX 文件。一个非常好的选择是minted具有良好语法高亮显示的包:

\documentclass{article}

\usepackage{minted}
\usepackage{mwe}

\begin{document}

\blinddocument

\clearpage

\inputminted[bgcolor=gray!10]{latex}{will.tex}

\end{document}

最后一页的内容如下:

输出

您可以自定义 minted 中输出的外观。

如果您不喜欢minted,还有其他用于排版代码的软件包,您应该能够以基本相同的方式使用它们。搜索此网站以查看其他一些选项。

答案3

我在源代码中使用了这个结构\LaTeX来给我的学生做练习

\usepackage{verbatim}    
...
\newpage
\emph{
Here is the \LaTeX{} source for this document. You can cut it from the
pdf and use it to start your answers. I used the \verb!\jobname! 
\emph{macro for the source file name, so you can call your file by any
  name you like.}
\verbatiminput{\jobname}
\end{document}

答案4

尝试

\begin{verbatimwrite}{myfile}

\end{verbatimwrite}

相关内容