From 4631b0c3499e3a3fb1f7336870b47ab7c8830828 Mon Sep 17 00:00:00 2001 From: jdutant <34026710+jdutant@users.noreply.github.com> Date: Sat, 13 Feb 2021 00:00:40 +0000 Subject: [PATCH 01/13] Initial commit Works in LaTeX and HTML. Issues: - doesn't preserve the classes and attributes of the DIV "refs" - need to customize the output on hanging and spacing - 'csl-ref' isn't usable in the template - put the formatting commands in a global variable --- bibliography-place/LICENSE | 21 ++++ bibliography-place/Makefile | 35 +++++++ bibliography-place/README.md | 100 ++++++++++++++++++++ bibliography-place/bibliography-place.lua | 56 +++++++++++ bibliography-place/expected_filtered.html | 22 +++++ bibliography-place/expected_filtered.tex | 49 ++++++++++ bibliography-place/expected_unfiltered.html | 23 +++++ bibliography-place/expected_unfiltered.tex | 49 ++++++++++ bibliography-place/sample.md | 15 +++ bibliography-place/template-broken.latex | 56 +++++++++++ bibliography-place/template.html | 20 ++++ bibliography-place/template.latex | 44 +++++++++ 12 files changed, 490 insertions(+) create mode 100644 bibliography-place/LICENSE create mode 100644 bibliography-place/Makefile create mode 100644 bibliography-place/README.md create mode 100644 bibliography-place/bibliography-place.lua create mode 100644 bibliography-place/expected_filtered.html create mode 100644 bibliography-place/expected_filtered.tex create mode 100644 bibliography-place/expected_unfiltered.html create mode 100644 bibliography-place/expected_unfiltered.tex create mode 100644 bibliography-place/sample.md create mode 100644 bibliography-place/template-broken.latex create mode 100644 bibliography-place/template.html create mode 100644 bibliography-place/template.latex diff --git a/bibliography-place/LICENSE b/bibliography-place/LICENSE new file mode 100644 index 00000000..b4e8923c --- /dev/null +++ b/bibliography-place/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Julien Dutant + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/bibliography-place/Makefile b/bibliography-place/Makefile new file mode 100644 index 00000000..ed27305e --- /dev/null +++ b/bibliography-place/Makefile @@ -0,0 +1,35 @@ +DIFF ?= diff --strip-trailing-cr -u + +.PHONY: test + +test: latex html + +latex: sample.md expected_filtered.tex expected_unfiltered.tex bibliography-place.lua + @pandoc -s --citeproc --to latex --template template $< \ + | $(DIFF) expected_unfiltered.tex - + @pandoc -s --citeproc --lua-filter bibliography-place.lua --to=latex \ + --template template $< | $(DIFF) expected_filtered.tex - + +html: sample.md expected_filtered.html expected_unfiltered.html + @pandoc -s --citeproc --to=html --template template $< \ + | $(DIFF) expected_unfiltered.html - + @pandoc -s --citeproc --lua-filter bibliography-place.lua --to=html \ + --template template $< | $(DIFF) expected_filtered.html - + +expected_filtered.html : sample.md bibliography-place.lua + @pandoc -s --citeproc --lua-filter bibliography-place.lua \ + --output expected_filtered.html \ + --template template $< \ + +expected_filtered.tex : sample.md bibliography-place.lua + @pandoc -s --citeproc --lua-filter bibliography-place.lua \ + --output expected_filtered.tex \ + --template template $< + +expected_unfiltered.html : sample.md bibliography-place.lua + @pandoc -s --citeproc --output expected_unfiltered.html \ + --template template $< + +expected_unfiltered.tex : sample.md bibliography-place.lua + @pandoc -s --citeproc --output expected_unfiltered.tex \ + --template template $< diff --git a/bibliography-place/README.md b/bibliography-place/README.md new file mode 100644 index 00000000..b1e4a258 --- /dev/null +++ b/bibliography-place/README.md @@ -0,0 +1,100 @@ +--- +title: "Bibliography-place: controlling the placement of the + bibliography via Pandoc templates" +author: "Julien Dutant" +--- + +Bibliography place +======= + +Allows controlling the placement of the bibliography via Pandoc +templates. + +Introduction +------------ + + + +Keeps parts of a document out of selected output formats. + +v1.0. Copyright: © 2021 Julien Dutant +License: MIT - see LICENSE file for details. + +Usage +----- + +This Lua filter for Pandoc that keeps parts of a document out of selected outputs formats. + +*Use case*. Sometimes a bit of markdown will convert well through Pandoc +to some formats not others. Say, you have a table that is reasonably +well converted to html and docx, but you want more control on the +LaTeX output. This filter allows you to: + +* Enter the desired LaTeX table output as a [fenced block with a raw + attribute](https://pandoc.org/MANUAL.html#extension-raw_attribute). +* Mark up the markdown table so that it is output only in formats other + than LaTeX. + +*Usage*. Mark up the part you want to keep out of some output format(s) +as a native Div with the attributes `not-in-format` and the names of the +format(s) in question: + +```markdown +::: {.not-in-format .latex .beamer} + +--------------------------- +This table is not kept +----------- ---------------- +in formats latex, beamer +---------------------------- + +::: +``` + +Use format names for [Pandoc's list of output formats](https://pandoc.org/MANUAL.html#option--to), which you can print out by running ```pandoc --list-output-formats```. + +You would normally provide a raw equivalent for the part in question in +the format(s) in question, using Pandoc's [fenced blocks with a raw +attribute](https://pandoc.org/MANUAL.html#extension-raw_attribute): + +```markdown +::: {.not-in-format .latex .beamer} + +--------------------------- +This table is not kept +----------- ---------------- +in formats latex, beamer +---------------------------- + +::: + +~~~{=latex} + +begin{tabular}{|c|c|} +\toprule +This table & is not kept \\ \addlinespace +\midrule +\endhead +in formats & latex, beamer \\ \addlinespace +\bottomrule +\end{tabluar} + +~~~ +``` + +A fenced block with a raw attribute can only have one attribute, so you +need one for each format for which the markdown is left out. But Pandoc +will output the raw block in equivalent formats: a `latex` block will +be output in `latex` and `beamer`, a `html5` block in `html` and `epub3` +and so on. See [Pandoc's manual](https://pandoc.org/MANUAL.html#extension-raw_attribute). + +Installation +------------ + +Copy `not-in-format.lua` in your document folder or in your pandoc data +dir path. + +Contributing +------------ + +PRs welcome. diff --git a/bibliography-place/bibliography-place.lua b/bibliography-place/bibliography-place.lua new file mode 100644 index 00000000..e4ffbc16 --- /dev/null +++ b/bibliography-place/bibliography-place.lua @@ -0,0 +1,56 @@ +--- # not-in-format - keep document parts out of selected output formats. +-- +-- This Lua filter for Pandoc allows placement of the bibliography +-- to be controlled in pandoc templates. +-- +-- @author Julien Dutant +-- @author Albert Krewinkel +-- @copyright 2021 Julien Dutant, Albert Krewinkel +-- @license MIT - see LICENSE file for details. +-- @release 1.0 + +local references = pandoc.List:new() + +--- Add environment to the references Div if needed +-- takes the body of references (list of blocks) +-- and wraps it in suitable environment commands for +-- each format. id needed for links. +-- @param content content of the bibliography +-- @param id identifier of the bibliography +local function add_environment(content, id) + if FORMAT:match("latex") then + content:insert(1,pandoc.RawBlock("latex", + "\\hypertarget{refs}{" .. id .. "}")) + content:insert(1,pandoc.RawBlock("latex", "\\begin{CSLReferences}{1}{0}")) + content:insert(pandoc.RawBlock("latex", "\\end{CSLReferences}")) + elseif FORMAT:match("html.*") then + -- wrap the content in an HTML Div + content:insert(1,pandoc.RawBlock("html", '
')) + content:insert(pandoc.RawBlock("html", '
')) + end + return content +end + +--- Div filter for the 'refs' Div. +-- Extract the Div with identifer 'refs' if present and +-- save it in `references`. +-- @param element a Div element +-- @return an empty list if Div has identifier `refs` +function Div(element) + if element.identifier == 'refs' + or element.classes:includes('csl-bib-body') then + references = add_environment(element.content, element.identifier) + return {} -- remove from main body + end +end + +--- Meta filter. +-- Places the references block (as string) in the `references` +-- field of the document's metadata. The template can +-- print it by using `$meta.references$`. +-- @param meta the document's metadata block +-- @return the modified metadata block +function Meta (meta) + meta.referencesblock = references + return meta +end diff --git a/bibliography-place/expected_filtered.html b/bibliography-place/expected_filtered.html new file mode 100644 index 00000000..b4eb8bd7 --- /dev/null +++ b/bibliography-place/expected_filtered.html @@ -0,0 +1,22 @@ + + + Sample document + + + +

I enjoyed Doe (1979).

+ +Seymour Butz +School of Studies + + + +
+
+Doe, Jane. 1979. Short Stories. +
+
+ + + + diff --git a/bibliography-place/expected_filtered.tex b/bibliography-place/expected_filtered.tex new file mode 100644 index 00000000..120145d7 --- /dev/null +++ b/bibliography-place/expected_filtered.tex @@ -0,0 +1,49 @@ +% A minimal template + +% Preamble commands for each bibliography engine +% These are included in Pandoc's default template +% +% TODO: when the filter has put the references in the +% metadata field, Pandoc's LaTeX writer doesn't +% set (csl-refs) to true, so we can't use if(csl-refs) +% +\newlength{\cslhangindent} +\setlength{\cslhangindent}{1.5em} +\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} + +\begin{document} + +I enjoyed Doe (1979). + +Seymour Butz +School of Studies + +% Refs should be below this + +\begin{CSLReferences}{1}{0} + +\hypertarget{refs}{refs} + +\leavevmode\hypertarget{ref-Doe}{}% +Doe, Jane. 1979. \emph{Short Stories}. + +\end{CSLReferences} + +\end{document} diff --git a/bibliography-place/expected_unfiltered.html b/bibliography-place/expected_unfiltered.html new file mode 100644 index 00000000..1fb90be4 --- /dev/null +++ b/bibliography-place/expected_unfiltered.html @@ -0,0 +1,23 @@ + + + Sample document + + + +

