4

I tried to reconfigure \Link, \ref, \cite to get the below output

Link --> <target targetid="x1-10001"></target>

ref --> <xref ref-type="Sec" rid="x1-10001">1</xref>

cite --> <xref ref-type="bibr" rid="Xbib1">1</xref>

I configured like below in .cfg

\Configure{Link}{xref}{LinkID=}{targetid=}{\empty} 

\Configure{ref}
    {\Configure{Link}{xref}{ref-type="\RefArg" rid=}{}{}\Link}
    {\ifx \RefArg\:UnDef\else\fi\EndLink%
      \Configure{Link}{xref}{LinkID=}{Targetid=}{\empty}}
    {}

\Configure{cite}{}{}
                {\Configure{Link}{xref}{ref-type="bibr" rid=}{id=}{\empty}%
                 \Link}
               {\EndLink}

I am getting the output like below

<sec sec-type="section" id="sample_s_001">
<label>1</label>
<title><target targetid="x1-10001"></target>
Sample Section head</title>

for \ref i am getting the output

<p class="noindent">Macro&#x00A0;<xref ref-type="Sec1" rid="x1-10001">1</xref> 
language has evolved gradually: as the need arose for actions beyond 

for \cite i am getting wrong output

[<target LinkID="Xbib1">1</target>]

how to configure those to achieve the expected output ?

MWE:

\documentclass{article}
\usepackage{times}
\usepackage{graphicx}
\usepackage[numbers]{natbib}
\title{TeX4HT Try}


\begin{document}

\maketitle

\section{Sample Section head}\label{Sec1}

Macro~\ref{Sec1} language has evolved gradually: as the need arose for actions beyond a predefined set of commands. As a consequence, it is a pretty non-standard language that implements loops and conditional statements with macro functions rather than keywords.


Sophisticated macro scripts involving loops and conditional statements are, admittedly, hard to write and read, and it may take some time to become familiar with it \cite{bib1}.

\begin{thebibliography}{}
\bibitem{bib1} text
\bibitem{bib2} text
\end{thebibliography}

1 Answer 1

4

It seems that configuration for the Natbib package doesn't take into account the \Configure{cite} command. I've just added the support for that. You can use the following patched natbib.4ht file until the support is added to TL:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% natbib.4ht                            2019-07-26-22:42 %
% Copyright (C) 1999-2009       Eitan M. Gurari         %
% Copyright 2009-2019 TeX Users Group
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either
% version 1.3c of this license or (at your option) any
% later version. The latest version of this license is in
%   http://www.latex-project.org/lppl.txt
% and version 1.3c or later is part of all distributions
% of LaTeX version 2005/12/01 or later.
%
% This work has the LPPL maintenance status "maintained".
%
% The Current Maintainer of this work
% is the TeX4ht Project <http://tug.org/tex4ht>.
%
% If you modify this program, changing the
% version identification would be appreciated.

\HRestore\@lbibitem
\HRestore\@bibitem
\ifNAT@super
   \def\citet{\@ifstar{\NAT@longnamestrue\ht@citet}%
          {\NAT@longnamesfalse\ht@citet}}

   \def\setb:anc#1{\let\sv:anc\AnchorLabel
   \def\bib:anc{\Link{}{bibitem\the
      \c@NAT@ctr}\EndLink \gdef\bib:anc{}}%
   \def\AnchorLabel{\bib:anc}}
