以下 MWE 发自这里
使用以下方式编译时不会出错:Latex —> Biber —> Latex。此外,它还产生了所需的结果。
但是,当使用 htlatex —> Biber —> htlatex 进行编译时,它会在第二次 htlatex 编译时产生以下类型的警告:
l.310 --- TeX4ht warning --- Problem with 'list' environment. Expected syntax:
\begin{list}{label}{spacing} \item.... \end{list} ---
! Missing number, treated as zero.
<to be read again>
\c:\end:itm
l.310 ...ography[title={Publication list by year}]
?
此外,它会跳过 html 文件中与新 bib 条目相对应的所有换行符,这似乎与警告信息直接相关。
这是不兼容还是错误?任何帮助或解决方法都将不胜感激。
这是 MWE:[编辑:在右侧 MWE 中添加 2 个 @misc 引用]
\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@Article{c,
date = 2020,
author = {Author, BBB},
title = {Title},
journaltitle = {Journal},
volume = 10,
number = 4,
pages = {100-141}}
@Misc{hh,
date = 2003,
author = {Misc, Misc},
title = {Misc},
journaltitle = {Misc},
pages = {100-141}}
@Report{hh2,
date = 2020,
author = {Misc, Misc},
title = {Misc},
journaltitle = {Misc},
pages = {100-141}}
@Misc{hh3,
date = 2005,
author = {Misc, Misc},
title = {Misc},
journaltitle = {Misc},
pages = {100-141}}
@Article{d,
date = 2003,
author = {Author, Amy},
title = {Title},
journaltitle = {Journal},
volume = 10,
number = 4,
pages = {100-141}}
@Article{i,
date = 2016,
author = {Author, Amy},
title = {Title},
journaltitle = {Journal},
volume = 10,
number = 4,
pages = {100-141}}
@patent{l,
year = 2016,
author = {Author, Amy},
title = {Patent 1},
number = 4,
pages = {100-141}}
@inproceedings{j,
date = 2020,
author = {Author, Amy},
title = {Title 1},
journaltitle = {Journal},
volume = 10,
number = 4,
pages = {100-141}}
@patent{o,
year = 2016,
author = {Author, Amy},
title = {Patent 1},
number = 4,
pages = {100-141}}
@patent{m,
year = 2016,
author = {Author, Amy},
title = {Patent 2},
number = 4,
pages = {100-141}}
@Article{n,
date = 2016,
author = {Author, Amy},
title = {Title},
journaltitle = {Journal},
volume = 10,
number = 4,
pages = {100-141}}
@Article{b,
date = 2003,
author = {Author, Amy},
title = {Title},
journaltitle = {Journal},
volume = 10,
number = 4,
pages = {100-141}}
\end{filecontents*}
\usepackage[backend=biber,defernumbers=true,sorting=ydnt]{biblatex}
\addbibresource{\jobname.bib}
\DeclareSourcemap{
\maps[datatype=bibtex]{
\map{
\pertype{article}
\step[fieldset=presort,fieldvalue=article]
}
\map{
\pertype{inproceedings}
\step[fieldset=presort,fieldvalue=inproceedings]
}
\map{
\pertype{patent}
\step[fieldset=presort,fieldvalue=patent]
}
}
}
\DeclareSortingTemplate{rasha}{
\sort[direction=ascending]{
\field{year}}
\sort{\field{presort}}
}
\defbibenvironment{bibliography}
{\enumerate}
{\endenumerate}
{\item[]}
\newcounter{myyear}
\setcounter{myyear}{0}
\newcommand\printyear{\textbf{\hspace*{-\leftmargin}\printfield{year}}\par}
\newcommand\bibsection[1]{\hspace*{-\leftmargin}\textbf{#1}\par\noindent}
\newcommand\printenum{\stepcounter{enumi}\hspace*{-\leftmargin}\arabic{enumi}.\space}
\newcommand\mybibitem{\printenum}
\renewbibmacro{begentry}{%
\ifnumgreater{\thefield{year}}{\value{myyear}}
{\printyear%
\setcounter{myyear}{\thefield{year}}%
\setcounter{enumi}{0}%
\xdef\mylastentrytype{}%
}%
{}%
\iffieldequals{entrytype}{\mylastentrytype}
{}
{%
\setcounter{enumi}{0}%
\iffieldequalstr{entrytype}{article}%
{\bibsection{Journal Articles}}%
{ \iffieldequalstr{entrytype}{inproceedings}%
{\bibsection{Conference Papers}%
}%
{\iffieldequalstr{entrytype}{patent}%
{\bibsection{Patents}%
\setcounter{enumi}{0}%
}%
{}%
}%
}%
\xdef\mylastentrytype{\thefield{entrytype}}%
}%
\mybibitem%
}
\begin{document}
\nocite{*}
\begin{refcontext}[sorting=rasha]
\printbibliography[title={Publication list by year}]
\end{refcontext}
\end{document}
答案1
这个例子对我来说有用,但我想你实际上想使用您在 TeX4ht 邮件列表上发布的示例。此示例实际上无法与 TeX4ht 配合使用,这是由自定义书目宏引起的。以下是修改后的版本,可在 PDF 和 HTML 中使用:
\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@Article{b,
date = 2003,
author = {Author, Amy},
title = {Title},
journaltitle = {Journal},
volume = 10,
number = 4,
pages = {100-141}}
@Article{c,
date = 2003,
author = {Author, BBB},
title = {Title},
journaltitle = {Journal},
volume = 10,
number = 4,
pages = {100-141}}
@Article{d,
date = 2003,
author = {Author, Amy},
title = {Title},
journaltitle = {Journal},
volume = 10,
number = 4,
pages = {100-141}}
@Article{i,
date = 2016,
author = {Author, Amy},
title = {Title},
journaltitle = {Journal},
volume = 10,
number = 4,
pages = {100-141}}
@patent{l,
year = 2016,
author = {Author, Amy},
title = {Patent 1},
number = 4,
pages = {100-141}}
@inproceedings{j,
date = 2016,
author = {Author, Amy},
title = {Title 1},
journaltitle = {Journal},
volume = 10,
number = 4,
pages = {100-141}}
@patent{o,
year = 2016,
author = {Author, Amy},
title = {Patent 1},
number = 4,
pages = {100-141}}
@patent{m,
year = 2016,
author = {Author, Amy},
title = {Patent 2},
number = 4,
pages = {100-141}}
@Article{n,
date = 2016,
author = {Author, Amy},
title = {Title},
journaltitle = {Journal},
volume = 10,
number = 4,
pages = {100-141}}
\end{filecontents*}
\usepackage[backend=biber,defernumbers=true,sorting=ydnt]{biblatex}
\addbibresource{\jobname.bib}
\DeclareSourcemap{
\maps[datatype=bibtex]{
\map{
\pertype{article}
\step[fieldset=presort,fieldvalue=article]
}
\map{
\pertype{inproceedings}
\step[fieldset=presort,fieldvalue=inproceedings]
}
\map{
\pertype{patent}
\step[fieldset=presort,fieldvalue=patent]
}
}
}
\DeclareSortingTemplate{rasha}{
\sort[direction=ascending]{
\field{year}}
\sort{\field{presort}}
}
\defbibenvironment{bibliography}
{\enumerate}
{\endenumerate}
{\item[]}
\newcounter{myyear}
\setcounter{myyear}{0}
\newcommand\printyear{\textbf{\hspace*{-\leftmargin}\printfield{year}}\par}
\newcommand\bibsection[1]{\hspace*{-\leftmargin}\textbf{#1}\par\noindent}
\newcommand\printenum{\stepcounter{enumi}\hspace*{-\leftmargin}\arabic{enumi}.\space}
\newcommand\mybibitem{\printenum}
\renewbibmacro{begentry}{%
\ifnumgreater{\thefield{year}}{\value{myyear}}
{\printyear%
\setcounter{myyear}{\thefield{year}}%
\setcounter{enumi}{0}%
\xdef\mylastentrytype{}%
}%
{}%
\iffieldequals{entrytype}{\mylastentrytype}
{}
{%
\setcounter{enumi}{0}%
\iffieldequalstr{entrytype}{article}%
{\bibsection{Journal Articles}}%
{ \iffieldequalstr{entrytype}{inproceedings}%
{\bibsection{Conference Papers}%
}%
{\iffieldequalstr{entrytype}{patent}%
{\bibsection{Patents}%
\setcounter{enumi}{0}%
}%
{}%
}%
}%
\xdef\mylastentrytype{\thefield{entrytype}}%
}
\mybibitem%
}
重要的部分是这样的:
\defbibenvironment{bibliography}
{\enumerate}
{\endenumerate}
{\item[]}
\newcounter{myyear}
\setcounter{myyear}{0}
\newcommand\printyear{\textbf{\hspace*{-\leftmargin}\printfield{year}}\par}
\newcommand\bibsection[1]{\hspace*{-\leftmargin}\textbf{#1}\par\noindent}
\newcommand\printenum{\stepcounter{enumi}\hspace*{-\leftmargin}\arabic{enumi}.\space}
\newcommand\mybibitem{\printenum}
\renewbibmacro{begentry}{%
\ifnumgreater{\thefield{year}}{\value{myyear}}
{\printyear%
\setcounter{myyear}{\thefield{year}}%
\setcounter{enumi}{0}%
\xdef\mylastentrytype{}%
}%
{}%
\iffieldequals{entrytype}{\mylastentrytype}
{}
{%
\setcounter{enumi}{0}%
\iffieldequalstr{entrytype}{article}%
{\bibsection{Journal Articles}}%
{ \iffieldequalstr{entrytype}{inproceedings}%
{\bibsection{Conference Papers}%
}%
{\iffieldequalstr{entrytype}{patent}%
{\bibsection{Patents}%
\setcounter{enumi}{0}%
}%
{}%
}%
}%
\xdef\mylastentrytype{\thefield{entrytype}}%
}
\mybibitem%
}
\begin{document}
\nocite{*}
\begin{refcontext}[sorting=rasha]
\printbibliography[title={Publication list by year}]
\end{refcontext}
\end{document}
它抑制在环境中打印项目编号bibliography
,因为它甚至会为各个部分打印数字:
\defbibenvironment{bibliography}
{\enumerate}
{\endenumerate}
{\item[]}
而是明确地打印产品编号:
\newcommand\printenum{\stepcounter{enumi}\hspace*{-\leftmargin}\arabic{enumi}.\space}
我已经定义了自定义宏来打印年份和出版物类型,因为它允许我们在 TeX4ht 中应用自定义格式。
这是 TeX4ht 的配置文件mycfg.cfg
:
\Preamble{xhtml}
\renewcommand\printyear{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="bibyear">}\printfield{year}\HCode{</div>}\par}
\renewcommand\bibsection[1]{\ifvmode\IgnorePar\fi\EndP\HCode{<div class="bibsection">}#1\HCode{</div>}\par}
\Css{.bibyear{font-size: 1.3em; margin-top: 1em;font-weight: bold;}}
\Css{.bibsection{font-size: 1em; margin-top: 1em;font-weight: bold;}}
\Css{.bibyear + .bibsection{margin-top: 0.5em;}}
\Css{.bibsection + p {margin-top: 0.5em;}}
\begin{document}
\EndPreamble
它只是重新定义宏来插入一些 HTML 标签并使用 CSS 来设置它们的样式。
使用以下方式编译文档
make4ht -c mycfg.cfg filename.tex
这是 HTML 版本:
PDF 版本如下: