Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

references variable in templates #771

Closed
jgm opened this issue Feb 28, 2013 · 18 comments
Closed

references variable in templates #771

jgm opened this issue Feb 28, 2013 · 18 comments

Comments

@jgm
Copy link
Owner

jgm commented Feb 28, 2013

Aditya Mahajan suggests on pandoc-discuss:

Is it possible to change the way bibliography is handled? Can you add
a $if(bibliography)$ check for the template file, and a $references$
tag for the list of references. Then, I can use the following in my
ConTeXt template:

$if(bibliography)$
%\subject{References}
\setupindenting[no]
\setupwhitespace[small]

$references$
$endif$

This may also circumvent the need to explicitly write #References in
the markdown file (but I don't know how other writers would handle
this).

@jgm
Copy link
Owner Author

jgm commented Feb 28, 2013

Instead of using two variables, I'd probably just use one, references. The default templates (for all writers) could just include:

$if(references)$
$references$
$endif$

This could be customized if desired, and writers could opt to include a subject heading in the template rather than at the end of the document.

@adityam
Copy link
Contributor

adityam commented Feb 28, 2013

Of course, using one variable is better.

@jgm
Copy link
Owner Author

jgm commented Mar 4, 2013

This change would not be easy, since currently the bibliography is added in the readers. The types of the reader functions would have to be changed to return a pair (Pandoc, [Block]). So this probably has to go on the back burner for now.

@jgm
Copy link
Owner Author

jgm commented Jul 26, 2013

I just realized that the new metadata changes make it possible to add this feature without further API changes. (Though I'm not positive this is a good way to do it.) One could simply add a new references metadata field in the reader, containing the bibliography. Then templates could simply include a references variable wherever they like. If I'm not mistaken, minimal changes would be required!

@jgm
Copy link
Owner Author

jgm commented Jul 26, 2013

The one potential drawback I see is that, in formats that print some representation of all of the metadata (e.g. reST, markdown), you'd get an extra copy of the bibliography in the metadata, which seems undesirable.

Perhaps this could be avoided by adding a special case for references.

@mmirate
Copy link

mmirate commented Jul 27, 2013

Actually, for non-reused bibliographic databases, wouldn't the ability to specify the bibliography inline with the document be considered a feature?

@jgm
Copy link
Owner Author

jgm commented Aug 3, 2013

Experimented with implementing this, but found some rough edges. (This approach is difficult for epub, OPML, and some other formats.) My work is preserved in the branch issue771, but I think for now I'll stick to the present system.

@ousia
Copy link
Contributor

ousia commented Mar 30, 2015

Experimented with implementing this, but found some rough edges. (This approach is difficult for epub, OPML, and some other formats.) My work is preserved in the branch issue771, but I think for now I'll stick to the present system.

@jgm, how about enabling a # references title in a similar way to the proposals for TOC (#1612) and footnotes (#1720)?

This is much easier to use for the final user. And I think way more powerful.

@jgm
Copy link
Owner Author

jgm commented Mar 30, 2015

Injecting the bibliography under a header with a special id (say, references) would indeed be easier technically than handling it with a template.

@ousia
Copy link
Contributor

ousia commented Mar 30, 2015

Injecting the bibliography under a header with a special id (say, references) would indeed be easier technically than handling it with a template.

@jgm, excuse me, but I can’t refrain from asking: are header with special titles technically easier to implement than variables in templates?

@lierdakil
Copy link
Contributor

Somewhat relevant pandoc-discuss thread: https://groups.google.com/forum/#!topic/pandoc-discuss/HxmpFK-Ydus


To answer @ousia, not necessarily, no. But for some particular cases, like epub, template is actually a section template, and not a document template (since epub is basically a collection of html pages). So this becomes a bit more difficult if handled with a template variable -- after all, we don't need references in every section.

@alick
Copy link

alick commented Apr 10, 2015

@lierdakil "after all, we don't need references in every section." It might not be the case where pandoc focuses on, but it is common for books to have references after each chapter. In latex chapterbib and biblatex can handle this.

@lierdakil
Copy link
Contributor

Let me rephrase this then: we don't need ALL references in every section.
Because pandoc-citeproc does not handle the use-case you are talking about,
and it would be extremely hard to make it to.

And pandoc does have support for biblatex for latex/pdf output. And it's
completely separate feature, not discussed here.

2015-04-10 11:50 GMT+03:00 Alick Zhao [email protected]:

@lierdakil https://github.com/lierdakil "after all, we don't need
references in every section." It might not be the case where pandoc focuses
on, but it is common for books to have references after each chapter. In
latex chapterbib and biblatex can handle this.


Reply to this email directly or view it on GitHub
#771 (comment).

@sergiocorreia
Copy link

Since we are already using pandoc-citeproc to construct the references, can we just have another filter that deals with this issue, instead of having it as a Pandoc problem? EG:

pandoc doc.md -F pandoc-citeproc -F pandoc-move-references

Now, what would be the best approach? append the references after a header with references id, or is there a better alternative? (If it's the former, I already have a sketch of a filter, from my pre-panflute days)

@nsbgn
Copy link

nsbgn commented Jun 25, 2017

What @sergiocorreia suggests is similar to the approach I took when I ran into this problem. I made a $references$ variable accessible from within the template (since I didn't need to export to EPUB or other formats where using a template would be problematic):

import panflute as pf

def prepare(doc):
    doc.references = None

def action(el, doc):
    if isinstance(el, pf.Div) and el.identifier == "refs":
        doc.references = list(el.content)
        return []

def finalize(doc):
    if doc.references:
        doc.metadata["references"] = pf.MetaBlocks(*doc.references) 
    del doc.references

if __name__ == "__main__":
    pf.toJSONFilter(action, prepare, finalize)

This works fine, and I think inserting after specific headers is reasonable for a more general approach.

@jgm
Copy link
Owner Author

jgm commented Feb 2, 2019

Pandoc-citeproc already allows you to insert a div with id refs, and in this case puts the references there.

Can this issue be closed, or is there something I'm missing?

@adityam
Copy link
Contributor

adityam commented Feb 2, 2019

Yes, I agree that this can be closed.

@mb21 mb21 closed this as completed Feb 2, 2019
@joundso
Copy link

joundso commented Jan 10, 2022

Pandoc-citeproc already allows you to insert a div with id refs, and in this case puts the references there.
Can this issue be closed, or is there something I'm missing?

In case someone is looking for a quick copy & paste example:

This is some text [@item1]

This is more text [@item2]

# References

<div id="refs"></div>

# appendix

Source: https://stackoverflow.com/a/44294306

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests