jgm / citeproc

CSL citation processing library in Haskell
BSD 2-Clause "Simplified" License
154 stars 16 forks source link

Two pandoc citeproc problems #41

Closed whrose closed 3 years ago

whrose commented 3 years ago

When using the new --citeproc option (having used the pandoc-citeproc previously) I find the following problems:

  1. the first item in a Reference list is preceded by an unexplicable number ‘10‘.
  2. the url field in the biblatex entry is not found in the item in the Reference list.

I will try to attach a document showing the difference between the output of the old pandoc-citeproc and the new --citeproc resulting in the ‘Reference list’, but also show it here:


@online{Lonardo2017Appunti,
    author       = {Lonardo, A.},
    title        = {{Appunti per visitare la basilica di San Marco
                       a Venezia, chiave per scoprire i segreti
                       medioevali della laguna}},
    address      = {\emph{Gli Scritto} [blog]},
    publisher    = {},
    year         = {2017},
    month        = {7},
    day          = {3},
    doi          = {},
    url          = {http://www.gliscritti.it/blog/entry/4205},
    urldate      = {},
    shorttitle   = {{Appunti}},
    keywords     = {@ART-Venice-San-Marco-Pentecost-Cupola},
}

---
nocite: |
  @Lonardo2017Appunti
---

output when using depecrated pandoc-citeproc filter

Lonardo, A. 2017. ‘Appunti per visitare la basilica di San Marco a Venezia, chiave per scoprire i segreti medioevali della laguna’. Gli Scritto [blog]. 3 juli 2017. http://www.gliscritti.it/blog/entry/4205.

Reference list

10 Lonardo, A. 2017. ‘Appunti per visitare la basilica di San Marco a Venezia, chiave per scoprire i segreti medioevali della laguna’. Gli Scritto [blog]. 3 juli 2017.


New_pandoc_citeproc_problems.pdf

jgm commented 3 years ago

On 2: your bibtex entry has both a doi and a url. If you remove the empty doi, the URL will render. The default chicago-author-date.csl has

          <choose>
            <if variable="DOI">
              <text variable="DOI" prefix="https://doi.org/"/>
            </if>
            <else>
              <text variable="URL"/>
            </else>
          </choose>

I think this is a bug; the doi variable shouldn't match if its content is empty, so this needs looking into.

On 1: I don't see the 10 when I try this. What pandoc version are you using, and what exact command did you use to produce this output?

jgm commented 3 years ago

Note: I don't think the "if" clause is being triggered here. If it were, we'd get the prefix. Also, I confirmed that doi is parsed as TextVal "" which should be considered empty. Correction: it is being triggered, as we can see by inserting <text value="BLAH"/> there. Not sure why though!

jgm commented 3 years ago

Aha. Putting a trace in before we call citeproc from pandoc, I see:

(Variable "doi",FancyVal (Many {unMany = fromList [Link ("",[],[]) [Str ""] ("https://doi.org/","")]}))

Culprit then is linkifyVariables, which should do nothing when the variable is empty.

jgm commented 3 years ago

I've fixed 2 in pandoc. Can't reproduce 1.

whrose commented 3 years ago

Thank you very much for fixing #2, that is very much appreciated. With respect to #1: I use pandoc version 2.11.3.1, and in vim I call for this command: !pandoc -t latex % --bibliography=/Users/whrose/pandocworkshop/masterwiki.bib --template=eisvowhr --top-level-division=part -F pandoc-crossref --citeproc --pdf-engine=xelatex -s -o /Users/whrose/pandocworkshop/pandoc_output.pdf

jgm commented 3 years ago

The problem is almost certainly that your custom template needs to be updated, if it's one designed for pandoc < 2.11. For one thing, the latex environment used for CSLReferences now takes a different number of arguments. I'm sure the 1 and 0 are the values pandoc is supplying for these parameters. Here's a diff from pandoc 2.10.1 to the current version:

diff --git a/data/templates/default.latex b/data/templates/default.latex
index d6cca9c98..169661582 100644
--- a/data/templates/default.latex
+++ b/data/templates/default.latex
@@ -89,6 +89,7 @@ $endif$
 $if(beamerarticle)$
 \usepackage{beamerarticle} % needs to be loaded first
 $endif$
+\usepackage{amsmath,amssymb}
 $if(fontfamily)$
 \usepackage[$for(fontfamilyoptions)$$fontfamilyoptions$$sep$,$endfor$]{$fontfamily$}
 $else$
@@ -97,7 +98,6 @@ $endif$
 $if(linestretch)$
 \usepackage{setspace}
 $endif$
-\usepackage{amssymb,amsmath}
 \usepackage{ifxetex,ifluatex}
 \ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex
   \usepackage[$if(fontenc)$$fontenc$$else$T1$endif$]{fontenc}
@@ -254,7 +254,8 @@ $if(highlighting-macros)$
 $highlighting-macros$
 $endif$
 $if(tables)$
-\usepackage{longtable,booktabs}
+\usepackage{longtable,booktabs,array}
+\usepackage{calc} % for calculating minipage widths
 $if(beamer)$
 \usepackage{caption}
 % Make caption package work with longtable
@@ -333,7 +334,10 @@ $for(polyglossia-otherlangs)$
   \setotherlanguage[$for(polyglossia-otherlangs.options)$$polyglossia-otherlangs.options$$sep$,$endfor$]{$polyglossia-otherlangs.name$}
 $endfor$
 \else
-  \usepackage[shorthands=off,$for(babel-otherlangs)$$babel-otherlangs$,$endfor$main=$babel-lang$]{babel}
+  \usepackage[$for(babel-otherlangs)$$babel-otherlangs$,$endfor$main=$babel-lang$]{babel}
+% get rid of language-specific shorthands (see #6817):
+\let\LanguageShortHands\languageshorthands
+\def\languageshorthands#1{}
 $if(babel-newcommands)$
   $babel-newcommands$
 $endif$
@@ -368,10 +372,27 @@ $endif$
 $if(csl-refs)$
 \newlength{\cslhangindent}
 \setlength{\cslhangindent}{1.5em}
-\newenvironment{cslreferences}%
-  {$if(csl-hanging-indent)$\setlength{\parindent}{0pt}%
-  \everypar{\setlength{\hangindent}{\cslhangindent}}\ignorespaces$endif$}%
-  {\par}
+\newlength{\csllabelwidth}
+\setlength{\csllabelwidth}{3em}
+\newenvironment{CSLReferences}[2] % #1 hanging-ident, #2 entry spacing
+ {% don't indent paragraphs
+  \setlength{\parindent}{0pt}
+  % turn on hanging indent if param 1 is 1
+  \ifodd #1 \everypar{\setlength{\hangindent}{\cslhangindent}}\ignorespaces\fi
+  % set entry spacing
+  \ifnum #2 > 0
+  \setlength{\parskip}{#2\baselineskip}
+  \fi
+ }%
+ {}
+\usepackage{calc}
+\newcommand{\CSLBlock}[1]{#1\hfill\break}
+\newcommand{\CSLLeftMargin}[1]{\parbox[t]{\csllabelwidth}{#1}}
+\newcommand{\CSLRightInline}[1]{\parbox[t]{\linewidth - \csllabelwidth}{#1}\break}
+\newcommand{\CSLIndent}[1]{\hspace{\cslhangindent}#1}
+$endif$
+$if(csquotes)$
+\usepackage{csquotes}
 $endif$

 $if(title)$
whrose commented 3 years ago

Thanks for pointing me to where the problem lies. I will update my template accordingly.

Thanks very much for solving two problems in one day!

Merry Christmas!

Wolter

Sent from my iPad

On 24 Dec 2020, at 20:00, John MacFarlane notifications@github.com wrote:

 The problem is almost certainly that your custom template needs to be updated, if it's one designed for pandoc < 2.11. For one thing, the latex environment used for CSLReferences now takes a different number of arguments.

diff --git a/data/templates/default.latex b/data/templates/default.latex index d6cca9c98..169661582 100644 --- a/data/templates/default.latex +++ b/data/templates/default.latex @@ -89,6 +89,7 @@ $endif$ $if(beamerarticle)$ \usepackage{beamerarticle} % needs to be loaded first $endif$ +\usepackage{amsmath,amssymb} $if(fontfamily)$ \usepackage[$for(fontfamilyoptions)$$fontfamilyoptions$$sep$,$endfor$]{$fontfamily$} $else$ @@ -97,7 +98,6 @@ $endif$ $if(linestretch)$ \usepackage{setspace} $endif$ -\usepackage{amssymb,amsmath} \usepackage{ifxetex,ifluatex} \ifnum 0\ifxetex 1\fi\ifluatex 1\fi=0 % if pdftex \usepackage[$if(fontenc)$$fontenc$$else$T1$endif$]{fontenc} @@ -254,7 +254,8 @@ $if(highlighting-macros)$ $highlighting-macros$ $endif$ $if(tables)$ -\usepackage{longtable,booktabs} +\usepackage{longtable,booktabs,array} +\usepackage{calc} % for calculating minipage widths $if(beamer)$ \usepackage{caption} % Make caption package work with longtable @@ -333,7 +334,10 @@ $for(polyglossia-otherlangs)$ \setotherlanguage[$for(polyglossia-otherlangs.options)$$polyglossia-otherlangs.options$$sep$,$endfor$]{$polyglossia-otherlangs.name$} $endfor$ \else

  • \usepackage[shorthands=off,$for(babel-otherlangs)$$babel-otherlangs$,$endfor$main=$babel-lang$]{babel}
  • \usepackage[$for(babel-otherlangs)$$babel-otherlangs$,$endfor$main=$babel-lang$]{babel} +% get rid of language-specific shorthands (see #6817): +\let\LanguageShortHands\languageshorthands +\def\languageshorthands#1{} $if(babel-newcommands)$ $babel-newcommands$ $endif$ @@ -368,10 +372,27 @@ $endif$ $if(csl-refs)$ \newlength{\cslhangindent} \setlength{\cslhangindent}{1.5em} -\newenvironment{cslreferences}%
  • {$if(csl-hanging-indent)$\setlength{\parindent}{0pt}%
  • \everypar{\setlength{\hangindent}{\cslhangindent}}\ignorespaces$endif$}%
  • {\par} +\newlength{\csllabelwidth} +\setlength{\csllabelwidth}{3em} +\newenvironment{CSLReferences}[2] % #1 hanging-ident, #2 entry spacing
  • {% don't indent paragraphs
  • \setlength{\parindent}{0pt}
  • % turn on hanging indent if param 1 is 1
  • \ifodd #1 \everypar{\setlength{\hangindent}{\cslhangindent}}\ignorespaces\fi
  • % set entry spacing
  • \ifnum #2 > 0
  • \setlength{\parskip}{#2\baselineskip}
  • \fi
  • }%
  • {} +\usepackage{calc} +\newcommand{\CSLBlock}[1]{#1\hfill\break} +\newcommand{\CSLLeftMargin}[1]{\parbox[t]{\csllabelwidth}{#1}} +\newcommand{\CSLRightInline}[1]{\parbox[t]{\linewidth - \csllabelwidth}{#1}\break} +\newcommand{\CSLIndent}[1]{\hspace{\cslhangindent}#1} +$endif$ +$if(csquotes)$ +\usepackage{csquotes} $endif$

    $if(title)$ — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.