
내 LaTeX 파일은 다음과 같습니다 foo.tex
.
\documentclass{article}
\usepackage{amsmath}
\title{Demo}
\begin{document}
\begin{align}
1 + 0 & = 1, \label{eq1} \\
1 + 1 & = 2, \label{eq2} \\
e^{i \pi} = -1. \label{eq3}
\end{align}
Equations \( \eqref{eq1} \), \( \eqref{eq2} \) and \( \eqref{eq3} \)
describe eternal truths.
The equation \( e^{i \pi} = -1 \) can also be rewritten as \( e^{i \pi}
+ 1 = 0 \) which is known as Euler's identity.
\end{document}
다음과 같이 HTML로 변환합니다.
$ make4ht foo mathjax
[STATUS] make4ht: Conversion started
[STATUS] make4ht: Input file: foo
[STATUS] make4ht: Conversion finished
출력은 다음과 같습니다 foo.html
.
<!DOCTYPE html>
<html lang='en-US' xml:lang='en-US'>
<head><title></title>
<meta charset='utf-8' />
<meta name='generator' content='TeX4ht (https://tug.org/tex4ht/)' />
<meta name='viewport' content='width=device-width,initial-scale=1' />
<link href='foo.css' type='text/css' rel='stylesheet' />
<meta name='src' content='foo.tex' />
<script>window.MathJax = { tex: { tags: "ams", inlineMath: [ ["\\\(","\\\)"] ], displayMath: [ ['$$','$$'], ["\\[","\\]"] ], processEscapes: true, processEnvironments: true, packages: ['base', 'color', 'ams'] }, loader: { load: ['[tex]/color', '[tex]/ams'] } }; </script>
<script id='MathJax-script' async='async' type='text/javascript' src='https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml-full.js'></script>
</head><body>
<!-- l. 10 --><p class='noindent'>\begin{align} 1 + 0 & = 1, \label{eq1} \\ 1 + 1 & = 2, \label{eq2} \\ e^{i \pi } = -1. \label{eq3} \end{align}
</p><!-- l. 12 --><p class='noindent'>Equations \( \eqref{eq1} \), \( \eqref{eq2} \) and \( \eqref{eq3} \) describe eternal truths.
</p><!-- l. 15 --><p class='indent'> The equation \( e^{i \pi } = -1 \) can also be rewritten as \( e^{i \pi } + 1 = 0 \) which is known as Euler’s identity.
</p>
</body>
</html>
여태까지는 그런대로 잘됐다. 하지만 제가 하고 싶은 것은 머리글과 바닥글을 결정하는 나만의 HTML 템플릿을 사용하는 것입니다. 에서 주요 콘텐츠만 생성하길 원합니다 make4ht
.
여기 내 템플릿이 있습니다 template.html
.
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<meta charset='utf-8' />
<meta name='viewport' content='width=device-width,initial-scale=1' />
<style>
body {background: gray}
main {background: white; max-width: 40em; margin: 0 auto; padding: 1em}
</style>
<script>window.MathJax = {tex: {tags: "ams"}}</script>
<script src='https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml-full.js'></script>
</head>
<body>
<main>
<!-- HTML converted by make4ht goes here -->
</main>
</body>
</html>
make4ht
출력 HTML을 생성하기 위해 자체 템플릿을 사용하는 대신 이 템플릿을 사용하도록 요청할 수 있는 방법이 있습니까 ?
답변1
가장 쉬운 방법은 TeX4ht가 기본 HTML 구성을 위해 제공하는 구성 가능한 후크를 사용하는 것입니다. 다음은 옵션을 .log
사용할 때 파일 에 포함되는 기본 정보입니다 .info
make4ht
\Configure{DOCTYPE}.........1
\Configure{HTML}............2
\Configure{HEAD}............2
\Configure{@HEAD}...........1
\Configure{BODY}............2
\Configure{TITLE+}..........1
\Configure{TITLE}...........2
\Configure{@TITLE}..........1
\Configure{Preamble}........2
<DOCTYPE>
<HTML 1>
<HEAD 1>
<TITLE 1>
<@TITLE>
<TITLE+>
<TITLE 2>
<@HEAD>
<HEAD 2>
<BODY 1>
......
<BODY 2>
<HTML 2>
The \Configure{@HEAD}{...} command is additive, concatenating the
content of all of its appearances. An empty parameter requests
the cancellation of the earlier contributions.
For instance,
\Configure{@HEAD}{A}
\Configure{@HEAD}{}
\Configure{@HEAD}{B}
\Configure{@HEAD}{C}
contributes `BC'.
The \Configure{TITLE+} provides the content for the title,
\Configure{TITLE} sets the envelop, and \Configure{@TITLE} acts as a
hook for introducing localized configurations. As is the case for
\Configure{@HEAD}, the contribution of \Configure{@TITLE} is also
additive.
These configurations should be introduced early enough in the
compilation. For instance, in the case of LaTeX, between \Preamble
and \begin{document} of a local configuration file.
\Preamble
%%% here %%%
\begin{document}
...
\EndPreamble
\Configure{@BODY}...........1
\Configure{@/BODY}..........1
Variants of \Configure{@HEAD} which contribute their content,
respectively, after <body> and before </body>.
\Configure{HTML}
따라서 요소 에서 속성을 제거하고 <html>
, \Configure{TITLE+}
자신만의 제목을 설정하고, 요소 \Configure{@HEAD}
에 대부분의 항목을 삽입하고 , 요소 를 삽입하려면 를 사용해야 합니다 .<head>
\Configure{@BODY}
\Configure{@/BODY}
<main>
.cfg
수행 방법을 보여주는 전체 파일은 다음과 같습니다 .
\Preamble{xhtml}
\Configure{@HEAD}{} % remove default content in HTML header
\Configure{@HEAD}{%
\HCode{<meta charset='utf-8' /> \Hnewline
<meta name='viewport' content='width=device-width,initial-scale=1' /> \Hnewline
<style>\Hnewline
body {background: gray}\Hnewline
main {background: white; max-width: 40em; margin: 0 auto; padding: 1em}\Hnewline
</style>\Hnewline
<script>window.MathJax = {tex: {tags: "ams"}}</script> \Hnewline
<script src='https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml-full.js'></script> \Hnewline
}}
\Configure{TITLE+}{test}
\Configure{HTML}{\HCode{<html>\Hnewline}}{\HCode{\Hnewline</html>}}
\Configure{@BODY}{\ifvmode\IgnorePar\fi\EndP\HCode{<main>\Hnewline}}
\Configure{@/BODY}{\ifvmode\IgnorePar\fi\EndP\HCode{\Hnewline</main>}}
\begin{document}
\EndPreamble
를 처음 사용하면 \Configure{@HEAD}{}
TeX4ht가 헤더에 삽입하는 일반적인 내용이 제거됩니다. 해당 구성의 두 번째 호출에 모든 태그를 삽입합니다. 매크로 사용에 유의하세요 \Hnewline
. 생성된 HTML 파일에 줄 바꿈을 삽입하는 데 사용됩니다.
문서 텍스트가 이미 조판되어 있을 때 \Configure{@BODY}
및가 사용되기 때문에 단락을 처리해야 합니다. 태그 불일치를 방지하는 데 사용됩니다.\Configure{@/BODY}
\ifvmode\IgnorePar\fi\EndP
결과 HTML은 다음과 같습니다.
<!DOCTYPE html>
<html>
<head> <title>test</title>
<meta charset='utf-8' />
<meta content='width=device-width,initial-scale=1' name='viewport' />
<style>
body {background: gray}
main {background: white; max-width: 40em; margin: 0 auto; padding: 1em}
</style>
<script>window.MathJax = {tex: {tags: "ams"}}</script>
<script src='https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml-full.js'></script>
</head><body>
<main>
<!-- l. 11 --><p class='indent'> \begin{align} 1 + 0 & = 1, \label{eq1} \\ 1 + 1 & = 2, \label{eq2} \\ e^{i \pi } = -1. \label{eq3} \end{align}
</p><!-- l. 13 --><p class='indent'> Equations \( \eqref{eq1} \), \( \eqref{eq2} \) and \( \eqref{eq3} \) describe eternal truths.
</p><!-- l. 16 --><p class='indent'> The equation \( e^{i \pi } = -1 \) can also be rewritten as \( e^{i \pi } + 1 = 0 \) which is known as Euler’s identity.
</p>
</main>
</body>
</html>
그리고 이것이 어떻게 보이는지입니다: