
看起來 tex4ht 標題<h2>
從標題開始。以下文字:
\documentclass{article}
\title{Testing headings}
\author{Alex Watson}
\date{\today}
\begin{document}
\maketitle
\section{Top level section}
\subsection{Next level section}
\end{document}
處理後make4ht -uf html5 ht-headings.tex
會產生以下 HTML:
<!DOCTYPE html>
<html lang='en-US' xml:lang='en-US'>
<head><title>Testing headings</title>
<meta charset='utf-8' />
<meta name='generator' content='TeX4ht (http://www.tug.org/tex4ht/)' />
<meta name='viewport' content='width=device-width,initial-scale=1' />
<link rel='stylesheet' type='text/css' href='ht-headings.css' />
<meta name='src' content='ht-headings.tex' />
</head><body>
<div class='maketitle'>
<h2 class='titleHead'>Testing headings</h2>
<div class='author'><span class='cmr-12'>Alex Watson</span></div><br />
<div class='date'><span class='cmr-12'>September 19, 2020</span></div>
</div>
<h3 class='sectionHead'><span class='titlemark'>1 </span> <a id='x1-10001'></a>Top level section</h3>
<!-- l. 13 --><p class='noindent'>
</p>
<h4 class='subsectionHead'><span class='titlemark'>1.1 </span> <a id='x1-20001.1'></a>Next level section</h4>
</body>
</html>
標題從h2
標題開始,然後h3
是部分,等等。
我原以為標題是h1
。
也許更重要的是,如果使用類別book
和一些\chapter
宏,標題仍然是h2
,但章節也是h2
!
有沒有一種簡單的方法可以將標題級別“向上移動”,用於h1
標題、h2
下一級分區等? (這是合理的事情嗎?)
一個適用於不同類別的解決方案(甚至可能分割成多個 html 檔案!)將是理想的,但我意識到這可能要求有點高。
答案1
我知道這不是太符合邏輯的結構,但我擔心更改它會破壞現有文件。不管怎樣,你可以嘗試這個設定檔:
\Preamble{xhtml}
\begin{document}
\catcode`\:=11
% configure all sections to use our sectioning configuration
\newcommand\:setlevel[2]{%
\Configure{#1}{}{}
{\ifvmode \IgnorePar\fi \EndP\IgnorePar
\HCode{<#2 class="#1Head"\a:LRdir>}\TitleMark\space\HtmlParOff}
{\HCode{</#2>}\HtmlParOn\ShowPar \IgnoreIndent \par}
\Configure{like#1}{}{}
{\ifvmode \IgnorePar\fi
\EndP\IgnorePar\HCode{<#2 class="like#1Head"\a:LRdir>}\HtmlParOff}
{\HCode{</#2>}\HtmlParOn \IgnoreIndent \ShowPar \par}
}
\ifdefined\chapter
\:setlevel{chapter}{h1}
\:setlevel{section}{h2}
\:setlevel{subsection}{h3}
\:setlevel{subsubsection}{h4}
\else
\:setlevel{section}{h1}
\:setlevel{subsection}{h2}
\:setlevel{subsubsection}{h3}
\fi
\catcode`\:=12
\EndPreamble
它定義了一個新命令 ,\:setlevel
它採用兩個參數:分段級別和該級別應使用的 HTML 元素。
<h1 class='chapterHead'><span class='titlemark'>Chapter 1</span> <a id='x1-10001'></a>my chapter</h1>
<h2 class='sectionHead'><span class='titlemark'>1.1 </span> <a id='x1-20001.1'></a>Top level section</h2>
<!-- l. 15 --><p class='noindent'>
</p>
<h3 class='subsectionHead'><span class='titlemark'>1.1.1 </span> <a id='x1-30001.1.1'></a>Next level section</h3>