File: trouble.tex

package info (click to toggle)
hevea 2.36-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,780 kB
  • sloc: ml: 19,453; sh: 503; makefile: 311; ansic: 132
file content (248 lines) | stat: -rw-r--r-- 7,979 bytes parent folder | download | duplicates (5)
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
\documentclass{article}

\usepackage{alltt}
\usepackage{hevea}
\newcommand{\rbox}[2]{$^{\mbox{#2}}$}
\newcommand{\lbox}[2]{$_{\mbox{#2}}$}
\begin{latexonly}
\gdef\myrule{\rule{10cm}{.05ex}}
\gdef\htmlout{\begingroup\parskip=0pt\parindent=0pt\begin{quote}\myrule\par}
\gdef\endhtmlout{\par\myrule\end{quote}\endgroup}
\end{latexonly} 
\begin{htmlonly}
\gdef\myrule{\@print{<HR NOSHADE SIZE=1 ALIGN=leftWIDTH=75%>
}}%
\gdef\htmlout{\begin{quote}\myrule}
\gdef\endhtmlout{\myrule\end{quote}}
\end{htmlonly}
\newenvironment{latexout}{\begin{htmlout}}{\end{htmlout}}
\title{How to spot and correct some trouble}
\begin{document}
\maketitle

\section{Simple corrections}
Most of the problems that occur during the translation of a given
\LaTeX\ file (say \verb+trouble.tex+) can be solved at
the macro-level. That is, most problems can be solved by writing a few
macros. The best place for these macros is an user-style file (say
\verb+trouble.sty+) given as
argument to \htmlgen.
\begin{verbatim}
# htmlgen trouble.sty trouble.tex
\end{verbatim}
By doing so, the macros written specially for \htmlgen\ are not
seen by \LaTeX. Even better, \verb+trouble.tex+ is not changed
at all.

Of course, this will be easier if the \LaTeX\ source is written in a
generic style, using macros.
Note that this style is recommended anyway, since it eases the changing
and tuning of documents.

\subsection{\htmlgen\ does not know a macro}
Consider the following \LaTeX\ source excerpt:
\begin{verbatim}
You can \raisebox{.6ex}{\em raise} text.
\end{verbatim}

\LaTeX\ typesets this as follows:
\begin{htmlout}
\begin{htmlonly}
%% BEGIN IMAGE      
You can \raisebox{.6ex}{\em raise} text.
%% END IMAGE
\imageflush
\end{htmlonly}      
\begin{latexonly}
You can \raisebox{.6ex}{\em raise} text.
\end{latexonly}
\end{htmlout}

Since \htmlgen\ does not know about \verb+raisebox+,
it uncorrectly processes this input. More precisely,
it first prints a warning message:
\begin{verbatim}
trouble.tex:34: Unknown macro: \raisebox
\end{verbatim}
Then, it goes on by translating the arguments of \verb+\raisebox+ as
there were normal text. As a
consequence some \verb+.6ex+ is finally found in the html output:
\begin{htmlout}
\begin{latexonly}
You can .6ex{\em raise} text.
\end{latexonly}
\begin{htmlonly}
You can \raisebox{.6ex}{\em raise} text.
\end{htmlonly}
\end{htmlout}

To correct this, you should provide a macro that more or less has the effect of
\verb+raisebox+. It is difficult, yet impossible, to write a generic
\verb+raisebox+ macro for \htmlgen. However, in this case, the effect
of \verb+\raisebox+ is to raise the box {\em a little}.
Thus, the first, numerical, argument to \verb+\raisebox+  can be
ignored:
\begin{verbatim}
\newcommand{\raisebox}[2]{$^{\mbox{#2}}$}
\end{verbatim}

Now, tranlating the document yields:
\begin{htmlout}
\renewcommand{\raisebox}[2]{$^{\mbox{#2}}$}%
You can \raisebox{.6ex}{\em raise} text a little.
\end{htmlout}
Of course this will work only when all \verb+\raisebox+ in the document
raise text a little. Consider, for instance, this example, where text
is both raised a lowered a little:
\begin{verbatim}
You can \raisebox{.6ex}{\em raise} or \raisebox{-.6ex}{\em lower} text.
\end{verbatim}
Which \LaTeX, renders as follows:
\begin{htmlout}
\begin{htmlonly}
%% BEGIN IMAGE
You can \raisebox{.6ex}{\em raise} or \raisebox{-.6ex}{\em lower} text.
%% END IMAGE
\imageflush
\end{htmlonly}
\begin{latexonly}
You can \raisebox{.6ex}{\em raise} or \raisebox{-.6ex}{\em lower} text.
\end{latexonly}
\end{htmlout}
Whereas, with the above definition of \verb+\raisebox+, \htmlgen\ produces:
\begin{htmlout}
\renewcommand{\raisebox}[2]{$^{\mbox{#2}}$}%
You can \raisebox{.6ex}{\em raise} or \raisebox{-.6ex}{\em lower} text.
\end{htmlout}


A solution is to add a new macro definition in the \verb+trouble.sty+ file:
\begin{verbatim}
\newcommand{\lowerbox}[2]{$_{\mbox{#2}}$}
\end{verbatim}
Then, \verb+trouble.tex+ itself has to be modified a little.
\begin{verbatim}
You can \raisebox{.6ex}{\em raise} or \lowerbox{-.6ex}{\em lower} text.
\end{verbatim}
{\htmlgen} now produces a satisfying output:
\begin{htmlout}
\begin{latexonly}\renewcommand{\raisebox}[2]{$^{\mbox{#2}}$}%
\newcommand{\lowerbox}[2]{$_{\mbox{#2}}$}
You can \raisebox{.6ex}{\em raise} or \lowerbox{-.6ex}{\em lower} text.
\end{latexonly}
\begin{htmlonly}\newcommand{\raisebox}[2]{$^{\mbox{#2}}$}%
\newcommand{\lowerbox}[2]{$_{\mbox{#2}}$}
You can \raisebox{.6ex}{\em raise} or \lowerbox{-.6ex}{\em lower} text.
\end{htmlonly}
\end{htmlout}

\subsection{\htmlgen\ uncorrectly interprets a macro}

Sometimes \htmlgen\ knows about a macro, but the produced hthml
is obviously wrong.
This kind of errors is a little more difficult to spot than the
previous one because the translator does not issue a warning. Here you
have to look a the output.
Consider, for instance, this definition:
\begin{verbatim}
\newcommand{\blob}{\rule[.2ex]{1ex}{1ex}}
\blob\ Blob \blob
\end{verbatim}
Which \LaTeX typesets as follows:
\begin{latexout}
\begin{htmlonly}
\begin{toimage}\newcommand{\blob}{\rule[.2ex]{1ex}{1ex}}
\blob\ Blob \blob
\end{toimage}
\imageflush
\end{htmlonly}
\end{latexout}
\htmlgen\ always translate \verb+\\rule+ by \verb+<HR>+, ignoring size
arguments.
Hence, it here produces the following, wrong, output:
\begin{htmlout}\newcommand{\blob}{\rule[.2ex]{1ex}{1ex}}
\begin{htmlonly}
\blob\ Blob \blob
\end{htmlonly}
\end{htmlout}

There is not small square in the symbol font used by \htmlgen.
However there are other small symbols that would perfectly do the job
of \verb+\blob+, such as a small bullet (\verb+\bullet+ in \LaTeX).
Thus you may choose to define \verb+\blob+ in \verb+trouble.sty+ as:
\begin{verbatim}
\newcommand{\blob}{\bullet}
\end{verbatim}
This new definition yields the following, more satisfying output:
\begin{htmlout}\newcommand{\blob}{\bullet}
\begin{htmlonly}
\blob\ Blob \blob
\end{htmlonly}
\end{htmlout}

\subsection{\htmlgen\ crashes with a \protect\texttt{html:} failure}

Such an errors may have many causes, including a bug in \htmlgen.
However, it may also steem from a wrong \LaTeX\ input.
Thus this section is to be read before reporting a bug\ldots

In  the following source, environments are not properly balanced:
\begin{verbatim}
\begin{flushright}
\begin{quote}
This is right-flushed quoted text.
\end{flushright}
\end{quote}
\end{verbatim}
Such a source will make both {\LaTeX} and {\htmlgen} choke.
Thus, when {\htmlgen} crashes, it is a good idea to check that the
input is correct by running {\LaTeX} on it.


Unfortunatly, {\htmlgen} may crash on input that does not affect
\LaTeX.
Such errors are likely to appear when processiong {\TeX}ish input,
such as found in style files.
Consider for instance the following ``optimized'' version of a
\verb+quoteright+  environment:
\begin{verbatim}
\newenvironment{quotebis}{\quote\flushright}{\endquote}

\begin{quotebis}
This a right-flushed quotation
\end{quotebis}
\end{verbatim}

{\LaTeX} produces the expected output:
\begin{latexout}
\begin{toimage}
\newenvironment{quotebis}{\quote\flushright}{\endquote}
\begin{quotebis}
This is a right-flushed quotation
\end{quotebis}
\end{toimage}\imageflush[ALIGN=right]\\
\end{latexout}

However, as {\htmlgen} often translates {\LaTeX} environments by html
opening and  closing tags and that it refuses to generate obviously
non-correct html, it crashes:
\begin{verbatim}
trouble.tex:8: Adios
Fatal error: uncaught exception Failure("hml: BLOCKQUOTE closes DIV")
\end{verbatim}

In this case the solution is easy: environments must be opened and
closed consistently. {\LaTeX} style being recommended, one should write:
\begin{verbatim}
\newenvironment{quotebis}
  {\begin{quote}\begin{flushright}}
  {\end{flushright}\end{quote}}
\end{verbatim}
And we get:
\begin{htmlout}\newenvironment{quotebis}{\begin{quote}\begin{flushright}}{\end{flushright}\end{quote}}
\begin{quotebis}
This is a right-flushed quotation
\end{quotebis}
\end{htmlout}

\end{document}