\def\nb:link#1{\Protect\Link{bibitem#1}{}#1\Protect\EndLink}
\def\nb@link#1{\Protect\Link{bibitem#1}{}#1\Protect\EndLink}
\let\nat:lbibitem\@lbibitem
\def\@lbibitem{%
  \ifx\hyper@natanchorstart\@gobble
     \def\hyper@natanchorstart##1{\Link{}{bibitem\the
      \c@NAT@ctr}\EndLink}\fi
  \nat:lbibitem
}
\catcode`\:12
  \def\ht@citet#1{\def\NAT@num{-1}\let\NAT@last@yr\relax\let\NAT@nm\@empty
     \let\@citea\@empty
     \@for\@citeb:=#1\do{%
      \@ifundefined{b@\@citeb\@extra@b@citeb}%
       {{\reset@font\bfseries?}\NAT@citeundefined\PackageWarning{natbib}%
         {Citation `\@citeb' on page \thepage \space undefined}%
       }%
       {\@citea\let\NAT@last@num\NAT@num\let\NAT@last@nm\NAT@nm
        \NAT@parse{\@citeb}%
        \ifNAT@longnames\@ifundefined{bv@\@citeb\@extra@b@citeb}{%
          \let\NAT@name=\NAT@all@names
          \global\@namedef{bv@\@citeb\@extra@b@citeb}{}}{}%
        \fi
        \ifNAT@full\let\NAT@nm\NAT@all@names\else
         \let\NAT@nm\NAT@name
        \fi
        \NAT@nm}\Tg<sup>\nb@link{\NAT@num}\Tg</sup>
        \def\@citea{\unskip\NAT@sep\penalty\@m\space}%
       }%
}
\def\NAT@citexnum[#1][#2]#3{%
 \NAT@sort@cites{#3}%
 \let\@citea\@empty
  \@cite{\def\NAT@num{-1}\let\NAT@last@yr\relax\let\NAT@nm\@empty
    \@for\@citeb:=\NAT@cite@list\do
    {\edef\@citeb{\expandafter\@firstofone\@citeb}%
     \if@filesw\immediate\write\@auxout{\string\citation{\@citeb}}\fi
     \@ifundefined{b@\@citeb\@extra@b@citeb}{%
       {\reset@font\bfseries?}
        \NAT@citeundefined\PackageWarning{natbib}%
       {Citation `\@citeb' on page \thepage \space undefined}}%
     {\let\NAT@last@num\NAT@num\let\NAT@last@nm\NAT@nm
      \NAT@parse{\@citeb}%
      \ifNAT@longnames\@ifundefined{bv@\@citeb\@extra@b@citeb}{%
        \let\NAT@name=\NAT@all@names
        \global\@namedef{bv@\@citeb\@extra@b@citeb}{}}{}%
      \fi
      \ifNAT@full\let\NAT@nm\NAT@all@names\else
        \let\NAT@nm\NAT@name\fi
      \ifNAT@swa
       \ifnum\NAT@ctype=2\relax\@citea
        \hyper@natlinkstart{\@citeb\@extra@b@citeb}%
            \NAT@test{2}\hyper@natlinkend\else
       \ifnum\NAT@sort>1
         \begingroup\catcode`\_8
            \ifcat _\ifnum\z@<0\NAT@num _\else A\fi
              \global\let\NAT@nm=\NAT@num \else \gdef\NAT@nm{-2}\fi
            \ifcat _\ifnum\z@<0\NAT@last@num _\else A\fi
              \global\@tempcnta\NAT@last@num
              \global\advance\@tempcnta \@ne
            \else \global\@tempcnta\m@ne\fi
         \endgroup
         \ifnum\NAT@nm=\@tempcnta
           \ifx\NAT@last@yr\relax
             \edef\NAT@last@yr{\@citea
                \csname o:mbox:\endcsname{\csname nb:link\endcsname
\NAT@num}}%
           \else
             \edef\NAT@last@yr{--\penalty
                \@m\csname o:mbox:\endcsname{\csname nb:link\endcsname
\NAT@num}}%
           \fi
         \else
           \NAT@last@yr \@citea \csname o:mbox:\endcsname{\csname nb:link\endcsname
\NAT@num}%
           \let\NAT@last@yr\relax
         \fi
       \else
         \@citea \csname o:mbox:\endcsname
               {\ifx\hyper@natanchorstart\@gobble
                    \Link{bibitem\NAT@num}{}\NAT@num
                    \EndLink
                \else
                    \hyper@natlinkstart{\@citeb\@extra@b@citeb}\NAT@num
                    \hyper@natlinkend
                \fi
               }%
       \fi
       \fi
       \def\@citea{\NAT@sep\penalty\@m\NAT@space}%
      \else
        \ifcase\NAT@ctype\relax
          \ifx\NAT@last@nm\NAT@nm \NAT@yrsep\penalty\@m\NAT@space\else
          \@citea \NAT@test{1}\ \NAT@@open
          \if\relax#1\relax\else#1\ \fi\fi \NAT@mbox{%
          \hyper@natlinkstart{\@citeb\@extra@b@citeb}%
          \NAT@num\hyper@natlinkend}%
          \def\@citea{\NAT@@close\NAT@sep\penalty\@m\ }%
        \or\@citea
          \hyper@natlinkstart{\@citeb\@extra@b@citeb}%
           \NAT@test{1}\hyper@natlinkend
          \def\@citea{\NAT@sep\penalty\@m\ }%
        \or\@citea
          \hyper@natlinkstart{\@citeb\@extra@b@citeb}\NAT@test{2}%
           \hyper@natlinkend
          \def\@citea{\NAT@sep\penalty\@m\ }%
        \fi
      \fi
      }}%
      \ifnum\NAT@sort>1\NAT@last@yr\fi
      \ifNAT@swa\else\ifnum\NAT@ctype=0\if\relax#2\relax\else
      \NAT@cmt\ #2\fi \NAT@@close\fi\fi}{#1}{#2}}
 \let\@citex\NAT@citexnum
\catcode`\:11

\else
  \def\hyper@natlinkstart#1{%
    \let\rel:hyper\def  \hyper@linkstart{cite}{X#1}%
    \def\hyper@nat@current{#1}%
  }
  \def\hyper@natlinkbreak#1#2{%
    \hyper@linkend#1\let\rel:hyper\def \hyper@linkstart{cite}{X#2}%
  }
  \def\hyper@natlinkend{\hyper@linkend}
  \expandafter\ifx \csname hyper@linkstart\endcsname\relax
   \def\hyper@linkstart#1#2{%
     \a:cite%
     \def\:temp{#1}%
     \ifx\:temp\@urltype
       \cIteLink[#2]{}{}%
     \else
       \ifx\rel:hyper\def\cIteLink{#2}{}\else\cIteLink[\##2]{}{}\fi
     \fi  \global\let\rel:hyper=\:UnDef
   }
   \def\hyper@linkend{\EndcIteLink\b:cite}
\fi
\long\def\:temp#1{}\ifx \:temp\hyper@natanchorstart
   \def\hyper@natanchorstart#1{\Link{}{X#1}\EndLink}
\fi

  \pend:defIII\NAT@cite{\let\mbox\o:mbox:}
\pend:defIII\NAT@citenum{\let\mbox\o:mbox:}

\fi
\Hinput{natbib}
\endinput

The important change is this:

 \def\hyper@linkstart#1#2{%
     \a:cite%
     \def\:temp{#1}%
     \ifx\:temp\@urltype
       \cIteLink[#2]{}{}%
     \else
       \ifx\rel:hyper\def\cIteLink{#2}{}\else\cIteLink[\##2]{}{}\fi
     \fi  \global\let\rel:hyper=\:UnDef
   }
   \def\hyper@linkend{\EndcIteLink\b:cite}

The \a:cite and \b:cite commands add the tags around the individual citations, \cIteLink is a custom link command, which needs to be configured correctly:

\LinkCommand\Xreflink{xref,id,rid,ref-type="bibr"}

\Configure{cite}{}{}
{\Xreflink}{\EndXreflink}

The link command used in fourth argument of \Configure{cite} must be defined using the \LinkCommand command. It takes arguments separated by commas:

\LinkCommand...................1 <= i <= 6

   Creates a \Link-like command

   #1   tag name
   #2   href-like attribute
   #3   name-like attribute
   #4   insertion
   #5   /, if empty element
   #6  replacement for #  (ignored if absent)

  Example:

    \LinkCommand\JSLink{a,\noexpand\jsref,name}
    \def\jsref="#1"{href="javascript:window.open('#1')"}

    \JSLink{a}{}xx\EndJSLink
    \Link{}{a}\EndLink       % or \JSLink{}{a}\EndJSLink

This is the result:

<p class="indent" >   Sophisticated macro scripts involving loops and conditional statements are,
admittedly, hard to write and read, and it may take some time to become familiar with it
[<xref 
 id="Xbib1" ref-type="bibr" >1</xref>].
</p>

You must log in to answer this question.

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