]> git.lyx.org Git - lyx.git/blob - development/lyx3/johnc
Update scons to the latest FreeBSD patch
[lyx.git] / development / lyx3 / johnc
1 This is part of a private discussion I had with John Collins, the author
2 of the first LaTeX2LyX conversor. Attached is also a document describing his
3 ideas about the subject. Such ideas could be useful for our project.
4
5 Alejandro
6
7 ------------------------------------------------------------
8 From: John Collins <John.Collins@cern.ch>
9 Date: Wed, 4 Sep 1996 11:39:45 +0200 (MET DST)
10 To: Alejandro Aguilar Sierra <asierra@servidor.unam.mx>
11 Subject: Re: TeX2LyX document
12
13 [Removed non-related stuff, AAS]
14
15 I am not convinced devising a lyx format as a subset of latex is ideal.
16 It would take some time to explain my thoughts.  But the problem I see
17 with latex is that its syntax is not pleasant, so that it is relatively
18 time-consuming and/or memory intensive to parse it.  Most importantly from
19 the point of view of an editor, it cannot be locally and bidirectionally
20 parsed.  (I can explain further.)  IMHO, the important matter in the
21 relation to latex is that the format should be in (1-1) correspondence
22 with a suitably rational subset of latex.  Is your format supposed to be
23 just a file format, or will it also be used for the representation of a
24 document in memory?  If the latter is true, then I would particularly stay
25 away from a directly latex based format.  A file format could be closer to
26 latex, since it might need to read by humans.
27
28 But you have obviously thought about the issue and have come to different
29 conclusions.
30
31 My experience in writing ET convinced me that a good internal format is
32 important to speed and to robustness.  ET will run with good speed on an
33 8088 processor(!), whereas the scientific word processor Scientific Word,
34 which has somewhat of the same philosophy as ET and lyx, needs a minimum
35 of a Pentium to be acceptable, and even then it frequently crashes the
36 operating system. (Scientific Word appears to use a latex-based format
37 internally.)
38
39 John Collins
40
41
42 ----------------------------------------------------
43 From: John Collins <collins@phys.psu.edu>
44 Date: Fri, 12 Jan 1996 11:57:23 -0500
45 To: lyx@via.ecp.fr
46 Subject: Latex2lyx
47
48 Although I have been working on the latex2lyx program, I do not have
49 something ready for use yet.  The trouble is that I am staring at
50 several other priority projects including a research grant renewal.
51
52 I realize a quick-and-dirty version would be useful, so perhaps I ought
53 to get that out.  That could probably be done quickly from my
54 preexisting code.  Several messages have provoked me to think that
55 would be worth doing.
56
57 What I realized over the Christmas break is that by a suitable design
58 of C++ classes I can fairly easily make a powerful, efficient and
59 robust (La)TeX parser.  (It would also give useful error messages.)
60 The tricky bit was to figure out the right design.  But I have that
61 now, and the basic program.  I would estimate about a month to get
62 something presentable to the lyx collaboration.
63
64 I have appended some of my thoughts about the overall ideas.  They
65 correspond to what I did for my ET editor.  I'd appreciate comments.
66
67
68 John Collins
69
70 ============================================================
71
72              Latex2lyx convertor
73              ===================
74
75 1.  Latex2lyx and the lyx2latex convertor in the lyx program should be
76 as close to 1-1 as reasonable.  This is particularly important for
77 collaborations where some people are using lyx and some are not.  Then
78 ordinary TeX files serve as the communications medium.
79
80 2.  Perfect 1-1 conversion is not possible, because there are several
81 different TeX constructs that are equivalent (for example a blank line
82 and \par).
83
84 3.  Parts of a TeX file not translated by latex2lyx should be converted
85 into something like LyX TeX style.  One then has raw TeX in the lyx
86 file, and that is reconstructed when making the TeX file.
87
88 4.  Some enhancements to lyx will be necessary to handle converted
89 files sensibly.  (E.g., (a) multiline pieces of raw TeX, including
90 arbitrary numbers of blank lines, (b) comments.)
91
92 5.  It appears necessary to change some of the lyx2latex conversion
93 done by lyx to approach the 1-1 ideal better.  (My preference, for
94 example, would be for paragraphs not to be enclosed in braces,
95 normally.  Paragraphs with font changes, etc would need different
96 treatment, of course.)  User preferences will undoubtedly vary here, so
97 some configuration options are likely to be needed.
98
99 6.  In particular, white space and new lines are often used to prettify
100 TeX files to make them convenient for humans to edit.  I feel it would
101 be useful to provide a mechanism for entering extra space and newlines
102 in a lyx file, not for the purpose of getting the corresponding spaces
103 and newlines in the hard copy, but for making the TeX file pretty.
104 (User preferences will vary here, of course.)  This will not matter
105 much if lyx is the only editor being used, but it will be important if
106 the .tex file is being worked on by a collaborator.  Automatic
107 prettyprinting of the output .tex file would help here, but lyx's
108 preprogrammed concept of prettyprinting may not agree with a user's
109 need-of-the-moment.
110
111 7.  The most general case of a TeX file would be very hard to deal
112 with, since catcodes and TeX macros may be redefined in an arbitrary
113 way.  Moreover the definitions may be hidden away in a TeX format
114 file.  So it is necessary to restrict latex2lyx's scope to files where
115 catcodes don't change, and where the macros don't lose their standard
116 meanings.
117
118 8.  I think all TeX files that I have ever seen satisfy this
119 requirement, except possibly in their preambles where commands are
120 defined or redefined.
121
122 9.  The program should handle incorrect TeX gracefully, and with useful
123 error messages.  At worst it should bundle up the
124 incorrect/misunderstood TeX as uninterpreted raw TeX that would be
125 recreated in the .tex file.  (I emphasize this because one commerical
126 competitor to lyx, Scientific Word (for MS-Windows), does a
127 particularly bad job: it sometimes crashes the operating system when
128 reading correct Latex files, and often loses bits of a file when the
129 structure doesn't correspond to Scientific Word's standards for LaTeX.
130 That is sufficiently unfriendly that I stopped using it.)
131
132 10.  latex2lyx is aimed at converting document contents, not TeX
133 programming, so it need not attempt to understand the semanitics of
134 \defs, \newcommands etc.  (Although it should know the syntax, to parse
135 the commands.)
136
137 11.  Since the most general case of a TeX macro definition is likely to
138 cause indigestion to latex2lyx (and quite often to a human reader, even
139 a TeXpert), there needs to be a mechanism to force latex2lyx to treat
140 sections of the tex file as raw TeX which is not to be converted.  I
141 propose that the conversion be controlled by metacommands (like
142 preprocessor metacommands in C).  These must be TeX comments, so that
143 they are invisible to TeX.
144
145 12.  It would be useful to recognize that other programs might want to
146 use the same mechanism.  I propose the following kind of format:
147
148             %#{}raw
149             %#{}end.raw
150
151
152 The signature of a metacommand is %#{program_name}command ....  The #
153 is reminiscent of a C metacommand.  To allow a mechanism for
154 metacommand sets for different programs, I allow a place for an
155 identifier for a program.  For example we MIGHT have
156
157             %#{lyx}begin.preamble
158             %#{lyx}end.preamble
159
160 for stuff that's to be bundled up in the LaTeX preamble used by lyx.
161 However, for that case, my preference is for latex2lyx to bundle up
162 ALL of the preamble automatically, except for those commands that are
163 specifically used by lyx (e.g., \usepackage).
164