tex4ebook:使用 cleveref 进行引用

tex4ebook:使用 cleveref 进行引用

我用来cleveref创建对定理的自定义引用,例如

我必须参考定理 A1、A3 和 A4。

使用时tex4ebook,与定理的相应链接在技术上可以正常工作,但外观并不是最漂亮的:在上面的例子中,“A1“ 将是第一个链接,”、A3“第二个链接,以及”和 A4“将是第三个链接。有没有办法只链接“A1”、“A3”和“A4”(而不是分别链接逗号和单词“and”)?

以下是 MWE:

\documentclass[12pt]{book}
\usepackage{enumitem}
\usepackage{cleveref}
\usepackage{amsthm}

\newtheoremstyle{Theorem}{3pt}{3pt}{\itshape}{}{\bfseries}{}{.5em}{\thmname{#1}\thmnumber{#2}}
\theoremstyle{Theorem}
\newtheorem{TheoremA}{Theorem A}
\setlist[1]{leftmargin=*, labelsep=10pt, itemsep=1pt, label=\theTheoremA.\arabic*, align=parleft}
\crefname{A}{A}{A}
\crefformat{A}{A#2#1#3}
\crefrangeformat{A}{A#3#1#4 to~A#5#2#6}
\crefmultiformat{A}{A#2#1#3}{ and~A#2#1#3}{, A#2#1#3}{ and~A#2#1#3}

\begin{document}

\begin{TheoremA} \label[A]{A1}
This is Theorem A1.
\end{TheoremA} 

\begin{TheoremA} \label[A]{A2}
This is Theorem A2.
\end{TheoremA} 

\begin{TheoremA} \label[A]{A3}
This is Theorem A3.
\end{TheoremA} 

\begin{TheoremA} \label[A]{A4}
This is Theorem A4.
\end{TheoremA} 

This is a reference to the Theorems \cref{A1,A2}.

This is a reference to the Theorems \cref{A1,A3,A4}.

\end{document}

还有一个简单的配置文件:

\Preamble{xhtml}

\begin{document}
\EndPreamble

答案1

您可以尝试这个版本cleveref.4ht。它将仅添加参考编号的链接:

% cleveref.4ht (2023-03-10-14:19), generated from tex4ht-4ht.tex
% Copyright 2018-2023 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.
\immediate\write-1{version 2023-03-10-14:19}



% orig:refstepcounter is saved in cleveref-hooks.4ht
\let\cref@old@refstepcounter\orig:refstepcounter%
\def\refstepcounter{%
  \@ifnextchar[{\refstepcounter@optarg}{\refstepcounter@noarg}%]
}%

% fix for TeX4ht label mechanism
\def\cref:currentlabel#1{\let\cnt:currentlabel\@currentlabel
\def\:@currentlabel{\ifx \cnt:currentlabel\@currentlabel
   \expandafter\the\csname c@#1\endcsname\else \@currentlabel\fi}%
%
  \anc:lbl r{#1}%
}

\def\refstepcounter@noarg#1{%
  \cref@old@refstepcounter{#1}%
  \cref@constructprefix{#1}{\cref@result}%
  \@ifundefined{cref@#1@alias}%
    {\def\@tempa{#1}}%
    {\def\@tempa{\csname cref@#1@alias\endcsname}}%
  \protected@xdef\cref@currentlabel{%
    [\@tempa][\arabic{#1}][\cref@result]%
    \csname p@#1\endcsname\csname the#1\endcsname}%
    \cref:currentlabel{#1}%
    }%
\def\refstepcounter@optarg[#1]#2{%
  \cref@old@refstepcounter{#2}%
  \cref@constructprefix{#2}{\cref@result}%
  \@ifundefined{cref@#1@alias}%
    {\def\@tempa{#1}}%
    {\def\@tempa{\csname cref@#1@alias\endcsname}}%
  \protected@xdef\cref@currentlabel{%
    [\@tempa][\arabic{#2}][\cref@result]%
    \csname p@#2\endcsname\csname the#2\endcsname}%
    \cref:currentlabel{#2}%
  }%

\ifdefined\@firstoffive\else%
  \def\@firstoffive#1#2#3#4#5{#1}%
\fi
\def\:tempa#1#2{\bgroup%
  \def\rEfLiNK##1##2{\Link{##1}{}}%
  \def\XRrEfLiNK[##1]##2##3{\Link[##1]{##2}{}}% handle links from Xr and Xr-hyper
  \cref@getlabel{#2}{\@templabel}%
  #1{\expandafter\expandafter\expandafter\@firstoffive\csname r@#2\endcsname{}{}{}{}{}%
\@templabel\EndLink}{}{}%
  \egroup%
}%

\HLet\@@@setcref=\:tempa

\@ifpackageloaded{amsthm}{
  \let\cref@thmnoarg\@thm%
  \def\@thm{\@ifnextchar[{\cref@thmoptarg}{\cref@thmnoarg}}%]
  \def\:tempb[#1]#2#3#4{%
   % call original amsthm theorem definition, but
   % disable \:thm in order to prevent infinite loop
   \let\:thm\:gobble%
   \cref@thmnoarg{#2}%
   \o:cref@thmoptarg:[#1]{#2}{#3}{#4}
  }%
  \HLet\cref@thmoptarg\:tempb%
}{}%


\Hinput{cleveref}

\endinput

结果如下:

在此处输入图片描述

相关内容