使用 htlatex 转换为 HTML 时自定义作者和所属机构的标签

使用 htlatex 转换为 HTML 时自定义作者和所属机构的标签

我尝试使用 转换为 HTML,tex4ht但没有成功。以下是我目前得到的结果:

样本

% 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

当我尝试时,htlatex sample1.tex "elife_style,xhtml" " -chunihft -utf8"出现类似undefined control sequence\begin{document}未定义的错误

我试图实现的预期 HTML 输出是

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

这里的想法是将乳胶转换为具有细粒度标记的 HTML,而不必担心布局方面。

我是新手latex,任何有助于克服这个问题的指导都会非常感激。请分享文档和指南以了解如何解决这个问题。我一直在尝试基于https://www.kodymirus.cz/tex4ht-doc/ForDevelopers.html#for-developers

答案1

这是该课程.4ht的文件(我之前为另一个课程创建过elifeelife.4ht类似问题

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

我必须采取各种措施才能在文档元数据中插入标签,因为elife作者和所属机构列表的解释方式使得这项任务非常困难。因此,我必须重新定义\texsuperscript等,以便能够插入额外的 HTML 标签。

\maketitle该样式要求在您的文档中使用,但您使用了\maketitlenew。要获得正确的格式,请使用此elife_style.4ht文件:

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

\HLet是 TeX4ht 的 版本\let,将重新定义的命令的原始版本保存为\o:originalcommand:,并在图片中使用这个原始版本。所以最好使用它。在这个版本中,我们重新定义\maketitlenew为使用 的定义\maketitle

最后提醒一下,不要使用htlatex,它已被弃用。请使用make4ht

 $ make4ht sample1.tex

它将默认生成 HTML 5 格式的 UTF-8 文档。

结果如下:

在此处输入图片描述

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

相关内容