帮助编写 make4ht 的配置文件

帮助编写 make4ht 的配置文件

我有一个如下所示的乳胶文件。

\documentclass[11pt,twoside]{book}
\ifdefined\HCode
\def\pgfsysdriver{pgfsys-dvisvgm4ht.def}
\fi 
%Below two lines to completely remove page numbering,header and footer
\usepackage{fancyhdr}
\pagestyle{empty}
%To Create a new list questions
\usepackage{enumitem}
\newlist{questions}{enumerate}{3}
\setlist[questions]{wide=0pt, leftmargin=15pt, labelwidth=15pt, labelsep=0pt, align=left,label=\color{futuringtheme}\bfseries\large\arabic*.}
\newcommand{\question}{\item}
%Defining necessary colours
\usepackage{xcolor} % Required for specifying colors by name
\definecolor{ocre}{RGB}{243,102,25} % Define the orange color used for highlighting throughout the book
\definecolor{futuringtheme}{RGB}{0,142,212}
%Defining exyear command for Exam Year
\newcommand{\exyear}[1]{\newline \llap{}\hfill \color{futuringtheme}{\textbf{[#1]}}}
%Defining command abox
\usepackage{environ}
\usepackage{tikz}
\NewEnviron{abox}{%
    \begin{center}
        \begin{tikzpicture}
        \node[align=center,anchor=base,draw,rectangle,text width=\textwidth,line width=2pt,rounded corners=15pt,draw=ocre,fill=white,fill opacity=0.9,inner sep=10pt] 
        {\centering \textbf{ \huge \color{futuringtheme}\BODY}};
        \end{tikzpicture}
        
    \end{center}
    
    
}
%Importing package task
\begin{document}
    \begin{abox}
        JAM Previous Year Questions
    \end{abox}
\section*{\centering{\color{futuringtheme} \underline{Coulomb's law and Superposition principle}}}
\begin{questions}
    \begin{minipage}{\textwidth}
    \question An electric field $\vec{E}(\vec{r})=(\alpha \hat{r}+\beta \sin \theta \cos \phi \hat{\phi})$ exists in space. What will be the total charge enclosed in a sphere of unit radius centered at the origin? 
    {\exyear{IIT JAM 2009}}
\end{minipage}


\end{questions} 

\end{document}

PDF 输出看起来像这样在此处输入图片描述

但是当我使用 make4ht 时,HTML 输出看起来完全混乱了。我该如何编写所需的配置文件。我找不到任何详细的文档。哪个配置文件可以完成这项工作?

答案1

我会稍微修改一下你的文件:

\documentclass[11pt,twoside]{book}
\ifdefined\HCode
\def\pgfsysdriver{pgfsys-dvisvgm4ht.def}
\fi 
%Below two lines to completely remove page numbering,header and footer
\usepackage{fancyhdr}
\pagestyle{empty}

%To Create a new list questions
\usepackage{enumitem}
\newlist{questions}{enumerate}{3}
\setlist[questions]{wide=0pt, leftmargin=15pt, labelwidth=15pt, labelsep=0pt, align=left,label=\color{futuringtheme}\bfseries\large\arabic*.}
\newcommand{\question}{\item}

%Defining necessary colours
\usepackage{xcolor} % Required for specifying colors by name
\definecolor{ocre}{RGB}{243,102,25} % Define the orange color used for highlighting throughout the book
\definecolor{futuringtheme}{RGB}{0,142,212}

%Defining exyear command for Exam Year
\newcommand{\exyear}[1]{\newline \llap{}\hfill \color{futuringtheme}{\textbf{[#1]}}}

%Defining command abox
\usepackage{environ}
\usepackage{tikz}
\NewEnviron{abox}{%
    \begin{center}
        \begin{tikzpicture}
        \node[align=center,anchor=base,draw,rectangle,text width=\textwidth,line width=2pt,rounded corners=15pt,draw=ocre,fill=white,fill opacity=0.9,inner sep=10pt] 
        {\centering \textbf{ \huge \color{futuringtheme}\BODY}};
        \end{tikzpicture}
        
    \end{center}
    
    
}

\newcommand\underlinesection[1]{\section*{\centering{\color{futuringtheme} \underline{#1}}}}

%Importing package task
\begin{document}
    \begin{abox}
        JAM Previous Year Questions
    \end{abox}

\underlinesection{Coulomb's law and Superposition principle}
\begin{questions}
\minipage{\textwidth}
    \question An electric field $\vec{E}(\vec{r})=(\alpha \hat{r}+\beta \sin \theta \cos \phi \hat{\phi})$ exists in space. What will be the total charge enclosed in a sphere of unit radius centered at the origin? 
    {\exyear{IIT JAM 2009}}
\endminipage


\end{questions} 


\end{document}

我的改变是:

\newcommand\underlinesection[1]{\section*{\centering{\color{futuringtheme} \underline{#1}}}}

使用自定义命令,而不是在文档中直接格式化。这适用于带蓝色下划线的部分。

第二个改变是,我将\begin{minipage}其改为\minipage。原因是它给 TeX4ht 带来了问题,它无法正确关闭列表。

经过这些更改,您可以使用以下配置文件:

\Preamble{xhtml}
\makeatletter

% insert tags for questions env
\ConfigureList{questions}{%
\ifvmode\IgnorePar\fi\EndP\HCode{<div class="questions">}\gdef\end@questions{}
}
{\ifvmode\IgnorePar\fi\EndP\end@questions\HCode{</div>}}
{
  \end@questions%
  \gdef\end@questions{\ifvmode\IgnorePar\fi\EndP\HCode{</div>}}
  \HCode{<div class="question-number">}%
}{\HCode{</div><div class="question-body">}\par\ShowPar}


\Css{.questions{ display:grid; grid-template-columns: 4ch 1fr; }}
\Css{.question-number{color: rgb(0,142,212);}}

\renewcommand{\exyear}[1]{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="exyear">}\textbf{[#1]}\HCode{</div>}}
\Css{.exyear{float:right;color: rgb(0,142,212);clear:both;}}
\Css{body{max-width:65ch;margin:1rem auto;}}

\renewcommand\underlinesection[1]{\ifvmode\IgnorePar\fi\EndP\HCode{<h2 class="underlinesection">}#1\HCode{</h2>}}
\Css{.underlinesection{color:rgb(0,142,212);text-decoration:underline;}}


\makeatother
\begin{document}
\EndPreamble

它定义列表的格式questions,并重新定义\underlinesection\exyear生成一些可以使用 CSS 设置样式的 HTML 标签。

结果如下:

在此处输入图片描述

您可以看到,问题中的垂直对齐方式不正确。这是由于数学太高造成的。我找不到解决办法。

相关内容