msprev / panzer

pandoc + styles
BSD 3-Clause "New" or "Revised" License
160 stars 13 forks source link

Biblatex option #1

Closed twsh closed 9 years ago

twsh commented 9 years ago

I would like to use pandoc's --biblatex option. I though that the following 'style.yaml' file would do it:

########################################################################
#                     Base - parent of all styles                      #
########################################################################

Base:
    all:
        metadata:
            bibliography: /Users/thomas/Library/texmf/bibtex/bib/bibliography.bib
    latex:
        preflight:
            - run: tmp_out.py
        postflight:
            - run: latexmk.py
            - run: open_pdf.py
        cleanup:
            - run: tmp_back.py
            - run: rmlatex.py

########################################################################
#                               Paper                                #
########################################################################

Paper:
    parent:
        - Base
    all:
        metadata:
            numbersections: true
    latex:
        metadata:
            biblatex: true
        template: default.latex

But when I do $ panzer --output foo.tex foo.txt it's clear that the biblatex option hasn't been called: my cite keys haven't turned to citations commands, and biblatex hasn't been called. I do get numbered sections, so it's not that panzer doesn't see my files or anything like that.

By the way, doing this works fine: $panzer --biblatex --output foo.tex foo.txt. Have I failed to set something up right in my style file?

msprev commented 9 years ago

Currently, the only way to do this currently is to pass --biblatex on the command line as you do.

panzer does not allow arbitrary pandoc command line options to set via metadata. I have been thinking of implementing this, but haven't thought of a good metadata syntax to express it. There are some use cases, like the one you mention, --smart, and --standalone.

Over time pandoc has moved some command-line only options to permit them to be set via metadata (e.g. --bibliography can be set via setting the bibliography field). I do not know if there are plans to move any more options to make them settable via metadata. If this happened in pandoc, it would solve the problem.

msprev commented 9 years ago

I've figured out a way to do this. I will implement it. All command line options, with the exception of reader and writer, will be settable via a metadata field. I'll push the changes once the feature is implemented.

twsh commented 9 years ago

That's great. I think panzer is going to be a lot more convenient than my current setup with make files.

On 23 May 2015, at 04:33, Mark Sprevak notifications@github.com wrote:

I've figured out a way to do this. I will implement it. All command line options, with the exception of reader and writer, will be settable via a metadata field. I'll push the changes once the feature is implemented.

— Reply to this email directly or view it on GitHub.

msprev commented 9 years ago

It's now implemented in the latest commit. I've added a new style definition field, commandline; documentation here: https://github.com/msprev/panzer#setting-pandoc-command-line-options. This allows one to set arbitrary pandoc command line options in metadata. Thanks for prompting me to do this.

Your new style definition should be:

Paper:
    parent:
        - Base
    all:
        metadata:
            numbersections: true
    latex:
        commandline:
            biblatex: true
        template: default.latex

Let me know if there are any problems.

twsh commented 9 years ago

It's working for me. Thanks!

On 23 May 2015, at 17:19, Mark Sprevak notifications@github.com wrote:

It's now implemented in the latest commit. I've added a new style definition field, commandline; documentation here: https://github.com/msprev/panzer#setting-pandoc-command-line-options. This allows one to set arbitrary pandoc command line options in metadata. Thanks for prompting me to do this.

Your new style definition should be:

Paper: parent:

  • Base all: metadata: numbersections: true latex: commandline: biblatex: true template: default.latex

Let me know if there are any problems.

— Reply to this email directly or view it on GitHub.

twsh commented 9 years ago

For some reason I haven't been able to figure out yet, adding commandline: smart to my styles doesn't work. I see this in the terminal:

----- style definitions -----
global:
 Base  Paper      
----- document style -----
style:
 Paper
full hierarchy:
 Base, Paper
writer:
 docx
----- run list -----
 empty
----- pandoc -----
running pandoc with options:
 --smart

So the option is being passed, and adding it explicitly to the call to panzer works fine. My style.yaml looks like this:

Paper:
    parent:
        - Base
    all:
        metadata:
            numbersections: true
    docx:
        commandline:
            smart: true
    latex:
        commandline:
            biblatex: true
        template: default.latex

The same thing happens with HTML(5).

twsh commented 9 years ago

I've noticed something else: LaTeX output should be 'smart' by default, but now it is as if the --no-tex-ligatures option had been set. Adding --smart to the call to panzer fixes it.

msprev commented 9 years ago

Can you describe the issue more accurately? I don't follow.

commandline: smart is not a valid construct. To set --smart you need

commandline:
    smart: true

pandoc's LaTeX writer is not 'smart' by default; you need to explicitly pass --smart on the command line if you want -- to be an en-dash etc. Currently, with your style definition, you are only passing --smart when the docx writer is selected.

I don't follow the comment on --no-tex-ligatures. This option would only be passed to pandoc if you explicitly require it. Can you give an minimal working example where panzer and pandoc latex output differs on same options?

twsh commented 9 years ago

Sorry, 'commandline: smart' was a typo; I have been doing correctly as in the style file in the above post. Here's an MWE for the problem.

This is the 'styles.yaml':

Base:
    docx:
        commandline:
            smart: true
    html:
        commandline:
            smart: true

This is a markdown file:

---
style: Base
...

'Hello world'

That should set the --smart option for the docx and html writers, and do nothing else, right?

I run the following commands and get three files where the quotes aren't 'smart':

These with Pandoc do give me 'smart' quotes:

The interesting thing with LaTeX is the default would be smart, and --no-tex-ligatures would have to be called to suppress it. (I know it's a bit more complicated than that because there are two issues i.e. ligatures and quotes and they come apart with the LaTeX writer.) The output I get from my latex panzer call is identical to what I get from:

msprev commented 9 years ago

I've worked out what is going on. The current implementation only sets pandoc writer options. --smart is a reader option, so it isn't being set. Serves me right for trying to implement a major change in one day. I need to rethink the implementation so that it will set the reader options. I've re-opened this issue. I have some ideas on how to implement it. However, for the moment, you need to pass options like --smart as a command line arguments to panzer. Writer options like --bibtex still work ok with commandline.

The latex writer issue is an interesting edge case. It is an instance when a pandoc reader option (--smart) is set by pandoc conditional on the writer (latex). panzer does not currently pick up on this as panzer works like a filter -- it gets pandoc to produce an ast, which is passed to the appropriate writer (i.e. like pandoc - -t json | pandoc -f json -t latex). My view is that this should always be equivalent to pandoc - -t latex; the writer shouldn't be affecting the reader. But this is case where that doesn't happen. I can add a tweak to reproduce this behaviour: automatically invoke --smart for the reader if the latex writer is selected. I'll check the pandoc documentation for similar cases too.

msprev commented 9 years ago

Both issues -- setting reader options and automatically setting --smart for latex writer -- fixed in latest commit. Let me know if there are any problems.

twsh commented 9 years ago

It's working for me now. Thanks for a great tool.

On 29 May 2015, at 04:59, Mark Sprevak notifications@github.com wrote:

Both issues -- setting reader options and automatically setting --smart for latex writer -- fixed in latest commit. Let me know if there are any problems.

— Reply to this email directly or view it on GitHub.

msprev commented 9 years ago

Thank you!