stsewd / ieee-pandoc-template

IEEE paper template for pandoc
MIT License
121 stars 41 forks source link

cslreferences error #12

Closed aparcar closed 1 year ago

aparcar commented 4 years ago

I'm getting the following error when using with bibtext:

pandoc -o build/paper.pdf --bibliography=bibliography.bib --csl=bibliography.csl -s -f markdown --template=template.latex paper.md metadata.yaml
Error producing PDF.
! LaTeX Error: Environment cslreferences undefined.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...

l.530 \begin{cslreferences}

make: *** [makefile:16: pdf] Error 43
aparcar commented 4 years ago

https://github.com/mpark/wg21/issues/54#issuecomment-569867462

moedn commented 3 years ago

@aparcar the solution seems to be a few comments below your linked one; it didn't work for me (running pandoc 2.11) – apparently the error came back in a later update.

adding the following lines to template.latex fixed it :tada: (thanks to this comment

$if(csl-refs)$
\newlength{\cslhangindent}
\setlength{\cslhangindent}{1.5em}
\newlength{\csllabelwidth}
\setlength{\csllabelwidth}{3em}
\newenvironment{CSLReferences}[3] % #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} % for \widthof, \maxof
\newcommand{\CSLBlock}[1]{#1\hfill\break}
\newcommand{\CSLLeftMargin}[1]{\parbox[t]{\maxof{\widthof{#1}}{\csllabelwidth}}{#1}}
\newcommand{\CSLRightInline}[1]{\parbox[t]{\linewidth}{#1}}
\newcommand{\CSLIndent}[1]{\hspace{\cslhangindent}#1}
$endif$

I could create a pull request, but I feel that I know too less about latex for that. I just copy&pasted these lines into the template directly after line 1. I assume there's some underlying logic in the document and I don't want to break it.

Also, this template works for general compilation with pandoc. Just add it to pandoc's template folder, put the YAML header in the MD file (where you specify CSL and bibliography file) and run

pandoc test.md -o test.pdf --citeproc --template="ieee" --bibliography=IEEE2021-bib.json --csl=ieee.csl

from inside the folder containing the MD file.

→ like that one can skip the 'edit paper.md and run make and get the file from build' step

nobodywasishere commented 2 years ago

@moedn Adding that to template.latex at line 2 gives me a different error that I'm not sure how to diagnose:

$ make

pandoc -o build/paper.pdf --bibliography=bibliography.bib --csl=bibliography.csl \
    -s -f markdown --citeproc --template=template.latex paper.md metadata.yaml
Error producing PDF.
! You can't use `\vadjust' in vertical mode.
l.166 \leavevmode\vadjust

make: *** [makefile:17: pdf] Error 43
arun5309 commented 2 years ago

@nobodywasishere I faced the same issue. So, I copy pasted the below code at the same place and this fixed the issue for me.

$if(csl-refs)$
% Pandoc citation processing
\newlength{\cslhangindent}
\setlength{\cslhangindent}{1.5em}
\newlength{\csllabelwidth}
\setlength{\csllabelwidth}{3em}
\newlength{\cslentryspacingunit} % times entry-spacing
\setlength{\cslentryspacingunit}{\parskip}
% for Pandoc 2.8 to 2.10.1
\newenvironment{cslreferences}%
  {$if(csl-hanging-indent)$\setlength{\parindent}{0pt}%
  \everypar{\setlength{\hangindent}{\cslhangindent}}\ignorespaces$endif$}%
  {\par}
% For Pandoc 2.11+
\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
  \let\oldpar\par
  \def\par{\hangindent=\cslhangindent\oldpar}
  \fi
  % set entry spacing
  \setlength{\parskip}{#2\cslentryspacingunit}
 }%
 {}
\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$

I got this code from here.

stsewd commented 1 year ago

Should be fixed with https://github.com/stsewd/ieee-pandoc-template/pull/15.