1

I have a latex file as shown below.

\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}

The PDF output look something like thisenter image description here

But when I use make4ht the HTML output seems completely cluttered.How can I write the required configuration file. I can't find any detailed documentation. What configuration file can do the job ?

1 Answer 1

1

I would change your document a bit:

\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}

My changes are:

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

Use a custom command instead of direct formatting in the document. This is for the blue underlined section.

The second change is that I've changed \begin{minipage} to \minipage. The reason is that it caused issues to TeX4ht, it couldn't properly close the list.

With these changes, you can use the following configuration file:

\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

It defines formatting for the questions list, and redefines \underlinesection and \exyear to produce some HTML tags that can be styled using CSS.

This is the result:

enter image description here

You can see, that there is wrong vertical alignment in the question. It is caused by math, which is too high. I couldn't find a fix for that.

3
  • Thanks a lot. A quick doubt, the svg files which are generated by t4ht reside in the same directory of main.html.Is there any way to move these svg files into a subfolder.
    – hfactor
    Commented Feb 9, 2022 at 10:16
  • 1
    @hfactor you would need make4ht build file for that, but it is possible to move files. I think it would be better to ask it as a new question.
    – michal.h21
    Commented Feb 9, 2022 at 11:42
  • Sure. I'll post it as a new question. Thanks a lot for your help.
    – hfactor
    Commented Feb 9, 2022 at 11:49

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .