-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlatex2html_via_tex4ht.tex
247 lines (218 loc) · 8.91 KB
/
latex2html_via_tex4ht.tex
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
% !Mode:: "TeX:Hard"
\documentclass{article}
\usepackage{amsmath,amsthm}
\usepackage{amsfonts}
\usepackage{a4wide}
% This is to tune using tiks with tex4ht
\ifdefined\HCode%
\def\pgfsysdriver{pgfsys-dvisvgm4ht.def}%
\fi%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{tikz}
\usetikzlibrary{shapes,arrows,positioning,fit}
\title{My notes on how to use Tex4ht+MathJax}
\author{Victor Kozyakin}
%\usepackage{tex4ht}
\begin{document}
\maketitle
\section{Call Command}\label{S1}
My problem was to make a HTML file with plenty of mathematics from a \LaTeX{}
one. As a beginner, I immediately faced the following problems:
\begin{itemize}
\item How to run Tex4ht to get HTML file with mathematics?
\item What to do to make proper referencing of mathematical formulas?
\item How to cope with TikZ figures?
\end{itemize}
After a while I discovered that the most suitable way for me is to join
Tex4ht with MathJax. And the simplest way was to run the following command to
process \verb|test.tex| file:
{\small
\begin{verbatim}
make4ht -s test.tex "myconfig" " -cunihtf -utf8"
\end{verbatim}}
\noindent and after that, if one wants to embed into resulted
\verb|test.html| the css-file \verb|test.css| generated during previous
command, one should issue one the following command {\small
\begin{verbatim}
htlatex test.tex "myconfig" " -cunihtf -utf8"
\end{verbatim}
\noindent or once more
\begin{verbatim}
make4ht -s test.tex "myconfig" " -cunihtf -utf8"
\end{verbatim}}
\noindent where the config file \verb|myconfig.cfg| is as
follows
{\small
\begin{verbatim}
\Preamble{xhtml,html5,0,mathjax,p-indent,charset=utf-8,css-in,fn-in}
\textwidth=2160pt
\Css{body { margin:5\% 5\%; max-width:72em; font-size:large; padding:0 40px;}}
\Css{p.indent {text-indent:1.5em;}}
\Css{.columns-3 p.indent {text-indent:0em;}}
\Css{p.bibitem-p { text-indent: 1.5em; margin-left: 2em; margin-top:0em; margin-bottom:0em;
background:\#F0F0F0; color:\#000000;}}
\def\eqref#1{$\mathrm{(\ref{#1})}$}
\begin{document}
\EndPreamble
\end{verbatim}}
\section{How to reference equations in TeX4ht+MathJax}\label{S2}
Unfortunately, it turned out that reference in conjunction TeX4ht+MathJax
works well when they referenced sections, subsections and other structure
element that are in \textbf{text mode}, but when you are trying to reference
the label of equation you are getting ???.
The problem is turned out to be rather easily solvable: to reference labels
of equations, align or other things in \textbf{math mode} you should put the
calling \verb|\eqref| or \verb|\ref| in a \textbf{math environment}, e.g. by
surrounding them by \verb|$'s| or \verb|\(|\ldots\verb|\)|. Another way is to
redefine the command \verb|\eqref| in order that it will be invoked in math
mode automatically (see the appropriate string in the config file
\verb|myconfig.cfg|.
So, for the \LaTeX{} code below
{\small
\begin{verbatim}
\begin{equation}
\boldsymbol{f}(x)=1\label{eq}
\end{equation}
\[
1\neq1. \tag{OneIsNotOne Condition}\label{E:mycond}
\]
Here, the reference to \tag{OneIsNotOne Condition} in previous
equation is as follows: \eqref{E:mycond}
\begin{align}
a&=1\label{A}\\
b&=0\label{B}
\end{align}
Example of references: we have equation \eqref{eq} from Sec. \ref{S1}. Or $\ref{A}$-\eqref{B}.
\end{verbatim}}
\noindent we obtain the following output:
\begin{equation}
\boldsymbol{f}(x)=1\label{eq}
\end{equation}
\[
1\neq1. \tag{OneIsNotOne Condition}\label{E:mycond}
\]
Here, the reference to \verb|\tag{OneIsNotOne Condition}| in previous
equation is as follows: \eqref{E:mycond}
\begin{align}
a & =1\label{A} \\
b & =0\label{B}
\end{align}
Example of references: we have equation \eqref{eq} from Sec. \ref{S1}. Or
$\ref{A}$-\eqref{B}.
\section{How to cope with TikZ figures}\label{S3}
Tex4th supports TikZ, however, for correct displaying text and math symbols
in TikZ picture, it is needed to put in the preamble of tex file the
following lines, before TikZ package loading:
\begin{verbatim}
\ifdefined\HCode%
\def\pgfsysdriver{pgfsys-dvisvgm4ht.def}%
\fi%
\end{verbatim}
Below is an example of using TikZ.
\usetikzlibrary{backgrounds}
\begin{figure}[!hbt]
\center
\begin{tikzpicture}[background rectangle/.style={fill=white}, show background rectangle,
every node/.style={text=blue},auto,>=latex',node font=\small]
\pgfmathsetmacro{\a}{15}
%
\begin{scope}[xscale=0.5, yscale=2.0]
\pgfmathsetmacro{\s}{2}
\coordinate (S) at ({cos(\a)*\s},{sin(-\a)*\s});
\coordinate (SS) at ({cos(\a)*\s},{sin(\a)*\s});
\draw[fill=blue!10, line width=0.3pt] (SS) to (0,0) to (S) arc [start angle=-\a, end angle=\a, radius=\s];
\path (SS) node[left] {$H_{1}S$};
\end{scope}
%
\begin{scope}[xscale=-0.5, yscale=-2.0]
\pgfmathsetmacro{\s}{2}
\coordinate (S) at ({cos(\a)*\s},{sin(-\a)*\s});
\coordinate (SS) at ({cos(\a)*\s},{sin(\a)*\s});
\draw[fill=blue!10, line width=0.3pt] (SS) to (0,0) to (S) arc [start angle=-\a, end angle=\a, radius=\s];
\path (SS) node[below] {$H_{1}\tilde{S}$};
\end{scope}
%
\pgfmathsetmacro{\s}{2}
\coordinate (S) at ({cos(\a)*\s},{sin(-\a)*\s});
\coordinate (SS) at ({cos(\a)*\s},{sin(\a)*\s});
\draw[fill=blue!5, line width=0.3pt] (SS) to (0,0) to (S) arc [start angle=-\a, end angle=\a, radius=\s];
\path (SS) node[below left,xshift=0.66ex] {$S$};
%
\begin{scope}[scale=-1.0]
\pgfmathsetmacro{\s}{2}
\coordinate (S) at ({cos(\a)*\s},{sin(-\a)*\s});
\coordinate (SS) at ({cos(\a)*\s},{sin(\a)*\s});
\draw[fill=blue!5, line width=0.3pt] (SS) to (0,0) to (S) arc [start angle=-\a, end angle=\a, radius=\s];
\path (SS) node[above right,xshift=-0.66ex] {$\tilde{S}$};
\end{scope}
%
\begin{scope}[xscale=0.5, yscale=2.0]
\pgfmathsetmacro{\s}{2}
\coordinate (S) at ({cos(\a)*\s},{sin(-\a)*\s});
\draw[densely dashed, line width=0.3pt] (S) arc [start angle=-\a, end angle=\a, radius=\s];
\end{scope}
%
\begin{scope}[xscale=-0.5, yscale=-2.0]
\pgfmathsetmacro{\s}{2}
\coordinate (S) at ({cos(\a)*\s},{sin(-\a)*\s});
\draw[densely dashed, line width=0.3pt] (S) arc [start angle=-\a, end angle=\a, radius=\s];
\end{scope}
\draw[->] (-\s-0.5,0) -- (\s+0.5,0) node[label={[color=red,xshift=-0.5em,yshift=-0.66ex]$x$}] {};
\draw[->] (0,-\s-0.5) -- (0,\s+0.5) node[label={[color=red,xshift=0.66em,yshift=-4ex]$y$}] {};
%
\draw[dashed] (0,0) circle [radius=\s];
\node[color=black,above left] at (0,\s) {$1$};
\node[color=black,below left] at (0,-\s) {$-1$};
\node[color=black,below right] at (\s,0) {$1$};
\node[color=black,below left] at (-\s,0) {$-1$};
\end{tikzpicture}
\caption{Example of Stanford}
\end{figure}
Citation example:~\cite{NDKKP:DSS96}.
\bigskip
%\paragraph{Remark}
%With recent versions of \texttt{GhostScript} ($>$=10.02.0) in your \TeX{}
%system and \texttt{dvisvgm} ($<$3.1.1), \texttt{tex4th} creates a corrupted
%version of the \texttt{svg} file, by including the following uncommented
%string (from \texttt{GhostScript} output) in its first lines: ``\emph{The
%old, written in PostScript, PDF interpreter has been removed entirely. You
%should cease using -dNEWDPF as it has no effect n}''. This should be
%recovered when \texttt{dvisvgm} version $>$=3.1.1 will be installed in your
%\LaTeX{} system.
%
%One way to recover: If it is your case and you will see no normal picture in
%the created html file, then \textbf{this string must be removed manually in
%the generated svg file using any text editor so that this file to be
%displayed normally in the html output!}
%
%Another way to recover (until it will be recovered by creators of
%\texttt{GhostScript} or \texttt{dvisvgm}). Find the file \verb|pdf_main.ps|
%in your \TeX{} system. For example, in TeXLive it is placed in the directory
%\verb|...\texlive\2023\tlpkg\tlgs\Resource\Init|. After that, replace in this
%file the following fragment of code:
%
%\begin{verbatim}
%systemdict /NEWPDF known {
% systemdict /NEWPDF get not {
% (The old, written in PostScript, PDF interpreter has been removed entirely.\n) print
% (You should cease using -dNEWDPF as it has no effect now.\n) print
% (Continuing to process PDF file using the new, written in C, PDF interpreter.\n) print
% } if
%} if
%\end{verbatim}
%with the following one:
%
%\begin{verbatim}
%systemdict /NEWPDF known {
% systemdict /NEWPDF get not {} if
%} if
%\end{verbatim}
%
%After that, the spurious string in the generated \texttt{svg} file disappears
%and this file will be happily accepted by the resulting \texttt{html} file!
%\qed
\newcommand{\BibAnnote}[1]{}%
\bibliographystyle{ugost705s}
\bibliography{kozpub}
\end{document}
% make4ht -sc myconfig.cfg test.tex "0,mathjax,p-indent,charset=utf-8" " -cunihtf -utf8"