1

I am trying to convert to HTML using tex4ht without luck. The following is what I have got so far:

sample.tex

% https://elife-cdn.s3.amazonaws.com/author-guide/elife-latex-template.zip
\documentclass[9pt,lineno]{elife}
\usepackage{elife_style}

\title{Grasp movement initiation and representation}

\author[1,2,\authfn{1}]{Elise C Croteau-Chonka}
\author[3,\authfn{1}]{Michael S Clayton}
\author[2]{Lalanti Venkatasubramanian}
\author[3]{Samuel N Harris}
\author[3]{Benjamin M W Jones}
\author[1]{Lakshmi Narayan}
\author[1,2]{Michael Winding}
\author[1,4]{Jean-Baptiste Masson}
\author[1,2,3*, \authfn{2}]{Marta Zlatic}
\author[1,2,\authfn{2}]{Kristina T Klein}
\affil[1]{Janelia Research Campus, Howard Hughes Medical Institute, Ashburn, Virginia, United States}
\affil[2]{Department of Zoology, University of Cambridge, Cambridge, United Kingdom}
\affil[3]{MRC Laboratory of Molecular Biology, Cambridge, United Kingdom}
\affil[4]{Decision and Bayesian Computation, Neuroscience Department CNRS UMR 3751 $\&$ Computational Biology Department USR 3756 (C3BI/DBC), Institut Pasteur, CNRS, Paris, France}
\corr{[email protected]}{MZ}

\contrib[\authfn{1}]{These authors contributed equally to this work}
\contrib[\authfn{2}]{These authors contributed equally to this work}

\presentadd[\authfn{1}]{Zanvyl Mind/Brain Institute, United States}

\begin{document}

\maketitlenew

\end{document}

elife_style.sty

\renewcommand{\maketitlenew}{
  {\LARGE{\bf \@title}}
  {\@author\par}
}

elife_style.4ht

\NewConfigure{maketitlenew}{2}
\let\tmp:maketitlenew\maketitlenew
\renewcommand\maketitlenew{\a:maketitlenew\tmp:maketitlenew\b:maketitlenew}

\NewConfigure{@title}{2}
\let\tmp:title\@title
\renewcommand\@title{\a:@title\tmp:title\b:@title}

\NewConfigure{author}{2}
\let\tmp:author\author
\renewcommand\author{\a:author\tmp:author\b:author}

\NewConfigure{@author}{2}
\let\tmp:author\@author
\renewcommand\@author{\a:@author\tmp:author\b:@author}

elife_style.4ht

\Preamble{xhtml}
\Configure{maketitlenew}
{\ifvmode \IgnorePar\fi
\EndP
\HCode{<div class="maketitle">}\IgnorePar }
{\ifvmode \IgnorePar\fi
\EndP \HCode{</div>}}
{} {}

\Configure{@title}
{\ifvmode \IgnorePar\fi \EndP\HCode{<div class="title">}\IgnorePar }
{\ifvmode \IgnorePar\fi \EndP\HCode{</div>}}
{} {}


\Configure{@author}{\HCode{<span class="author">}\NoFonts}
{\EndNoFonts\HCode{</span>}}


\Configure{textit}{\HCode{<span class="textit">}\NoFonts}
{\EndNoFonts\HCode{</span>}}

\begin{document}
\EndPreamble

When I try htlatex sample1.tex "elife_style,xhtml" " -chunihft -utf8" I get errors like undefined control sequence or \begin{document} is not defined

The expected HTML output I am trying to achieve is

<div class="maketitle">
<h1 class="manuscripttitle">Grasp movement initiation and representation</h1>
<p class="author">J. Steven<span class="affref">1</span><span class="authfn">1</span></p>
<p class="author">S. Manesesh<span class="affref">2</span></p>
<p class="author">K. Alexanders<span class="affref">1*</span></p>
<p class="aff"><span class="affref">1</span><span class="aff">Department of Clinical and Movement Neurosciences, United Kingdom</span></p>
<p class="aff"><span class="affref">2</span><span class="aff">Gatsby Computational Neuroscience Unit, United Kingdom</p>
<p class="corr"><span class="email">[email protected]</span><span class="initial">AC</span></p>
<p class="present"><span class="authfn">1</span><span class="aff">Department of Clinical and Movement Neurosciences, United Kingdom</span></p>
</div>

The idea here is to convert the latex to HTML with granular tagging without worrying about the layout aspect.