I enjoyed Doe (1979).

+
+
+Doe, Jane. 1979. Short Stories. +
+
+ +Seymour Butz +School of Studies + + + + + + + + diff --git a/bibliography-place/expected_unfiltered.tex b/bibliography-place/expected_unfiltered.tex new file mode 100644 index 00000000..541fe7ec --- /dev/null +++ b/bibliography-place/expected_unfiltered.tex @@ -0,0 +1,49 @@ +% A minimal template + +% Preamble commands for each bibliography engine +% These are included in Pandoc's default template +% +% TODO: when the filter has put the references in the +% metadata field, Pandoc's LaTeX writer doesn't +% set (csl-refs) to true, so we can't use if(csl-refs) +% +\newlength{\cslhangindent} +\setlength{\cslhangindent}{1.5em} +\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} + +\begin{document} + +I enjoyed Doe (1979). + +\hypertarget{refs}{} +\begin{CSLReferences}{1}{0} +\leavevmode\hypertarget{ref-Doe}{}% +Doe, Jane. 1979. \emph{Short Stories}. + +\end{CSLReferences} + +Seymour Butz +School of Studies + +% Refs should be below this + + + +\end{document} diff --git a/bibliography-place/sample.md b/bibliography-place/sample.md new file mode 100644 index 00000000..80dd2b7b --- /dev/null +++ b/bibliography-place/sample.md @@ -0,0 +1,15 @@ +--- +title: Sample document +author: Seymour Butz +institute: School of Studies +references: +- author: + - family: Doe + given: Jane + id: Doe + issued: 1979 + title: Short stories + type: book +... + +I enjoyed @Doe. diff --git a/bibliography-place/template-broken.latex b/bibliography-place/template-broken.latex new file mode 100644 index 00000000..557e8977 --- /dev/null +++ b/bibliography-place/template-broken.latex @@ -0,0 +1,56 @@ +% A minimal template + +% Preamble commands for each bibliography engine +% These are included in Pandoc's default template +% +% TODO: when the filter has put the references in the +% metadata field, Pandoc's LaTeX writer doesn't +% set (csl-refs) to true, so we can't use if(csl-refs) +% +$if(natbib)$ +\usepackage[$natbiboptions$]{natbib} +\bibliographystyle{$if(biblio-style)$$biblio-style$$else$plainnat$endif$} +$endif$ +$if(biblatex)$ +\usepackage[$if(biblio-style)$style=$biblio-style$,$endif$$for(biblatexoptions)$$biblatexoptions$$sep$,$endfor$]{biblatex} +$for(bibliography)$ +\addbibresource{$bibliography$} +$endfor$ +$endif$ +$if(csl-refs)$ +\newlength{\cslhangindent} +\setlength{\cslhangindent}{1.5em} +\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$ + +\begin{document} + +$body$ + +$for(author)$$author$$endfor$ +$if(institute)$ +$for(institute)$$institute$$endfor$ +$endif$ + +% Refs should be below this + +$if(referencesblock)$$referencesblock$$endif$ + +\end{document} diff --git a/bibliography-place/template.html b/bibliography-place/template.html new file mode 100644 index 00000000..063a9d98 --- /dev/null +++ b/bibliography-place/template.html @@ -0,0 +1,20 @@ + + + $if(title-prefix)$$title-prefix$ – $endif$$pagetitle$ + + + +$body$ + +$for(author)$$author$$endfor$ +$if(institute)$ +$for(institute)$$institute$$endfor$ +$endif$ + + + +$if(referencesblock)$$referencesblock$$endif$ + + + + diff --git a/bibliography-place/template.latex b/bibliography-place/template.latex new file mode 100644 index 00000000..952c4707 --- /dev/null +++ b/bibliography-place/template.latex @@ -0,0 +1,44 @@ +% A minimal template + +% Preamble commands for each bibliography engine +% These are included in Pandoc's default template +% +% TODO: when the filter has put the references in the +% metadata field, Pandoc's LaTeX writer doesn't +% set (csl-refs) to true, so we can't use if(csl-refs) +% +\newlength{\cslhangindent} +\setlength{\cslhangindent}{1.5em} +\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} + +\begin{document} + +$body$ + +$for(author)$$author$$endfor$ +$if(institute)$ +$for(institute)$$institute$$endfor$ +$endif$ + +% Refs should be below this + +$if(referencesblock)$$referencesblock$$endif$ + +\end{document} From ec3c2efa78eed1b995876efa01fd6fd3789f6c59 Mon Sep 17 00:00:00 2001 From: jdutant <34026710+jdutant@users.noreply.github.com> Date: Sat, 13 Feb 2021 00:28:06 +0000 Subject: [PATCH 02/13] update README.md --- bibliography-place/README.md | 106 ++++++---------------- bibliography-place/bibliography-place.lua | 5 +- 2 files changed, 32 insertions(+), 79 deletions(-) diff --git a/bibliography-place/README.md b/bibliography-place/README.md index b1e4a258..5f77fea3 100644 --- a/bibliography-place/README.md +++ b/bibliography-place/README.md @@ -1,100 +1,52 @@ --- -title: "Bibliography-place: controlling the placement of the - bibliography via Pandoc templates" +title: "Bibliography-place" author: "Julien Dutant" --- Bibliography place ======= -Allows controlling the placement of the bibliography via Pandoc -templates. +**WORK IN PROGRESS** + +Control the placement of a `citeproc`-generated bibliography +via Pandoc templates. Introduction ------------ +In Pandoc templates the main text is contained in the variable +`$body$`. Suppose you want your document template to add something +just below the body, such as the author's name and affiliation: - -Keeps parts of a document out of selected output formats. - -v1.0. Copyright: © 2021 Julien Dutant -License: MIT - see LICENSE file for details. - -Usage ------ - -This Lua filter for Pandoc that keeps parts of a document out of selected outputs formats. - -*Use case*. Sometimes a bit of markdown will convert well through Pandoc -to some formats not others. Say, you have a table that is reasonably -well converted to html and docx, but you want more control on the -LaTeX output. This filter allows you to: - -* Enter the desired LaTeX table output as a [fenced block with a raw - attribute](https://pandoc.org/MANUAL.html#extension-raw_attribute). -* Mark up the markdown table so that it is output only in formats other - than LaTeX. - -*Usage*. Mark up the part you want to keep out of some output format(s) -as a native Div with the attributes `not-in-format` and the names of the -format(s) in question: - -```markdown -::: {.not-in-format .latex .beamer} - ---------------------------- -This table is not kept ------------ ---------------- -in formats latex, beamer ----------------------------- - -::: ``` +$body$ -Use format names for [Pandoc's list of output formats](https://pandoc.org/MANUAL.html#option--to), which you can print out by running ```pandoc --list-output-formats```. - -You would normally provide a raw equivalent for the part in question in -the format(s) in question, using Pandoc's [fenced blocks with a raw -attribute](https://pandoc.org/MANUAL.html#extension-raw_attribute): - -```markdown -::: {.not-in-format .latex .beamer} +$for(author)$$author$$endfor$ +$if(institute)$ +$for(institute)$$institute$$endfor$ +$endif$ ---------------------------- -This table is not kept ------------ ---------------- -in formats latex, beamer ----------------------------- +``` -::: +When using `citeproc` to generate a bibliography you will not get +the desired result, because `citeproc`-generated bibliographies +are inserted at the end of the `$body$`` variable. The template +above will print the author's name and institute after the +bibliography. -~~~{=latex} +This filter takes the `citeproc` bibliography out of `$body$` and +places it in a `$referencesblock$` variable instead. -begin{tabular}{|c|c|} -\toprule -This table & is not kept \\ \addlinespace -\midrule -\endhead -in formats & latex, beamer \\ \addlinespace -\bottomrule -\end{tabluar} +Usage +---- -~~~ ``` +$body$ -A fenced block with a raw attribute can only have one attribute, so you -need one for each format for which the markdown is left out. But Pandoc -will output the raw block in equivalent formats: a `latex` block will -be output in `latex` and `beamer`, a `html5` block in `html` and `epub3` -and so on. See [Pandoc's manual](https://pandoc.org/MANUAL.html#extension-raw_attribute). +$for(author)$$author$$endfor$ +$if(institute)$ +$for(institute)$$institute$$endfor$ +$endif$ -Installation ------------- - -Copy `not-in-format.lua` in your document folder or in your pandoc data -dir path. - -Contributing ------------- +``` -PRs welcome. diff --git a/bibliography-place/bibliography-place.lua b/bibliography-place/bibliography-place.lua index e4ffbc16..1deb82db 100644 --- a/bibliography-place/bibliography-place.lua +++ b/bibliography-place/bibliography-place.lua @@ -1,4 +1,5 @@ ---- # not-in-format - keep document parts out of selected output formats. +--- # Bibliography-place: template-controlled bibliography +-- placement in Pandoc. -- -- This Lua filter for Pandoc allows placement of the bibliography -- to be controlled in pandoc templates. @@ -7,7 +8,7 @@ -- @author Albert Krewinkel -- @copyright 2021 Julien Dutant, Albert Krewinkel -- @license MIT - see LICENSE file for details. --- @release 1.0 +-- @release 0.1 local references = pandoc.List:new() From d2542bcb511756a9e5af5ad98b6ffacdec3f7c0b Mon Sep 17 00:00:00 2001 From: jdutant <34026710+jdutant@users.noreply.github.com> Date: Sat, 13 Feb 2021 00:56:22 +0000 Subject: [PATCH 03/13] Simplified by passing the Div --- bibliography-place/README.md | 3 +++ bibliography-place/bibliography-place.lua | 26 ++++------------------- bibliography-place/expected_filtered.tex | 4 +--- bibliography-place/template.latex | 16 ++++++++++---- bibliography-place/test.html | 18 ++++++++++++++++ 5 files changed, 38 insertions(+), 29 deletions(-) create mode 100644 bibliography-place/test.html diff --git a/bibliography-place/README.md b/bibliography-place/README.md index 5f77fea3..24ce294b 100644 --- a/bibliography-place/README.md +++ b/bibliography-place/README.md @@ -40,6 +40,8 @@ places it in a `$referencesblock$` variable instead. Usage ---- +Place references with the `$referencesblock` variable: + ``` $body$ @@ -48,5 +50,6 @@ $if(institute)$ $for(institute)$$institute$$endfor$ $endif$ +$if(referencesblock)$$referencesblock$$endif$ ``` diff --git a/bibliography-place/bibliography-place.lua b/bibliography-place/bibliography-place.lua index 1deb82db..6e0f8249 100644 --- a/bibliography-place/bibliography-place.lua +++ b/bibliography-place/bibliography-place.lua @@ -10,27 +10,7 @@ -- @license MIT - see LICENSE file for details. -- @release 0.1 -local references = pandoc.List:new() - ---- Add environment to the references Div if needed --- takes the body of references (list of blocks) --- and wraps it in suitable environment commands for --- each format. id needed for links. --- @param content content of the bibliography --- @param id identifier of the bibliography -local function add_environment(content, id) - if FORMAT:match("latex") then - content:insert(1,pandoc.RawBlock("latex", - "\\hypertarget{refs}{" .. id .. "}")) - content:insert(1,pandoc.RawBlock("latex", "\\begin{CSLReferences}{1}{0}")) - content:insert(pandoc.RawBlock("latex", "\\end{CSLReferences}")) - elseif FORMAT:match("html.*") then - -- wrap the content in an HTML Div - content:insert(1,pandoc.RawBlock("html", '
')) - content:insert(pandoc.RawBlock("html", '
')) - end - return content -end +local references = nil --- Div filter for the 'refs' Div. -- Extract the Div with identifer 'refs' if present and @@ -40,8 +20,10 @@ end function Div(element) if element.identifier == 'refs' or element.classes:includes('csl-bib-body') then - references = add_environment(element.content, element.identifier) + + references = pandoc.MetaBlocks( { element } ) return {} -- remove from main body + end end diff --git a/bibliography-place/expected_filtered.tex b/bibliography-place/expected_filtered.tex index 120145d7..cc68257b 100644 --- a/bibliography-place/expected_filtered.tex +++ b/bibliography-place/expected_filtered.tex @@ -37,10 +37,8 @@ % Refs should be below this +\hypertarget{refs}{} \begin{CSLReferences}{1}{0} - -\hypertarget{refs}{refs} - \leavevmode\hypertarget{ref-Doe}{}% Doe, Jane. 1979. \emph{Short Stories}. diff --git a/bibliography-place/template.latex b/bibliography-place/template.latex index 952c4707..93e399b7 100644 --- a/bibliography-place/template.latex +++ b/bibliography-place/template.latex @@ -3,10 +3,17 @@ % Preamble commands for each bibliography engine % These are included in Pandoc's default template % -% TODO: when the filter has put the references in the -% metadata field, Pandoc's LaTeX writer doesn't -% set (csl-refs) to true, so we can't use if(csl-refs) -% +$if(natbib)$ +\usepackage[$natbiboptions$]{natbib} +\bibliographystyle{$if(biblio-style)$$biblio-style$$else$plainnat$endif$} +$endif$ +$if(biblatex)$ +\usepackage[$if(biblio-style)$style=$biblio-style$,$endif$$for(biblatexoptions)$$biblatexoptions$$sep$,$endfor$]{biblatex} +$for(bibliography)$ +\addbibresource{$bibliography$} +$endfor$ +$endif$ +$if(csl-refs)$ \newlength{\cslhangindent} \setlength{\cslhangindent}{1.5em} \newlength{\csllabelwidth} @@ -27,6 +34,7 @@ \newcommand{\CSLLeftMargin}[1]{\parbox[t]{\csllabelwidth}{#1}} \newcommand{\CSLRightInline}[1]{\parbox[t]{\linewidth - \csllabelwidth}{#1}\break} \newcommand{\CSLIndent}[1]{\hspace{\cslhangindent}#1} +$endif$ \begin{document} diff --git a/bibliography-place/test.html b/bibliography-place/test.html new file mode 100644 index 00000000..b6416f30 --- /dev/null +++ b/bibliography-place/test.html @@ -0,0 +1,18 @@ + + + Sample document + + + +

I enjoyed @Doe.

+ +Seymour Butz +School of Studies + + + +true + + + + From 20fe8fdee727fb308992f1366515400a19a8b717 Mon Sep 17 00:00:00 2001 From: jdutant <34026710+jdutant@users.noreply.github.com> Date: Sat, 13 Feb 2021 01:06:59 +0000 Subject: [PATCH 04/13] Update README.md --- bibliography-place/README.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/bibliography-place/README.md b/bibliography-place/README.md index 24ce294b..83fc60ec 100644 --- a/bibliography-place/README.md +++ b/bibliography-place/README.md @@ -6,8 +6,6 @@ author: "Julien Dutant" Bibliography place ======= -**WORK IN PROGRESS** - Control the placement of a `citeproc`-generated bibliography via Pandoc templates. @@ -40,6 +38,9 @@ places it in a `$referencesblock$` variable instead. Usage ---- +Call the filter from the command line or the defaults file. *It must be called +after citeproc*. + Place references with the `$referencesblock` variable: ``` @@ -53,3 +54,14 @@ $endif$ $if(referencesblock)$$referencesblock$$endif$ ``` +Warnings and troubleshooting +---------------------------- + +The filter must be called after *citeproc*. + +If you process the document with another or no bibliography engine, the +reference sections will simply be erased. + +If you use the filter with the default pandoc templates or with a template +that does not use `$referencesblock$` your bibliography will not be printed. + From 99298aa5cb8bc35aad2b4be0fa4ddefd9f95f2e8 Mon Sep 17 00:00:00 2001 From: jdutant <34026710+jdutant@users.noreply.github.com> Date: Sat, 13 Feb 2021 01:10:26 +0000 Subject: [PATCH 05/13] Delete template-broken.latex --- bibliography-place/template-broken.latex | 56 ------------------------ 1 file changed, 56 deletions(-) delete mode 100644 bibliography-place/template-broken.latex diff --git a/bibliography-place/template-broken.latex b/bibliography-place/template-broken.latex deleted file mode 100644 index 557e8977..00000000 --- a/bibliography-place/template-broken.latex +++ /dev/null @@ -1,56 +0,0 @@ -% A minimal template - -% Preamble commands for each bibliography engine -% These are included in Pandoc's default template -% -% TODO: when the filter has put the references in the -% metadata field, Pandoc's LaTeX writer doesn't -% set (csl-refs) to true, so we can't use if(csl-refs) -% -$if(natbib)$ -\usepackage[$natbiboptions$]{natbib} -\bibliographystyle{$if(biblio-style)$$biblio-style$$else$plainnat$endif$} -$endif$ -$if(biblatex)$ -\usepackage[$if(biblio-style)$style=$biblio-style$,$endif$$for(biblatexoptions)$$biblatexoptions$$sep$,$endfor$]{biblatex} -$for(bibliography)$ -\addbibresource{$bibliography$} -$endfor$ -$endif$ -$if(csl-refs)$ -\newlength{\cslhangindent} -\setlength{\cslhangindent}{1.5em} -\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$ - -\begin{document} - -$body$ - -$for(author)$$author$$endfor$ -$if(institute)$ -$for(institute)$$institute$$endfor$ -$endif$ - -% Refs should be below this - -$if(referencesblock)$$referencesblock$$endif$ - -\end{document} From 3945c11f58ad9c40727a8ca3ba8c053c8015d653 Mon Sep 17 00:00:00 2001 From: jdutant <34026710+jdutant@users.noreply.github.com> Date: Sat, 13 Feb 2021 01:17:32 +0000 Subject: [PATCH 06/13] Fall back when using natbib or biblatex --- bibliography-place/sample.md | 1 + bibliography-place/template.latex | 37 +++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/bibliography-place/sample.md b/bibliography-place/sample.md index 80dd2b7b..ec3bad62 100644 --- a/bibliography-place/sample.md +++ b/bibliography-place/sample.md @@ -10,6 +10,7 @@ references: issued: 1979 title: Short stories type: book +bibliography: none.bib ... I enjoyed @Doe. diff --git a/bibliography-place/template.latex b/bibliography-place/template.latex index 93e399b7..8f55572c 100644 --- a/bibliography-place/template.latex +++ b/bibliography-place/template.latex @@ -49,4 +49,41 @@ $endif$ $if(referencesblock)$$referencesblock$$endif$ + +% +% From pandoc's template: placement +% of bibliography with natbib and biblatex + +$if(natbib)$ + $if(bibliography)$ + $if(biblio-title)$ + $if(has-chapters)$ + \renewcommand\bibname{$biblio-title$} + $else$ + \renewcommand\refname{$biblio-title$} + $endif$ + $endif$ + $if(beamer)$ + \begin{frame}[allowframebreaks]{$biblio-title$} + \bibliographytrue + $endif$ + \bibliography{$for(bibliography)$$bibliography$$sep$,$endfor$} + $if(beamer)$ + \end{frame} + $endif$ + $endif$ +$endif$ + +$if(biblatex)$ + $if(beamer)$ + \begin{frame}[allowframebreaks]{$biblio-title$} + \bibliographytrue + \printbibliography[heading=none] + \end{frame} + $else$ +\printbibliography$if(biblio-title)$[title=$biblio-title$]$endif$ + $endif$ +$endif$ + + \end{document} From 6daab31c6af7a06d47b66055242f192479e1c4b2 Mon Sep 17 00:00:00 2001 From: jdutant <34026710+jdutant@users.noreply.github.com> Date: Sat, 13 Feb 2021 01:26:15 +0000 Subject: [PATCH 07/13] Update README.md --- bibliography-place/README.md | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/bibliography-place/README.md b/bibliography-place/README.md index 83fc60ec..1f1ed8e6 100644 --- a/bibliography-place/README.md +++ b/bibliography-place/README.md @@ -38,10 +38,24 @@ places it in a `$referencesblock$` variable instead. Usage ---- -Call the filter from the command line or the defaults file. *It must be called -after citeproc*. +Call the filter at the command line or in a defaults file (see Pandoc's +manual for detail). **Important**: the filter must be called after *citeproc*. From the command line: -Place references with the `$referencesblock` variable: +``` +pandoc -s --citeproc -L bibliography-place.lua sample.md -t html + +pandoc -s --citeproc --lua-filter bibliography-place.lua sample.md -t html +``` + +In a default file: + +``` +filters: +- citeproc +- bibliography-place.lua +``` + +In you custom Pandoc template you can then place the references block with the `referencesblock` variable: ``` $body$ @@ -54,14 +68,11 @@ $endif$ $if(referencesblock)$$referencesblock$$endif$ ``` -Warnings and troubleshooting ----------------------------- +Notes +----- -The filter must be called after *citeproc*. - -If you process the document with another or no bibliography engine, the -reference sections will simply be erased. +The template can be agnostic on which bibliography engine your run. If you process the document with other bibliography engines (natbib, biblatex) the filter will leave them untouched and you can place them by moving the +`\printbibliography` commands in the template. If you use the filter with the default pandoc templates or with a template that does not use `$referencesblock$` your bibliography will not be printed. - From 01c199f431c9f997a2b6229501c18c0e2c85a6f6 Mon Sep 17 00:00:00 2001 From: jdutant <34026710+jdutant@users.noreply.github.com> Date: Sat, 13 Feb 2021 13:10:07 +0000 Subject: [PATCH 08/13] fixed make (adds empty none.bib) --- bibliography-place/expected_filtered.tex | 12 ++++++++---- bibliography-place/expected_unfiltered.tex | 12 ++++++++---- bibliography-place/none.bib | 0 bibliography-place/test.html | 18 ------------------ 4 files changed, 16 insertions(+), 26 deletions(-) create mode 100644 bibliography-place/none.bib delete mode 100644 bibliography-place/test.html diff --git a/bibliography-place/expected_filtered.tex b/bibliography-place/expected_filtered.tex index cc68257b..bc14b317 100644 --- a/bibliography-place/expected_filtered.tex +++ b/bibliography-place/expected_filtered.tex @@ -3,10 +3,6 @@ % Preamble commands for each bibliography engine % These are included in Pandoc's default template % -% TODO: when the filter has put the references in the -% metadata field, Pandoc's LaTeX writer doesn't -% set (csl-refs) to true, so we can't use if(csl-refs) -% \newlength{\cslhangindent} \setlength{\cslhangindent}{1.5em} \newlength{\csllabelwidth} @@ -44,4 +40,12 @@ \end{CSLReferences} + +% +% From pandoc's template: placement +% of bibliography with natbib and biblatex + + + + \end{document} diff --git a/bibliography-place/expected_unfiltered.tex b/bibliography-place/expected_unfiltered.tex index 541fe7ec..a454b266 100644 --- a/bibliography-place/expected_unfiltered.tex +++ b/bibliography-place/expected_unfiltered.tex @@ -3,10 +3,6 @@ % Preamble commands for each bibliography engine % These are included in Pandoc's default template % -% TODO: when the filter has put the references in the -% metadata field, Pandoc's LaTeX writer doesn't -% set (csl-refs) to true, so we can't use if(csl-refs) -% \newlength{\cslhangindent} \setlength{\cslhangindent}{1.5em} \newlength{\csllabelwidth} @@ -46,4 +42,12 @@ + +% +% From pandoc's template: placement +% of bibliography with natbib and biblatex + + + + \end{document} diff --git a/bibliography-place/none.bib b/bibliography-place/none.bib new file mode 100644 index 00000000..e69de29b diff --git a/bibliography-place/test.html b/bibliography-place/test.html deleted file mode 100644 index b6416f30..00000000 --- a/bibliography-place/test.html +++ /dev/null @@ -1,18 +0,0 @@ - - - Sample document - - - -

