输出纯文本文档而不是 DVI/PDF

输出纯文本文档而不是 DVI/PDF

有没有办法让 LaTeX 生成纯文本(即.txt文件)输出而不是.pdf/.dvi文件?

我正在编写一些很长的手册,并且试图找到一种方法来生成格式如下的漂亮的 ASCII 文档:

########################################################################
HEADING 1
########################################################################

========================================================================
HEADING 2
========================================================================

........................................................................
HEADING 3
........................................................................

Lorem ipsum dolor. Everything here wraps at seventy-two (72) characters so
someone can copy-paste into a Linux mail client, like neomutt or pine.

    Multi-line code snippet that is indented via
    a hard-tab.
    Isn't
    that
    cool?

Aaaaaaaaand....

    Here's a really long code snippet that's allowed to extend past the 72-character margin.

More text.

我选择使用 LaTeX,因为我对它很熟悉,并且文档中会有很多对章节、ASCII 艺术图形等的内部引用,其中一些手册非常庞大(200 多页)。

谢谢。

答案1

如果我采用标准 latex 示例文档sample2e.tex(它应该已经位于你的 tex 输入路径中)并运行latex sample2e以获取 DVI 文件,则会dvi2tty sample2e产生

                  An Example Document



                           Leslie Lamport


                          January 21, 1994



   This is an example input file. Comparing it with the output it generates can
show you how to produce a simple document of your own.



1    Ordinary Text


The ends of words and sentences are marked by spaces. It doesn't matter how
many spaces you type; one is as good as 100.  The end of a line counts as a
space.
   One or more blank lines denote the end of a paragraph.
   Since any number of consecutive spaces are treated like a single one, the fo*
 *r-
matting of the input file makes no difference to LATEX, but it makes a differen*
 *ce
to you. When you use LATEX, making your input file as easy to read as possible
will be a great help as you write your document and when you change it. This
sample file shows how you can add comments to your own input file.
   Because printing is different from typewriting, there are a number of things
that you have to do differently when preparing an input file than if you were j*
 *ust
typing the document directly. Quotation marks like "this" have to be handled
specially, as do quotes within quotes: " `this' is what I just wrote, not `that*
 *' ".
   Dashes come in three sizes: an intra-word dash, a medium dash for number
ranges like 1--2, and a punctuation dash---like this.
   A sentence-ending space should be larger than the space between words
within a sentence. You sometimes have to type special commands in conjunc-
tion with punctuation characters to get this right, as in the following sentenc*
 *e.
Gnats, gnus, etc. all begin with G. You should check the spaces after periods
when reading your output to make sure you haven't forgotten any special cases.
Generating an ellipsis . . . with the right spacing around the periods requires*
 * a
special command.
   LATEX interprets some common characters as commands, so you must type
special commands to generate them. These characters include the following: $
& % # { and }.
   In printing, text is usually emphasized with an italic type style.
   A long segment of text can also be emphasized in this way. Text within such
a segment can be given additional emphasis.



                                  1




   It is sometimes necessary to prevent LATEX from breaking a line where it
might otherwise do so.  This may be at a space, as between the "Mr." and
"Jones" in "Mr. Jones", or within a word---especially when the word is a symbol
like itemnum that makes little sense when hyphenated across lines.
   Footnotes1 pose no problem.
   LATEX is good at typesetting mathematicalPformulas like x - 3y + z = 7 or
a1 > x2n + y2n > x# or (A, B) =   iaibi.  The spaces you type in a formula
are ignored.  Remember that a letter like x is a formula when it denotes a
mathematical symbol, and it should be typed as one.



2    Displayed Text


Text is displayed by indenting it from the left margin. Quotations are commonly
displayed. There are short quotations

     This is a short quotation. It consists of a single paragraph of text.
     See how it is formatted.

and longer ones.

        This is a longer quotation. It consists of two paragraphs of text,
     neither of which are particularly interesting.
        This is the second paragraph of the quotation. It is just as dull
     as the first paragraph.

Another frequently-displayed structure is a list. The following is an example of
an itemized list.

   o This is the first item of an itemized list. Each item in the list is marked
     with a "tick". You don't have to worry about what kind of tick mark is
     used.

   o This is the second item of the list. It contains another list nested inside
     it. The inner list is an enumerated list.

       1. This is the first item of an enumerated list that is nested within the
          itemized list.

       2. This is the second item of the inner list.  LATEX allows you to nest
          lists deeper than you really should.

     This is the rest of the second item of the outer list. It is no more inter*
 *esting
     than any other part of the item.

   o This is the third item of the list.

You can even display poetry.
____________________________1
   This is an example of a footnote.



                                  2




     There is an environment for verse
     Whose features some poets will curse.

     For instead of making
     Them do all line breaking,
     It allows them to put too many words on a line when they'd rather
        be forced to be terse.

   Mathematical formulas may also be displayed. A displayed formula is one-
line long; multiline formulas require special formatting instructions.


                         (#, ##) = x##+ y2 + zni


Don't start a paragraph with a displayed equation, nor make one a paragraph
by itself.



                                  3

与 pdflatex 输出的合理近似

在此处输入图片描述

相关内容