I am new to latex, any directions to help overcome the problem is much appreciated. Please share documents and guides to understand how to solve this. I have been trying things out based on https://www.kodymirus.cz/tex4ht-doc/ForDevelopers.html#for-developers

1 Answer 1

0

Here is a .4ht file for the elife class, elife.4ht (I've created if earlier for another similar question)

% \renewcommand{\Authfont}{}
% \renewcommand{\Affilfont}{}

\def\:tempa{%
     \a:themetadata%
     %\textbf{*For correspondence:}
      \bgroup
      \def\end:corr{}
      % we redefine \url to insert tags. the hyperlink is not expected in the output
      \def\url##1{\end:corr\a:coresp\def\end:corr{\c:coresp}##1\b:coresp}
       \par\@correspondence\c:coresp\par
      \egroup
     \ifx\empty\@contribution\else
     \c:themetadata\bigskip
     \bgroup
     \a:contribution
     \let\textsuperscript\@firstofone%
     \def\:tempx{\b:contribution\a:contribution}
     \let\\\:tempx
     \@contribution
     \b:contribution\egroup\d:themetadata\fi
     \ifx\empty\@presentaddress\else
     \bgroup
     %\show\@presentaddress
     \def\end:present{}
     \def\textsuperscript##1{\end:present\a:presentaddress\def\end:present{\c:presentaddress}##1\b:presentaddress}
     \e:themetadata
     %\textbf{Present address: }
     \@presentaddress\end:present\f:themetadata\egroup\fi
     \bigskip
     \ifx\empty\@deceased\else\g:themetadata\@deceased\h:themetadata\fi
     \b:themetadata%
}


\HLet\themetadata\:tempa

\NewConfigure{coresp}{3}
\Configure{coresp}{\ifvmode\IgnorePar\fi\EndP\HCode{<p class="corr"><span class="email">}\NoFonts}
{\HCode{</span><span class="initial">}}{\EndNoFonts\HCode{</span></p>}}

\NewConfigure{contribution}{2}
\Configure{contribution}{\HCode{<p class="contrib">}\NoFonts}{\EndNoFonts\HCode{</p>}}


\def\:tempa#1{\a:authfn\o:authfn:{#1}\b:authfn}
\HLet\authfn\:tempa

\NewConfigure{authfn}{2}
\Configure{authfn}{\HCode{<span class="authfn">}\NoFonts}{\EndNoFonts\HCode{</span>}}

\NewConfigure{presentaddress}{3}
\Configure{presentaddress}{\HCode{<p class="present">}\NoFonts}{\HCode{<span class="aff">}}{\EndNoFonts\HCode{</span></p>}}



% % redefine \@author to include affiliations and other information
% \def\:tempa{\a:authlist\ifx\AB@affillist\AB@empty\AB@author\else
%       \ifnum\value{affil}>\value{Maxaffil}\def\rlap##1{##1}%
%     \c:authlist\AB@authlist\d:authlist\themetadata\e:authlist\AB@affillist\f:authlist
%     \else  \AB@authors\fi\fi\b:authlist}
% \HLet\@author\:tempa

\def\:tempa{%
\a:authlist 
    \ifx\AB@affillist\AB@empty\AB@author\else
      \ifnum\value{affil}>\value{Maxaffil}\def\rlap##1{##1}%
    \c:authlist
     \bgroup
     \def\end:author{}%
     % \large is used by \Authfont, which is protected
     \def\ab:affref##1{\a:affref##1\b:affref}%
     \let\@textsuperscript\ab:affref%
     \def\large{\end:author\a:authorinlist\def\end:author{\b:authorinlist}}%
     \AB@authlist\end:author
     \egroup
     \d:authlist%
    \themetadata%
    \e:authlist%
    \bgroup%
     \def\end:affilitem{}%
     % use \textsuperscript to insert formatting for particual affiliations items
     \def\ab:superscript##1{\end:affilitem\a:affil\def\end:affilitem{\c:affil}##1\b:affil}%
     % \textsuperscript is protected, we must use \@textsuperscript
     \let\@textsuperscript\ab:superscript
     \a:affillist\AB@affillist\end:affilitem\b:affillist%
    \egroup\f:authlist%
    \else  \AB@authors\fi\fi\b:authlist}%

\HLet\@author\:tempa

\NewConfigure{affil}{3}
\NewConfigure{affillist}{2}

\NewConfigure{authorinlist}{2}
\NewConfigure{affref}{2}





\NewConfigure{themetadata}{8}

\NewConfigure{authlist}{6}

\renewenvironment{abstract}{%
   \textcolor{eLifeLightBlue}{\large\bfseries\abstractname\space}
}{%   
}

\AtBeginDocument{

% Add some formatting around suppinfo
% we must use \protect because we are writting to an auxilary file
\addtostream{suppinfo}{\protect\ifvmode\protect\IgnorePar\protect\fi\protect\EndP\protect\HCode{<div class="suppinfo">}}
\Configure{@/BODY}{\ifvmode\IgnorePar\fi\EndP\HCode{</div>}}

% configure environments in \maketitle
\Configure{authlist}
{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="authlist">}}
{\ifvmode\IgnorePar\fi\EndP\HCode{</div>}}
{\HCode{<div class="authors">}}{\HCode{</div><div>}}{\HCode{</div><div>}}{\HCode{</div>}}

\Configure{authorinlist}{\HCode{<p class="author">}\NoFonts}{\EndNoFonts\HCode{</p>\Hnewline}}
\Configure{affref}{\HCode{<span class="affref">}}{\HCode{</span>}}

\Configure{themetadata}
{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="themetadata">\Hnewline}}
{\ifvmode\IgnorePar\fi\EndP\HCode{</div>\Hnewline}}
{}{}{}
{}{}{}
\Css{.themetadata{font-size:0.8rem;}}