I enjoyed @Doe.

- -Seymour Butz -School of Studies - - - -true - - - - From 71e68b73507a64c8850ca0aea52267f4794fedf6 Mon Sep 17 00:00:00 2001 From: jdutant <34026710+jdutant@users.noreply.github.com> Date: Sat, 13 Feb 2021 13:12:54 +0000 Subject: [PATCH 09/13] simplifies sample.md --- bibliography-place/expected_filtered.html | 2 +- bibliography-place/expected_filtered.tex | 2 +- bibliography-place/expected_unfiltered.html | 2 +- bibliography-place/expected_unfiltered.tex | 2 +- bibliography-place/none.bib | 0 bibliography-place/sample.bib | 5 +++++ bibliography-place/sample.md | 10 +--------- 7 files changed, 10 insertions(+), 13 deletions(-) delete mode 100644 bibliography-place/none.bib create mode 100644 bibliography-place/sample.bib diff --git a/bibliography-place/expected_filtered.html b/bibliography-place/expected_filtered.html index b4eb8bd7..5b1568b9 100644 --- a/bibliography-place/expected_filtered.html +++ b/bibliography-place/expected_filtered.html @@ -13,7 +13,7 @@
-Doe, Jane. 1979. Short Stories. +Doe, John. 1979. Short Stories.
diff --git a/bibliography-place/expected_filtered.tex b/bibliography-place/expected_filtered.tex index bc14b317..c4be2b0b 100644 --- a/bibliography-place/expected_filtered.tex +++ b/bibliography-place/expected_filtered.tex @@ -36,7 +36,7 @@ \hypertarget{refs}{} \begin{CSLReferences}{1}{0} \leavevmode\hypertarget{ref-Doe}{}% -Doe, Jane. 1979. \emph{Short Stories}. +Doe, John. 1979. \emph{Short Stories}. \end{CSLReferences} diff --git a/bibliography-place/expected_unfiltered.html b/bibliography-place/expected_unfiltered.html index 1fb90be4..61dc524e 100644 --- a/bibliography-place/expected_unfiltered.html +++ b/bibliography-place/expected_unfiltered.html @@ -7,7 +7,7 @@

