![编写一个用于生成基于文本的输出的 LaTeX 引擎需要什么](https://linux22.com/image/365966/%E7%BC%96%E5%86%99%E4%B8%80%E4%B8%AA%E7%94%A8%E4%BA%8E%E7%94%9F%E6%88%90%E5%9F%BA%E4%BA%8E%E6%96%87%E6%9C%AC%E7%9A%84%E8%BE%93%E5%87%BA%E7%9A%84%20LaTeX%20%E5%BC%95%E6%93%8E%E9%9C%80%E8%A6%81%E4%BB%80%E4%B9%88.png)
作为潜在的后续行动能否使 LaTeX 产生文本输出?生成基于文本的输出(例如纯 ascii/utf-8 文本、html、xml)有多种部分解决方案。据我所知TeX4ht结合使用 LaTeX 和一些魔法来创建一个 dvi 文件,可以从中提取文本。LaTeX转RTF似乎完全绕过了 LaTeX。还有基于Lua的解决方案其中框被写入输出文件。
天真地看来,这似乎是一种潜在的更轻松解决方案是修改 tex 引擎以生成文本文件。显然这会丢失图像等内容,并且格式可能会受到限制。这可以在引擎级别实现吗?
答案1
在 pdftex 或 luatex 中,后端内置于程序中,但在经典 tex(或 xetex)中,tex 程序仅生成一个独立于设备的表示,可以从中构建 pdf 或文本等,使用单独的驱动程序而无需扩展主 tex 可执行文件。texlive 附带 dvi2tty。
例如,标准乳胶测试文档small2e
,pdflatex small2e
使
并latex small2e; dvi2tty small2e
产生
1 Simple Text
Words are separated by one or more spaces. Paragraphs are separated by one
or more blank lines. The output is not affected by adding extra spaces or extra
blank lines to the input file.
Double quotes are typed like this: "quoted text". Single quotes are typed
like this: `single-quoted text'.
Long dashes are typed as three dash characters---like this.
Emphasized text is typed like this: this is emphasized. Bold text is typed
like this: this is bold.
1.1 A Warning or Two
If you get too much space after a mid-sentence period---abbreviations like etc.
are the common culprits)---then type a backslash followed by a space after the
period, as in this sentence.
Remember, don't type the 10 special characters (such as dollar sign and
backslash) except as directed! The following seven are printed by typing a
backslash in front of them: $ & # % _{ and }. The manual tells how to make
other symbols.
请注意,这不仅仅是原始文本,还尝试表明布局已完成,并且换行符与 pdf 版本中的换行符相匹配。