我正在尝试.bib
从 git 更改日志生成一个 形状的“biblatex”数据库。典型的(?)项目如下所示:
@gitcommit{f1750d6,
author = {Brent Longborough},
date = {2013-12-15},
title = {Complete name changes
Decomplicate top-level PROCs (&VERSION -> &CONFIG)
},
title
该 MWE 生成的字段可以包含任何事物,并且我需要避免任何额外的外部命令(即不允许使用 sed、awk):
\documentclass{article}
\begin{document}
{\catcode`\%=12
\immediate\write18{
git --no-pager log --reverse --pretty='format:@gitcommit{%h,%n
author = {%an},%n
date = {%ad},%n
title = {%B},%n
commithash = {%H}
}' --date=short > \jobname.gll}
}
\end{document}
我应该尝试生成什么来代替title = {xxxx},
,以及如何将任何适当的 TeX 命令注入到\write18
生成的git
命令行中?
答案1
biblatex
具有恰当命名的字段类型verbatim
,可能适合此处的要求。文档州(第 14 页)
逐字字段以逐字模式处理,可能包含特殊字符。逐字字段的典型示例是
file
和doi
。
所以我们需要做的title
就是verbatim
通过
\DeclareDatamodelFields[type=field,datatype=verbatim]{
title,
}
我们可以出发了。
当然,有些东西甚至连verbatim
字段都无法忍受,到目前为止,我只能想到不匹配的花括号,但可能还有更多。不过,我们不需要担心大多数其他事情。s%
和\
s 完全没问题。
MWE(cave filecontents
em:这将覆盖gitlog.dbx
,gitlog.bbx
和\jobname.gll
)
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{filecontents}
\begin{filecontents*}{gitlog.dbx}
\DeclareDatamodelEntrytypes{gitcommit}
\DeclareDatamodelFields[type=field,datatype=literal]{
commithash,
}
\DeclareDatamodelFields[type=field,datatype=verbatim]{
title,
}
\DeclareDatamodelEntryfields[gitcommit]{
title,
author,
date,
commithash,
}
\end{filecontents*}
\begin{filecontents*}{gitlog.bbx}
\ProvidesFile{gitlog.bbx}[gitlog bibliography file 2015/11/17]
\defbibenvironment{bibliography}
{\list
{\printfield{entrykey}}
{\setlength{\labelwidth}{0pt}%
\setlength{\itemindent}{-\leftmargin}%
\setlength{\itemsep}{\bibitemsep}%
\setlength{\parsep}{\bibparsep}%
\renewcommand*{\makelabel}[1]{%
\hspace\labelsep\ttfamily##1}}}
{\endlist}
{\item}
\newbibmacro*{begentry}{}
\newbibmacro*{finentry}{\finentry}
\DeclareBibliographyDriver{gitcommit}{%
\usebibmacro{bibindex}%
\usebibmacro{begentry}%
\usebibmacro{title}%
\newblock%
\usebibmacro{author}%
\newunit
\usebibmacro{date}%
\newunit
\usebibmacro{commithash}
\usebibmacro{finentry}}
\newbibmacro*{commithash}{%
\printtext{%
\printfield{commithash}%
}}
\endinput
\end{filecontents*}
\usepackage[%
datamodel=gitlog,
bibstyle=gitlog,
sorting=none,
date=iso8601,
firstinits=true,
]{biblatex}
\begin{filecontents*}{\jobname.gll}
@gitcommit{f1750d6,
author = {Brent Longborough},
date = {2013-12-15},
title = {Complete name changes
Decomplicate top-level PROCs (&VERSION -> &CONFIG)
},
}
@gitcommit{9dce109,
author = {Brent Longborough},
date = {2015-11-15},
title = {Initial commit &&&&&& %
},
commithash = {9dce10970bb6be976ce59f76dd28e52abeb3b103} }
@gitcommit{f558cdd,
author = {Brent Longborough},
date = {2015-11-15},
title = {First code to build pseudo-bibfile
},
commithash = {f558cddc5a95acb1c081ead6f6e81cb9941941a0} }
@gitcommit{240f4c9,
author = {Brent Longborough},
date = {2015-11-15},
title = {Added data model (not working) - now we step back a bit
},
commithash = {240f4c9dbb22631f6098fbe45c409ef58cdddb09} }
@gitcommit{b4629f6,
author = {Brent Longborough},
date = {2015-11-16},
title = {First working version full of restrictions
},
commithash = {b4629f6bb7504b2d6e4a677294a761e1d1d5c659} }
@gitcommit{d651d24,
author = {Brent Longborough},
date = {2015-11-17},
title = {Gradually improving things (especially understanding)
},
commithash = {d651d249a3a14fd270a0f40e5d8124f6c552cc5b} }
@gitcommit{4c1dd2c,
author = {Brent Longborough},
date = {2015-11-17},
title = {Making an MWE for TeX.SX},
commithash = {4c1dd2c540ff8a2f2976d972d15071c1f54f9379},
verba = {4c1dd2c540ff8a2f2976d972d15071c1f54f9379} }
\end{filecontents*}
\addbibresource{\jobname.gll}
\begin{document}
\nocite{*}
\printbibliography[title={Change Log},type=gitcommit]
\end{document}