summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/generic/FAQ-en/faq-fmt-conv.tex
blob: 9ad13a1ee2e028c34d2e2a93d9c3ff33fa8f4c9c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
% $Id: faq-fmt-conv.tex,v 1.7 2011/07/21 19:16:13 rf10 Exp rf10 $

\section{Format conversions}

\Question[Q-toascii]{Conversion from \AllTeX{} to plain text}

The aim here is to emulate the Unix \ProgName{nroff}, which formats
text as best it can for the screen, from the same
input as the Unix typesetting program \ProgName{troff}.

Converting \acro{DVI} to plain text is the basis of many of these
techniques; sometimes the simple conversion provides a good enough
response.  Options are:
\begin{itemize}
\item \ProgName{dvi2tty} (one of the earliest),
\item \ProgName{crudetype} and
\item \ProgName{catdvi}, which is capable of generating Latin-1
  (ISO~8859-1) or \acro{UTF}-8 encoded output.  \ProgName{Catdvi} was
  conceived as a replacement for \ProgName{dvi2tty}, but development
  seems to have stopped before the authors were willing to declare the
  work complete.
\end{itemize}
A common problem is the hyphenation that \TeX{} inserts when
typesetting something: since the output is inevitably viewed using
fonts that don't match the original, the hyphenation usually looks
silly.

Ralph Droms provides a \Package{txt} bundle of things in support of
\acro{ASCII} generation,
but it doesn't do a good job with tables and mathematics.

Another possibility is to
use the \LaTeX{}-to-\acro{ASCII} conversion program, \ProgName{l2a},
although this is really more of a de-\TeX{}ing program.

The canonical de-\TeX{}ing program is \ProgName{detex}, which removes
all comments and control sequences 
from its input before writing it to its output.  Its original purpose
was to prepare input for a dumb spelling checker, and it's only usable
for preparing useful \acro{ASCII} versions of a document in highly
restricted circumstances.

\ProgName{Tex2mail} is slightly more than a de-TeX{}er~--- it's a
\ProgName{Perl} script that converts \TeX{} files into
plain text files, expanding various mathematical symbols
(sums, products, integrals, sub/superscripts, fractions, square
roots, \dots{}\@) into ``\acro{ASCII} art'' that spreads over
multiple lines if necessary. The result is more readable to human
beings than the flat-style \TeX{} code.

Another significant possibility is to use one of the
\Qref*{\acro{HTML}-generation solutions}{Q-LaTeX2HTML},
and then to use a browser such as \ProgName{lynx} to dump the resulting
\acro{HTML} as plain text.
\begin{ctanrefs}
\item[catdvi]\CTANref{catdvi}
\item[crudetype]\CTANref{crudetype}
\item[detex]\CTANref{detex}
\item[dvi2tty]\CTANref{dvi2tty}
\item[l2a]\CTANref{l2a}
\item[tex2mail]\CTANref{tex2mail}
\item[txt]\CTANref{txtdist}
\end{ctanrefs}
\LastEdit{2011-07-21}

\Question[Q-SGML2TeX]{Conversion from \acro{SGML} or \acro{HTML} to \protect\TeX{}}

\acro{SGML} is a very important system for document storage and interchange,
but it has no formatting features; its companion \acro{ISO} standard
\acro{DSSSL}
(see \URL{http://www.jclark.com/dsssl/}) is designed for writing
transformations and formatting,
but this has not yet been widely implemented. Some \acro{SGML} authoring
systems (e.g., SoftQuad \ProgName{Author/Editor}) have formatting
abilities, and
there are high-end specialist \acro{SGML} typesetting systems (e.g., Miles33's
\ProgName{Genera}).  However, the majority of \acro{SGML} users probably transform
the source to an existing typesetting system when they want to print. 
\TeX{} is a good candidate for this. There are three approaches to writing a
translator:
\begin{enumerate}
\item Write a free-standing translator in the traditional way, with
  tools like \ProgName{yacc} and \ProgName{lex}; this is hard, in
  practice, because of the complexity of \acro{SGML}.
\item Use a specialist language designed for \acro{SGML} transformations; the
  best known are probably \ProgName{Omnimark} and \ProgName{Balise}.
  They are expensive, but powerful, incorporating \acro{SGML} query and
  transformation abilities as well as simple translation.
\item Build a translator on top of an existing \acro{SGML} parser.  By far
  the best-known (and free!) parser is James Clark's
  \ProgName{nsgmls}, and this produces a much simpler output format,
  called \acro{ESIS}, which can be parsed quite straightforwardly (one also
  has the benefit of an \acro{SGML} parse against the \acro{DTD}). Two
  good public domain packages use this method:
  \begin{itemize}
  \item
\begin{narrowversion} % really non-hyper
      David Megginson's \ProgName{sgmlspm}, written in \ProgName{Perl}
      5, which is available from 
      \URL{http://www.perl.com/CPAN/modules/by-module/SGMLS}
\end{narrowversion}
\begin{wideversion}
      David Megginson's
      \href{http://www.perl.com/CPAN/modules/by-module/SGMLS}{\ProgName{sgmlspm}},
      written in \ProgName{Perl} 5.
\end{wideversion}
    \item
\begin{narrowversion} % really non-hyper
      Joachim Schrod and Christine Detig's \ProgName{STIL}
      (`\acro{SGML} Transformations in Lisp'), which is available from
      \URL{ftp://ftp.tu-darmstadt.de/pub/text/sgml/stil}
\end{narrowversion}
\begin{wideversion}
      Joachim Schrod and Christine Detig's
      \href{ftp://ftp.tu-darmstadt.de/pub/text/sgml/stil}{\ProgName{STIL}},
       (`\acro{SGML} Transformations in Lisp').
\end{wideversion}
  \end{itemize}
  Both of these allow the user to write `handlers' for every \acro{SGML}
  element, with plenty of access to attributes, entities, and
  information about the context within the document tree.

  If these packages don't meet your needs for an average \acro{SGML}
  typesetting job, you need the big commercial stuff.
\end{enumerate}

Since \acro{HTML} is simply an example of \acro{SGML}, we do not need a specific
system for \acro{HTML}.  However, Nathan Torkington developed
% (\Email{Nathan.Torkington@vuw.ac.nz}) 
\ProgName{html2latex} from the \acro{HTML} parser in \acro{NCSA}'s
Xmosaic package.
The program takes an \acro{HTML} file and generates a \LaTeX{} file from it.
The conversion code is subject to \acro{NCSA} restrictions, but the whole
source is available on \acro{CTAN}.

Michel Goossens and Janne Saarela published a very useful summary of
\acro{SGML}, and of public domain tools for writing and manipulating it, in
\TUGboat{} 16(2).
\begin{ctanrefs}
\item[html2latex \nothtml{\rmfamily}source]\CTANref{html2latex}
\end{ctanrefs}

\Question[Q-LaTeX2HTML]{Conversion from \AllTeX{} to \acro{HTML}}

\TeX{} and \LaTeX{} are well suited to producing electronically publishable
documents. However, it is important to realize the difference
between page layout and functional markup. \TeX{} is capable of
extremely detailed page layout; \acro{HTML} is not, because \acro{HTML} is a
functional markup language not a page layout language. \acro{HTML}'s exact
rendering is not specified by the document that is published but is, to
some degree, left to the discretion of the browser. If you require your
readers to see an exact replication of what your document looks like
to you, then you cannot use \acro{HTML} and you must use some other
publishing format such as \acro{PDF}. That is true for any \acro{HTML}
authoring tool.

\TeX{}'s excellent mathematical capabilities remain a challenge in the
business of conversion to \acro{HTML}.  There are only two generally
reliable techniques for generating mathematics on the web: creating
bitmaps of bits of typesetting that can't be translated, and using
symbols and table constructs.  Neither technique is entirely
satisfactory.  Bitmaps lead to a profusion of tiny files, are slow to
load, and are inaccessible to those with visual disabilities.  The
symbol fonts offer poor coverage of mathematics, and their use
requires configuration of the browser.  The future of mathematical
browsing may be brighter~--- see
% beware line break
\Qref[question]{future Web technologies}{Q-mathml}.

For today, possible packages are:
\begin{description}
\item[\ProgName{LaTeX2HTML}]a \ProgName{Perl} script package that
  supports \LaTeX{} only, and generates mathematics (and other
  ``difficult'' things) using bitmaps.  The original version was
  written by Nikos Drakos for Unix systems, but the package now sports
  an illustrious list of co-authors and is also available for Windows
  systems.  Michel Goossens and Janne Saarela published a detailed
  discussion of \ProgName{LaTeX2HTML}, and how to tailor it, in
  \TUGboat{} 16(2).

  A mailing list for users may be found via
  \URL{http://tug.org/mailman/listinfo/latex2html}
\item[\ProgName{TtH}]a compiled program that supports either \LaTeX{}
  or \plaintex{}, and uses the font/table technique for representing
  mathematics.  It is written by Ian Hutchinson, using
  \ProgName{flex}.  The distribution consists of a single \acro{C}
  source (or a compiled executable), which is easy to install and very
  fast-running.
\item[\ProgName{TeX4ht}]a compiled program that supports either
  \LaTeX{} or \plaintex{}, by processing a \acro{DVI} file; it uses
  bitmaps for mathematics, but can also use other technologies where
  appropriate.  Written by Eitan Gurari, it parses the \acro{DVI}
  file generated when you run \AllTeX{} over your file with
  \ProgName{tex4ht}'s macros included.  As a result, it's pretty
  robust against the macros you include in your document, and it's
  also pretty fast.
\item[\ProgName{plasTeX}]a Python-based \LaTeX{} document processing
    framework.  It gives DOM-like access to a \LaTeX{} document, as
    well as the ability to generate mulitple output formats
    (e.g. HTML, DocBook, tBook, etc.).
\item[\ProgName{TeXpider}]a commercial program from
  \Qref*{Micropress}{Q-commercial}, which is
  described on \URL{http://www.micropress-inc.com/webb/wbstart.htm};
  it uses bitmaps for equations.
\item[\ProgName{Hevea}] a compiled program that supports \LaTeX{}
  only, and uses the font/table technique for equations (indeed its
  entire approach is very similar to \ProgName{TtH}).  It is written
  in Objective \acro{CAML} by Luc Maranget.  \ProgName{Hevea} isn't
  archived on \acro{CTAN}; details (including download points) are
  available via \URL{http://pauillac.inria.fr/~maranget/hevea/}
\end{description}
An interesting set of samples, including conversion of the same text
by the four free programs listed above, is available at
\URL{http://www.mayer.dial.pipex.com/samples/example.htm}; a linked
page gives lists of pros and cons, by way of comparison.

The World Wide Web Consortium maintains a list of ``filters'' to
\acro{HTML}, with sections on \AllTeX{} and \BibTeX{}~--- see
\URL{http://www.w3.org/Tools/Word_proc_filters.html}
\begin{ctanrefs}
\item[latex2html]Browse \CTANref{latex2html}
\item[plasTeX]Browse \CTANref{plastex}
\item[tex4ht]\CTANref{tex4ht} (but see \url{http://tug.org/tex4ht/})
\item[tth]\CTANref{tth}
\end{ctanrefs}

\Question[Q-fmtconv]{Other conversions to and from \AllTeX{}}

\begin{description}
\item[troff]\ProgName{Tr2latex}, assists in the translation of a
  \ProgName{troff} document into \LaTeXo{} format.  It recognises most
  |-ms| and |-man| macros, plus most \ProgName{eqn} and some
  \ProgName{tbl} preprocessor commands.  Anything fancier needs to be
  done by hand. Two style files are provided. There is also a man page
  (which converts very well to \LaTeX{}\dots{}).
  \ProgName{Tr2latex} is an enhanced version of the earlier
  \ProgName{troff-to-latex} (which is no longer available).

% The \acro{DECUS} \TeX{} distribution (see
% \Qref[question]{sources of software}{Q-archives})
% also contains a program which converts \ProgName{troff} to \TeX{}.

%\item[Scribe] Mark James (\Email{jamesm@dialogic.com}) has a copy of
%  \ProgName{scribe2latex} he has been unable to test but which he will
%  let anyone interested have. The program was written by Van Jacobson
%  of Lawrence Berkeley Laboratory.%
%  \checked{RF}{1994/11/18}
  
\item[WordPerfect] \ProgName{wp2latex} is actively maintained, and is
  available either for \MSDOS{} or for Unix systems.
\item[\acro{RTF}] \ProgName{Rtf2tex}, by Robert Lupton, is for
  converting Microsoft's Rich Text Format to \TeX{}.  There is also a
  converter to \LaTeX{} by Erwin Wechtl, called \ProgName{rtf2latex}.
  The latest converter, by Ujwal Sathyam and Scott Prahl, is
  \ProgName{rtf2latex2e} which seems rather good, though development
  of it seems to have stalled.

  Translation \emph{to} \acro{RTF} may be done (for a somewhat
  constrained set of \LaTeX{} documents) by \TeX{}2\acro{RTF}, which
  can produce ordinary \acro{RTF}, Windows Help \acro{RTF} (as well as
  \acro{HTML}, \Qref{conversion to HTML}{Q-LaTeX2HTML}).
  \TeX{}2\acro{RTF} is supported on various Unix platforms and under
  Windows~3.1
\item[Microsoft Word] A rudimentary (free) program for converting
  \acro{MS-W}ord to \LaTeX{} is \ProgName{wd2latex}, which runs on \MSDOS{};
  it probably produces output destined for an archaic version of
  \acro{MS-W}ord (the program itself was archived in 1991).

  The current preferred free-software method is a two-stage process:
  \begin{itemize}
  \item Convert \latex{} to \ProgName{OpenOffice} format, using the
    \ProgName{tex4ht} command \ProgName{oolatex};
  \item open the result in \ProgName{OpenOffice} and `save as' a
    \acro{MS-W}ord document.
  \end{itemize}
  (Note that \ProgName{OpenOffice} itself is \emph{not} on
  \acro{CTAN}; see \url{http://www.openoffice.org/}, though most
  \ProgName{linux} systems offer it as a ready-to-install bundle.)

  \ProgName{Word2}\emph{\TeX{}} and \emph{\TeX{}}\ProgName{2Word} are 
  shareware translators from % beware line break
  \href{http://www.chikrii.com/}{Chikrii Softlab}; positive users'
  reports have been noted (but not recently).

  The excellent \ProgName{tex4ht} will generate OpenOffice \acro{ODT}
  format, which can be used as an intermediate to producing Word
  format files.

  If cost is a constraint, the best bet is probably to use an
  intermediate format such as \acro{RTF} or \acro{HTML}.
  \ProgName{Word} outputs and reads both, so in principle this route
  may be useful.

  You can also use \acro{PDF} as an intermediate format: Acrobat Reader
  for Windows (version 5.0 and later) will output rather feeble
  \acro{RTF} that \ProgName{Word} can read.
\item[Excel] \ProgName{Excel2Latex} converts an \ProgName{Excel} file
  into a \LaTeX{} \environment{tabular} environment; it comes as a
  \extension{xls} file which defines some \ProgName{Excel} macros to produce
  output in a new format.
\item[runoff] Peter Vanroose's \ProgName{rnototex}
  conversion program is written in \acro{VMS} Pascal.
  The sources are distributed with a \acro{VAX} executable.
\item[refer/tib] There are a few programs for converting bibliographic
  data between \BibTeX{} and \ProgName{refer}/\ProgName{tib} formats.
  The collection includes a shell script converter from \BibTeX{} to
  \ProgName{refer} format as well. The collection
  is not maintained.
\item[\acro{PC}-Write]\ProgName{pcwritex.arc} is a
  print driver for \acro{PC}-Write that ``prints'' a \acro{PC}-Write
  V2.71 document to a \TeX{}-compatible disk file.  It was written by Peter
  Flynn at University College, Cork, Republic of Ireland.
\end{description}

% beware line breaks
\href{http://www.tug.org/utilities/texconv/index.html}{Wilfried Hennings' \acro{FAQ}},
which deals specifically with conversions between \TeX{}-based formats
and word processor formats, offers much detail as well as tables that
allow quick comparison of features.

A group at Ohio State University (\acro{USA}) is working on
a common document format based on \acro{SGML}, with the ambition that any
format could be
translated to or from this one.  \ProgName{FrameMaker} provides
``import filters'' to aid translation from alien formats
(presumably including \TeX{}) to \ProgName{FrameMaker}'s own.
\begin{ctanrefs}
\item[excel2latex]\CTANref{excel2latex}
\item[pcwritex.arc]\CTANref{pcwritex}
\item[refer and tib tools]\CTANref{refer-tools}
\item[rnototex]\CTANref{rnototex}
\item[rtf2latex]\CTANref{rtf2latex}
\item[rtf2latex2e]\CTANref{rtf2latex2e}
\item[rtf2tex]\CTANref{rtf2tex}
\item[tex2rtf]\CTANref{tex2rtf}
\item[tex4ht]\CTANref{tex4ht} (but see \url{http://tug.org/tex4ht/})
\item[tr2latex]\CTANref{tr2latex}
\item[wd2latex]\CTANref{wd2latex}
\item[wp2latex]\CTANref{wp2latex}
\item[\nothtml{\rmfamily}Word processor \acro{FAQ} (source)]%
  \CTANref{texcnvfaq}
\end{ctanrefs}

\Question[Q-readML]{Using \TeX{} to read \acro{SGML} or \acro{XML} directly}

This can nowadays be done, with a certain amount of clever macro
programming.  David Carlisle's \Package{xmltex} is the prime example;
it offers a solution (of sorts) for typesetting \acro{XML} files.

One use of a \TeX{} that can typeset \acro{XML} files is as a backend
processor for \acro{XSL} formatting objects, serialized as \acro{XML}.
Sebastian Rahtz's Passive\TeX{} uses \Package{xmltex} to
achieve this end.

However, modern usage would proceed via \acro{XSL} or \acro{XSLT}2 to
produce a formattable version.
\begin{ctanrefs}
\item[xmltex]\CTANref{xmltex}
\item[passivetex]\CTANref{passivetex}
\end{ctanrefs}

\Question[Q-recovertex]{Retrieving \AllTeX{} from \acro{DVI}, etc.}

The job just can't be done automatically: \acro{DVI}, \PS{} and
\acro{PDF} are ``final'' formats, supposedly not susceptible to
further editing~--- information about where things came from has been
discarded.  So if you've lost your \AllTeX{} source (or never
had the source of a document you need to work on) you've a serious job
on your hands.  In many circumstances, the best strategy is to retype
the whole document, but this strategy is to be tempered by
consideration of the size of the document and the potential typists'
skills.

If automatic assistance is necessary, it's unlikely that any more than
text retrieval is going to be possible; the \AllTeX{} markup that
creates the typographic effects of the document needs to be recreated
by editing.

If the file you have is in \acro{DVI} format, many of the techniques
for \Qref*{converting \AllTeX{} to \acro{ASCII}}{Q-toascii} are
applicable.  Consider \ProgName{dvi2tty}, \ProgName{crudetype} and
\ProgName{catdvi}.  Remember that there are likely to be problems
finding included material (such as included \PS{} figures, that
don't appear in the \acro{DVI} file itself), and mathematics is
unlikely to convert easily.

To retrieve text from \PS{} files, the
\ProgName{ps2ascii} tool (part of the  \ProgName{ghostscript}
distribution) is available.  One could try applying this tool to
\PS{} derived from an \acro{PDF} file using \ProgName{pdf2ps} (also
from the \ProgName{ghostscript} distribution), or \ProgName{Acrobat}
\ProgName{Reader} itself; an alternative is \ProgName{pdftotext},
which is distributed with \ProgName{xpdf}.

Another avenue available to those with a \acro{PDF} file they want to
process is offered by Adobe \ProgName{Acrobat} (version 5 or later):
you can tag the \acro{PDF} file into an estructured document, output
thence to well-formed \acro{XHTML}, and import the results into
Microsoft \ProgName{Word} (2000 or later).  From there, one may
convert to \AllTeX{} using one of the techniques discussed in
% beware line break
\wideonly{``}\Qref[question]{converting to and from \AllTeX{}}{Q-fmtconv}\wideonly{''}.

The result will typically (at best) be poorly marked-up.  Problems may
also arise from the oddity of typical \TeX{} font encodings (notably
those of the maths fonts), which \ProgName{Acrobat} doesn't know how
to map to its standard Unicode representation.
\begin{ctanrefs}
\item[catdvi]\CTANref{catdvi}
\item[crudetype]\CTANref{crudetype}
\item[dvi2tty]\CTANref{dvi2tty}
\item[ghostscript]Browse \CTANref{ghostscript}
\item[xpdf]Browse \CTANref{xpdf}
\end{ctanrefs}
\LastEdit{2009-05-29}

\Question[Q-LaTeXtoPlain]{Translating \LaTeX{} to \plaintex{}}

Unfortunately, no ``general'', simple, automatic process is likely to
succeed at this task.  See % ! line break
``\Qref*{How does \LaTeX{} relate to \plaintex{}}{Q-LaTeXandPlain}''
for further details.

Translating a document designed to work with \LaTeX{} into one
designed to work with \plaintex{} is likely to amount to carefully
including (or otherwise re-implementing) all those parts of \LaTeX{},
beyond the provisions of \plaintex{}, which the document uses.

Some of this work is has (in a sense) been done, in the port of the
\LaTeX{} graphics package to \plaintex{}.  However, while
\Package{graphics} is available, other complicated packages (notably
\Package{hyperref}) are not.  The aspiring translator may find the
\Qref*{\Eplain{}}{Q-eplain} system a useful source of code.  (In fact,
a light-weight system such as \Eplain{} might reasonably be adopted as
an alternative target of translation, though it undoubtedly gives the
user more than the ``bare minimum'' that \plaintex{} is designed to
offer.)
\begin{ctanrefs}
\item[\nothtml{\begingroup\rmfamily}The\nothtml{\endgroup} eplain \nothtml{\rmfamily}system]%
  \CTANref{eplain}
\item[\nothtml{\begingroup\rmfamily`}\plaintex{}\nothtml{'\endgroup} graphics]%
  \CTANref{graphics-plain}
\end{ctanrefs}
\LastEdit{2011-05-04}