I enjoyed Doe (1979).

-Doe, Jane. 1979. Short Stories. +Doe, John. 1979. Short Stories.
diff --git a/bibliography-place/expected_unfiltered.tex b/bibliography-place/expected_unfiltered.tex index a454b266..f74179f5 100644 --- a/bibliography-place/expected_unfiltered.tex +++ b/bibliography-place/expected_unfiltered.tex @@ -31,7 +31,7 @@ \hypertarget{refs}{} \begin{CSLReferences}{1}{0} \leavevmode\hypertarget{ref-Doe}{}% -Doe, Jane. 1979. \emph{Short Stories}. +Doe, John. 1979. \emph{Short Stories}. \end{CSLReferences} diff --git a/bibliography-place/none.bib b/bibliography-place/none.bib deleted file mode 100644 index e69de29b..00000000 diff --git a/bibliography-place/sample.bib b/bibliography-place/sample.bib new file mode 100644 index 00000000..c63b34e1 --- /dev/null +++ b/bibliography-place/sample.bib @@ -0,0 +1,5 @@ +@book{Doe, + title = "Short Stories", + author = "Doe, John", + year = 1979, +} diff --git a/bibliography-place/sample.md b/bibliography-place/sample.md index ec3bad62..6ac08245 100644 --- a/bibliography-place/sample.md +++ b/bibliography-place/sample.md @@ -2,15 +2,7 @@ title: Sample document author: Seymour Butz institute: School of Studies -references: -- author: - - family: Doe - given: Jane - id: Doe - issued: 1979 - title: Short stories - type: book -bibliography: none.bib +bibliography: sample.bib ... I enjoyed @Doe. From d7b74340d9bf6c2a09d5ae1c693dd5f81509069e Mon Sep 17 00:00:00 2001 From: jdutant <34026710+jdutant@users.noreply.github.com> Date: Fri, 19 Mar 2021 18:47:23 +0000 Subject: [PATCH 10/13] Captures the bibliography heading as well Modified the filter so that both the bibliography and the heading that immediately precedes it (if any) are placed in a metadata element. --- {bibliography-place => bib-place}/LICENSE | 0 {bibliography-place => bib-place}/Makefile | 0 {bibliography-place => bib-place}/README.md | 7 +- bib-place/bib-place.lua | 77 +++++++++++++++++++ .../expected_filtered.html | 1 + .../expected_filtered.tex | 4 + .../expected_unfiltered.html | 1 + .../expected_unfiltered.tex | 4 + {bibliography-place => bib-place}/sample.bib | 0 {bibliography-place => bib-place}/sample.md | 3 + .../template.html | 0 .../template.latex | 0 bibliography-place/bibliography-place.lua | 39 ---------- 13 files changed, 94 insertions(+), 42 deletions(-) rename {bibliography-place => bib-place}/LICENSE (100%) rename {bibliography-place => bib-place}/Makefile (100%) rename {bibliography-place => bib-place}/README.md (95%) create mode 100644 bib-place/bib-place.lua rename {bibliography-place => bib-place}/expected_filtered.html (88%) rename {bibliography-place => bib-place}/expected_filtered.tex (91%) rename {bibliography-place => bib-place}/expected_unfiltered.html (88%) rename {bibliography-place => bib-place}/expected_unfiltered.tex (91%) rename {bibliography-place => bib-place}/sample.bib (100%) rename {bibliography-place => bib-place}/sample.md (83%) rename {bibliography-place => bib-place}/template.html (100%) rename {bibliography-place => bib-place}/template.latex (100%) delete mode 100644 bibliography-place/bibliography-place.lua diff --git a/bibliography-place/LICENSE b/bib-place/LICENSE similarity index 100% rename from bibliography-place/LICENSE rename to bib-place/LICENSE diff --git a/bibliography-place/Makefile b/bib-place/Makefile similarity index 100% rename from bibliography-place/Makefile rename to bib-place/Makefile diff --git a/bibliography-place/README.md b/bib-place/README.md similarity index 95% rename from bibliography-place/README.md rename to bib-place/README.md index 1f1ed8e6..14d93fb9 100644 --- a/bibliography-place/README.md +++ b/bib-place/README.md @@ -1,13 +1,14 @@ --- -title: "Bibliography-place" +title: "Bib-place" author: "Julien Dutant" --- -Bibliography place +Bib-place ======= Control the placement of a `citeproc`-generated bibliography -via Pandoc templates. +via Pandoc templates. Only works with a single-bibliography +document. Introduction ------------ diff --git a/bib-place/bib-place.lua b/bib-place/bib-place.lua new file mode 100644 index 00000000..d1fdcaaf --- /dev/null +++ b/bib-place/bib-place.lua @@ -0,0 +1,77 @@ +--- # bib-place: template-controlled bibliography +-- placement in Pandoc. +-- +-- This Lua filter for Pandoc allows placement of the bibliography +-- to be controlled in pandoc templates. +-- +-- @author Julien Dutant +-- @author Albert Krewinkel +-- @copyright 2021 Julien Dutant, Albert Krewinkel +-- @license MIT - see LICENSE file for details. +-- @release 0.1 + +local references = pandoc.List({}) + +--- Filter for the document's blocks +-- Extract the Div with identifer 'refs' if present, as well as +-- any heading that immediately precedes it, and stores them in +-- the variable `references`. To find a heading that precedes +-- the `refs` Div it needs to walk through the document +-- backwards, element by element. +-- @param element a Div element +-- @return an empty list if Div has identifier `refs` +local blocks_filter = { + + Pandoc = function (doc) + + local previous_was_refs = false + + for i = #doc.blocks, 1, -1 do + + -- if we have already found the Div `refs` we check + -- whether we have a heading and end the loop + if previous_was_refs then + if doc.blocks[i].t == 'Header' then + references:insert(1, pandoc.MetaBlocks( { doc.blocks[i] } )) + doc.blocks:remove(i) -- remove the heading + break + else + break + end + + elseif doc.blocks[i].identifier == 'refs' + or ( doc.blocks[i].classes and + doc.blocks[i].classes:includes('csl-bib-body') ) then + + references:insert(pandoc.MetaBlocks( { doc.blocks[i] } )) + doc.blocks:remove(i) -- remove the Div + previous_was_refs = true + + end + + end + + return(doc) + + end +} + +--- Metadata filter. +-- Places the references block (as string) in the `references` +-- field of the document's metadata. The template can +-- print it by using `$meta.references$`. +-- @param meta the document's metadata block +-- @return the modified metadata block +local metadata_filter = { + Meta = function (meta) + meta.referencesblock = references + return meta + end +} + +--- Main code +-- Returns the filters in the desired order of execution +return { + blocks_filter, + metadata_filter +} diff --git a/bibliography-place/expected_filtered.html b/bib-place/expected_filtered.html similarity index 88% rename from bibliography-place/expected_filtered.html rename to bib-place/expected_filtered.html index 5b1568b9..ff6648eb 100644 --- a/bibliography-place/expected_filtered.html +++ b/bib-place/expected_filtered.html @@ -5,6 +5,7 @@

I enjoyed Doe (1979).

+

References

Seymour Butz School of Studies diff --git a/bibliography-place/expected_filtered.tex b/bib-place/expected_filtered.tex similarity index 91% rename from bibliography-place/expected_filtered.tex rename to bib-place/expected_filtered.tex index c4be2b0b..731fcbb4 100644 --- a/bibliography-place/expected_filtered.tex +++ b/bib-place/expected_filtered.tex @@ -28,6 +28,10 @@ I enjoyed Doe (1979). +\hypertarget{references}{% +\section*{References}\label{references}} +\addcontentsline{toc}{section}{References} + Seymour Butz School of Studies diff --git a/bibliography-place/expected_unfiltered.html b/bib-place/expected_unfiltered.html similarity index 88% rename from bibliography-place/expected_unfiltered.html rename to bib-place/expected_unfiltered.html index 61dc524e..b6576421 100644 --- a/bibliography-place/expected_unfiltered.html +++ b/bib-place/expected_unfiltered.html @@ -5,6 +5,7 @@

I enjoyed Doe (1979).

+

References

Doe, John. 1979. Short Stories. diff --git a/bibliography-place/expected_unfiltered.tex b/bib-place/expected_unfiltered.tex similarity index 91% rename from bibliography-place/expected_unfiltered.tex rename to bib-place/expected_unfiltered.tex index f74179f5..1e087c5a 100644 --- a/bibliography-place/expected_unfiltered.tex +++ b/bib-place/expected_unfiltered.tex @@ -28,6 +28,10 @@ I enjoyed Doe (1979). +\hypertarget{references}{% +\section*{References}\label{references}} +\addcontentsline{toc}{section}{References} + \hypertarget{refs}{} \begin{CSLReferences}{1}{0} \leavevmode\hypertarget{ref-Doe}{}% diff --git a/bibliography-place/sample.bib b/bib-place/sample.bib similarity index 100% rename from bibliography-place/sample.bib rename to bib-place/sample.bib diff --git a/bibliography-place/sample.md b/bib-place/sample.md similarity index 83% rename from bibliography-place/sample.md rename to bib-place/sample.md index 6ac08245..0a4e364d 100644 --- a/bibliography-place/sample.md +++ b/bib-place/sample.md @@ -6,3 +6,6 @@ bibliography: sample.bib ... I enjoyed @Doe. + +## Works cited {.refs} + diff --git a/bibliography-place/template.html b/bib-place/template.html similarity index 100% rename from bibliography-place/template.html rename to bib-place/template.html diff --git a/bibliography-place/template.latex b/bib-place/template.latex similarity index 100% rename from bibliography-place/template.latex rename to bib-place/template.latex diff --git a/bibliography-place/bibliography-place.lua b/bibliography-place/bibliography-place.lua deleted file mode 100644 index 6e0f8249..00000000 --- a/bibliography-place/bibliography-place.lua +++ /dev/null @@ -1,39 +0,0 @@ ---- # Bibliography-place: template-controlled bibliography --- placement in Pandoc. --- --- This Lua filter for Pandoc allows placement of the bibliography --- to be controlled in pandoc templates. --- --- @author Julien Dutant --- @author Albert Krewinkel --- @copyright 2021 Julien Dutant, Albert Krewinkel --- @license MIT - see LICENSE file for details. --- @release 0.1 - -local references = nil - ---- Div filter for the 'refs' Div. --- Extract the Div with identifer 'refs' if present and --- save it in `references`. --- @param element a Div element --- @return an empty list if Div has identifier `refs` -function Div(element) - if element.identifier == 'refs' - or element.classes:includes('csl-bib-body') then - - references = pandoc.MetaBlocks( { element } ) - return {} -- remove from main body - - end -end - ---- Meta filter. --- Places the references block (as string) in the `references` --- field of the document's metadata. The template can --- print it by using `$meta.references$`. --- @param meta the document's metadata block --- @return the modified metadata block -function Meta (meta) - meta.referencesblock = references - return meta -end From 2e7ac27edb9424595d664c3711733d6f1210ca9f Mon Sep 17 00:00:00 2001 From: jdutant <34026710+jdutant@users.noreply.github.com> Date: Fri, 19 Mar 2021 18:53:47 +0000 Subject: [PATCH 11/13] make fix --- bib-place/Makefile | 18 +++++++++--------- bib-place/README.md | 6 +++--- bib-place/expected_filtered.html | 3 +-- bib-place/expected_filtered.tex | 8 +++----- bib-place/expected_unfiltered.html | 2 +- bib-place/expected_unfiltered.tex | 6 +++--- 6 files changed, 20 insertions(+), 23 deletions(-) diff --git a/bib-place/Makefile b/bib-place/Makefile index ed27305e..839ecc21 100644 --- a/bib-place/Makefile +++ b/bib-place/Makefile @@ -4,32 +4,32 @@ DIFF ?= diff --strip-trailing-cr -u test: latex html -latex: sample.md expected_filtered.tex expected_unfiltered.tex bibliography-place.lua +latex: sample.md expected_filtered.tex expected_unfiltered.tex bib-place.lua @pandoc -s --citeproc --to latex --template template $< \ | $(DIFF) expected_unfiltered.tex - - @pandoc -s --citeproc --lua-filter bibliography-place.lua --to=latex \ + @pandoc -s --citeproc --lua-filter bib-place.lua --to=latex \ --template template $< | $(DIFF) expected_filtered.tex - html: sample.md expected_filtered.html expected_unfiltered.html @pandoc -s --citeproc --to=html --template template $< \ | $(DIFF) expected_unfiltered.html - - @pandoc -s --citeproc --lua-filter bibliography-place.lua --to=html \ + @pandoc -s --citeproc --lua-filter bib-place.lua --to=html \ --template template $< | $(DIFF) expected_filtered.html - -expected_filtered.html : sample.md bibliography-place.lua - @pandoc -s --citeproc --lua-filter bibliography-place.lua \ +expected_filtered.html : sample.md bib-place.lua + @pandoc -s --citeproc --lua-filter bib-place.lua \ --output expected_filtered.html \ --template template $< \ -expected_filtered.tex : sample.md bibliography-place.lua - @pandoc -s --citeproc --lua-filter bibliography-place.lua \ +expected_filtered.tex : sample.md bib-place.lua + @pandoc -s --citeproc --lua-filter bib-place.lua \ --output expected_filtered.tex \ --template template $< -expected_unfiltered.html : sample.md bibliography-place.lua +expected_unfiltered.html : sample.md bib-place.lua @pandoc -s --citeproc --output expected_unfiltered.html \ --template template $< -expected_unfiltered.tex : sample.md bibliography-place.lua +expected_unfiltered.tex : sample.md bib-place.lua @pandoc -s --citeproc --output expected_unfiltered.tex \ --template template $< diff --git a/bib-place/README.md b/bib-place/README.md index 14d93fb9..ea5b5078 100644 --- a/bib-place/README.md +++ b/bib-place/README.md @@ -43,9 +43,9 @@ Call the filter at the command line or in a defaults file (see Pandoc's manual for detail). **Important**: the filter must be called after *citeproc*. From the command line: ``` -pandoc -s --citeproc -L bibliography-place.lua sample.md -t html +pandoc -s --citeproc -L bib-place.lua sample.md -t html -pandoc -s --citeproc --lua-filter bibliography-place.lua sample.md -t html +pandoc -s --citeproc --lua-filter bib-place.lua sample.md -t html ``` In a default file: @@ -53,7 +53,7 @@ In a default file: ``` filters: - citeproc -- bibliography-place.lua +- bib-place.lua ``` In you custom Pandoc template you can then place the references block with the `referencesblock` variable: diff --git a/bib-place/expected_filtered.html b/bib-place/expected_filtered.html index ff6648eb..ed326b22 100644 --- a/bib-place/expected_filtered.html +++ b/bib-place/expected_filtered.html @@ -5,14 +5,13 @@