\Configure{maketitle}
   {\ifvmode \IgnorePar\fi \EndP {\Configure{maketitle}{}{}{}{}%
\a:NoSection \let\leavevmode\empty \let\not@math@alphabet\:gobbleII
\def\text@command##1{##1}\let\selectfont\empty
\def\check@icl ##1\check@icr{}%
\let\thanks\:gobble
\def\TeX{TeX}%
\def\mbox{\hbox}%
\def\gobble:font##1##2{##2}\:TITLE: \no:fonts
\def\footnotemark[##1]{}%
\def\:hashintitle{\protect\symbol{35}}
\let\#\:hashintitle
\Tag{TITLE+}{\@title}}
%
    \HCode{<div class="maketitle">}}
   {\ifvmode \IgnorePar\fi \EndP \HCode{</div>}}
   {\NoFonts\IgnorePar\HCode{<h1 class="manuscripttitle"\a:LRdir>}\IgnorePar}
   {\HCode{</h1>}\IgnoreIndent\EndNoFonts}

\def\IgnoreRule{\special{t4ht@\string_}}
\def\EndIgnoreRule{\special{t4ht@\string_\string_}}

\ConfigureEnv{abstract}
{\ifvmode\IgnorePar\fi\EndP\HCode{<section role="doc-abstract" class="abstract">\Hnewline}\IgnoreRule}
{\ifvmode\IgnorePar\fi\EndP\HCode{</section>\Hnewline}\EndIgnoreRule}{}{}

\Configure{affillist}{\ifvmode\IgnorePar\fi\EndP\HCode{\Hnewline<div class="affiliations">\Hnewline}}{\ifvmode\IgnorePar\fi\EndP\HCode{</div>\Hnewline}}

\Configure{affil}{\HCode{<p class="aff"><span class="affref">}\NoFonts}{\HCode{</span><span class="aff">}}{\EndNoFonts\HCode{</span></p>\Hnewline}}
\Css{.affref,.authfn{ vertical-align: super; font-size:70\%}}
\Css{p.aff,p.author,p.contrib{margin-top:0;}}

\Css{.authlist span{font-size:0.8rem;}}




\Configure{section}{}{}
   {\ifvmode \IgnorePar\fi \EndP\IgnorePar
    \HCode{<h3 class="sectionHead"\a:LRdir>}\TitleMark\space\HtmlParOff}
   {\HCode{</h3>}\HtmlParOn\ShowPar \IgnoreIndent \par}
\Configure{likesection}{}{}
   {\ifvmode \IgnorePar\fi
    \EndP\IgnorePar\HCode{<h3 class="likesectionHead"\a:LRdir>}\HtmlParOff}
   {\HCode{</h3>}\HtmlParOn \IgnoreIndent \ShowPar \par}
}
\Hinput{elife}
\endinput

I had to make various hacks to insert tags inside document metadata, because elife construes lists of authors and affiliations in a way that makes this task quite difficult. So I had to redefine \texsuperscript etc., to be able to insert extra HTML tags.

The style expects use of \maketitle in your document, but you use \maketitlenew. To get the correct formatting, use this elife_style.4ht file:

\HLet\maketitlenew\maketitle
\Hinput{elife_style}
\endinput