I enjoyed Doe (1979).

-

References

Seymour Butz School of Studies -
+

Works cited

Doe, John. 1979. Short Stories.
diff --git a/bib-place/expected_filtered.tex b/bib-place/expected_filtered.tex index 731fcbb4..6df245eb 100644 --- a/bib-place/expected_filtered.tex +++ b/bib-place/expected_filtered.tex @@ -28,16 +28,14 @@ I enjoyed Doe (1979). -\hypertarget{references}{% -\section*{References}\label{references}} -\addcontentsline{toc}{section}{References} - Seymour Butz School of Studies % Refs should be below this -\hypertarget{refs}{} +\hypertarget{works-cited}{% +\subsection*{Works cited}\label{works-cited}} +\addcontentsline{toc}{subsection}{Works cited}\hypertarget{refs}{} \begin{CSLReferences}{1}{0} \leavevmode\hypertarget{ref-Doe}{}% Doe, John. 1979. \emph{Short Stories}. diff --git a/bib-place/expected_unfiltered.html b/bib-place/expected_unfiltered.html index b6576421..0957e6d3 100644 --- a/bib-place/expected_unfiltered.html +++ b/bib-place/expected_unfiltered.html @@ -5,7 +5,7 @@

I enjoyed Doe (1979).

-

References

+

Works cited

Doe, John. 1979. Short Stories. diff --git a/bib-place/expected_unfiltered.tex b/bib-place/expected_unfiltered.tex index 1e087c5a..17ad9d62 100644 --- a/bib-place/expected_unfiltered.tex +++ b/bib-place/expected_unfiltered.tex @@ -28,9 +28,9 @@ I enjoyed Doe (1979). -\hypertarget{references}{% -\section*{References}\label{references}} -\addcontentsline{toc}{section}{References} +\hypertarget{works-cited}{% +\subsection*{Works cited}\label{works-cited}} +\addcontentsline{toc}{subsection}{Works cited} \hypertarget{refs}{} \begin{CSLReferences}{1}{0} From 549156a47190694469d764af18de5b4707a6a833 Mon Sep 17 00:00:00 2001 From: jdutant <34026710+jdutant@users.noreply.github.com> Date: Fri, 19 Mar 2021 19:04:45 +0000 Subject: [PATCH 12/13] update for pandoc 2.12 --- bib-place/expected_filtered.tex | 2 +- bib-place/expected_unfiltered.tex | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bib-place/expected_filtered.tex b/bib-place/expected_filtered.tex index 6df245eb..ba253a94 100644 --- a/bib-place/expected_filtered.tex +++ b/bib-place/expected_filtered.tex @@ -37,7 +37,7 @@ \subsection*{Works cited}\label{works-cited}} \addcontentsline{toc}{subsection}{Works cited}\hypertarget{refs}{} \begin{CSLReferences}{1}{0} -\leavevmode\hypertarget{ref-Doe}{}% +\leavevmode\vadjust pre{\hypertarget{ref-Doe}{}}% Doe, John. 1979. \emph{Short Stories}. \end{CSLReferences} diff --git a/bib-place/expected_unfiltered.tex b/bib-place/expected_unfiltered.tex index 17ad9d62..454dfc5e 100644 --- a/bib-place/expected_unfiltered.tex +++ b/bib-place/expected_unfiltered.tex @@ -34,7 +34,7 @@ \subsection*{Works cited}\label{works-cited}} \hypertarget{refs}{} \begin{CSLReferences}{1}{0} -\leavevmode\hypertarget{ref-Doe}{}% +\leavevmode\vadjust pre{\hypertarget{ref-Doe}{}}% Doe, John. 1979. \emph{Short Stories}. \end{CSLReferences} From f6b8aff245cbe82c3884de55fa31a25dab6a80c1 Mon Sep 17 00:00:00 2001 From: jdutant <34026710+jdutant@users.noreply.github.com> Date: Fri, 19 Mar 2021 19:19:34 +0000 Subject: [PATCH 13/13] Update README.md --- bib-place/README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bib-place/README.md b/bib-place/README.md index ea5b5078..84eceb29 100644 --- a/bib-place/README.md +++ b/bib-place/README.md @@ -10,6 +10,9 @@ Control the placement of a `citeproc`-generated bibliography via Pandoc templates. Only works with a single-bibliography document. +The filter does not affect biblatex / natbib outputs, so it can be +used with a custom template that caters for all bibliography engines. + Introduction ------------