\HLet is TeX4ht's version of \let, saves the original version of the redefined command as \o:originalcommand:, and it uses this original version in pictures. So it is preferable to use it. In this version, we redefine \maketitlenew to use the definition for \maketitle.

One last remark, don't use htlatex, it is deprecated. Use make4ht instead:

 $ make4ht sample1.tex

It will produce UTF-8 document in the HTML 5 format by default.

This is the result:

enter image description here

  <div class='maketitle'>
                                                                             
                                                                             
                                                                             
                                                                             

<h1 class='manuscripttitle'>Grasp movement initiation and representation</h1>
<div class='author'><div class='authlist'><div class='authors'><p class='author'>Elise C Croteau-Chonka<span class='affref'>1,2,†</span>, </p> 
<p class='author'>Michael S Clayton<span class='affref'>3,†</span>, </p> 
<p class='author'>Lalanti Venkatasubramanian<span class='affref'>2</span>,
</p> 
<p class='author'>Samuel N Harris<span class='affref'>3</span>, </p> 
<p class='author'>Benjamin M W Jones<span class='affref'>3</span>, </p> 
<p class='author'>Lakshmi Narayan<span class='affref'>1</span>, </p> 
<p class='author'>Michael Winding<span class='affref'>1,2</span>,
</p> 
<p class='author'>Jean-Baptiste Masson<span class='affref'>1,4</span>, </p> 
<p class='author'>Marta Zlatic<span class='affref'>1,2,3*, ‡</span>, </p> 
<p class='author'>Kristina T Klein<span class='affref'>1,2,‡</span></p> 
</div><div><div class='themetadata'> 

<p class='corr'><span class='email'>[email protected]</span><span class='initial'> (MZ)</span></p>
<p class='contrib'> <span class='authfn'>†</span>These authors contributed equally to this work</p><p class='contrib'><span class='authfn'>‡</span>These authors contributed equally to
this work</p><p class='contrib'></p>  <p class='present'><span class='authfn'>†</span><span class='aff'>Zanvyl Mind/Brain Institute, United States</span></p></div> 
</div><div> 
<div class='affiliations'> 
<p class='aff'><span class='affref'>1</span><span class='aff'>Janelia Research Campus,
Howard Hughes Medical Institute, Ashburn, Virginia, United States; </span></p> 
<p class='aff'><span class='affref'>2</span><span class='aff'>Department of
Zoology, University of Cambridge, Cambridge, United Kingdom; </span></p> 
<p class='aff'><span class='affref'>3</span><span class='aff'>MRC Laboratory of
Molecular Biology, Cambridge, United Kingdom; </span></p> 
<p class='aff'><span class='affref'>4</span><span class='aff'>Decision and Bayesian Computation,
Neuroscience Department CNRS UMR 3751 &amp; Computational Biology Department USR
3756 (C3BI/DBC), Institut Pasteur, CNRS, Paris, France</span></p> 
</div> 
</div></div></div>
<div class='date'><span class='OpenSans-Regular-T1-TLF-'>December 1, 2022</span></div>
   </div>
                                                                             
                                                                             
   <div class='suppinfo'>  </div> 
11
  • That was helpful, but what I was looking for is slightly beyond that. I would like to understand how to tag individual authors like <p class="author">J. Steven<span class="affref">1</span><span class="authfn">1</span></p>. Without worrying about linking with affiliations and other items The moment I had added a few authors it broke and got the following error: [ERROR] htlatex: ./sample1.tex 35 LaTeX Error: Something's wrong--perhaps a missing \item. [ERROR] htlatex: ./sample1.tex 35 LaTeX Error: Something's wrong--perhaps a missing \item. Commented Nov 14, 2022 at 17:54
  • I have edited my original question to with the author and affiliation string in the tex file Commented Nov 14, 2022 at 18:03
  • @Parivalavan I see. I am working on that, but it will take some time.
    – michal.h21
    Commented Nov 15, 2022 at 16:16
  • Thanks. In the meanwhile will it be possible to share some tips or documents that would help me understand the basics of this process. Basically, I am looking for a way to take control of each tag in LaTeX and convert it into some meaningful HTML structure for us to use in our system Commented Nov 15, 2022 at 17:27
  • @Parivalavan I think that the most up to date info is in the documentation that you already saw. What is the problem in this case is that the contents for maketitle are constructed already in the document preamble, where normal TeX4ht commands are not active yet. So it needs some special treatment, which I will show in my answer.
    – michal.h21
    Commented Nov 15, 2022 at 20:35

You must log in to answer this question.

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