public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* Issues with using include-before/include-after when output is pdf
@ 2015-07-23 16:12 Tahir B
       [not found] ` <12a3b4c1-e64e-4f0d-ba1b-545311045f86-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Tahir B @ 2015-07-23 16:12 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 3295 bytes --]

I wanted to format the body of my article text such that paragraphs (all 
but first in a section) were indented and that lines were spaced out. But I 
wanted the bibliography to not be indented and have normal spacing.

Following the instructions I got from some Google searches I thought the 
following would do the trick:

---

title: This is a test
linestretch: 1.5
header-includes:
    - \usepackage{fullpage}
include-before:
    - \setlength{\parindent}{15pt}
include-after:
    - \setlength{\parindent}{0pt}
    - \setstretch{1}

---


Unfortunately this did not work as I had hoped. I tried three approaches for generating a pdf: just pandoc, pandoc+csl+latex, pandoc+biblatex+latex. In all three cases what I found was that the include-after lines were added actually after the bibliography command had been called.


Here is my attempt to reproduce the issue: 


https://gist.github.com/majorgreys/af344eb9824b947f393b


In the pandoc+csl+latex outputted tex file I got this:


\section*{References}\label{references}
\addcontentsline{toc}{section}{References}

Last, First. 1981. \emph{Book Title}. Publisher.

---------. 2001. \emph{Book Title 2}. Publisher.

\setlength{\parindent}{0pt}

\setstretch{1}


And, in the pandoc+biblatex+latex outputted tex file I got this:


\printbibliography[title=References]

\setlength{\parindent}{0pt}

\setstretch{1}


This then led me to look at the default latex template, where the relevant lines are:


$body$

$if(natbib)$
$if(bibliography)$
$if(biblio-title)$
$if(book-class)$
\renewcommand\bibname{$biblio-title$}
$else$
\renewcommand\refname{$biblio-title$}
$endif$
$endif$
\bibliography{$for(bibliography)$$bibliography$$sep$,$endfor$}

$endif$
$endif$
$if(biblatex)$
\printbibliography$if(biblio-title)$[title=$biblio-title$]$endif$

$endif$
$for(include-after)$
$include-after$

$endfor$


Now it makes sense why in all three approaches the include-after clauses do not end up affecting the bibliography.


I can certainly modify the latex template so that the include-after block is before the natbib block. But that only resolves the issue when I'm not using citeproc.


I wonder if include-after behavior for straight pdf output should actually be like the modified latex template I just described. Should $body have the citeproc-generated bibliography appended to it or should the include-after applied before the bibliography is inserted into the document? I expected that the latter would be how things worked, but maybe there are many good reasons for the former to be the typical behavior.


Hope my issue and questions made sense.


Thanks!

Tahir

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/12a3b4c1-e64e-4f0d-ba1b-545311045f86%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 5828 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Issues with using include-before/include-after when output is pdf
       [not found] ` <12a3b4c1-e64e-4f0d-ba1b-545311045f86-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2015-07-23 16:20   ` John MacFarlane
       [not found]     ` <20150723162035.GF31766-nFAEphtLEs/fysO+viCLMa55KtNWUUjk@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: John MacFarlane @ 2015-07-23 16:20 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

Currently pandoc-citeproc adds the bibliography to the body.

You can use a pandoc filter to intercept this section (which
has the identifier "references") and put it inside a special
latex environment.  That would probably be the easiest
solution.

See http://pandoc.org/scripting for basic instructions; if
you need help, ask here.


+++ Tahir B [Jul 23 15 09:12 ]:
>   I wanted to format the body of my article text such that paragraphs
>   (all but first in a section) were indented and that lines were spaced
>   out. But I wanted the bibliography to not be indented and have normal
>   spacing.
>   Following the instructions I got from some Google searches I thought
>   the following would do the trick:
>   ---
>title: This is a test
>linestretch: 1.5
>header-includes:
>    - \usepackage{fullpage}
>include-before:
>    - \setlength{\parindent}{15pt}
>include-after:
>    - \setlength{\parindent}{0pt}
>    - \setstretch{1}
>---
>
>Unfortunately this did not work as I had hoped. I tried three approaches for gen
>erating a pdf: just pandoc, pandoc+csl+latex, pandoc+biblatex+latex. In all thre
>e cases what I found was that the include-after lines were added actually after
>the bibliography command had been called.
>
>Here is my attempt to reproduce the issue:
>
>[1]https://gist.github.com/majorgreys/af344eb9824b947f393b
>
>In the pandoc+csl+latex outputted tex file I got this:
>
>\section*{References}\label{references}
>\addcontentsline{toc}{section}{References}
>
>Last, First. 1981. \emph{Book Title}. Publisher.
>
>---------. 2001. \emph{Book Title 2}. Publisher.
>
>\setlength{\parindent}{0pt}
>
>\setstretch{1}
>
>
>And, in the pandoc+biblatex+latex outputted tex file I got this:
>
>\printbibliography[title=References]
>
>\setlength{\parindent}{0pt}
>
>\setstretch{1}
>
>
>This then led me to look at the default latex template, where the relevant lines
> are:
>
>$body$
>
>$if(natbib)$
>$if(bibliography)$
>$if(biblio-title)$
>$if(book-class)$
>\renewcommand\bibname{$biblio-title$}
>$else$
>\renewcommand\refname{$biblio-title$}
>$endif$
>$endif$
>\bibliography{$for(bibliography)$$bibliography$$sep$,$endfor$}
>
>$endif$
>$endif$
>$if(biblatex)$
>\printbibliography$if(biblio-title)$[title=$biblio-title$]$endif$
>
>$endif$
>$for(include-after)$
>$include-after$
>
>$endfor$
>
>
>Now it makes sense why in all three approaches the include-after clauses do not
>end up affecting the bibliography.
>
>I can certainly modify the latex template so that the include-after block is bef
>ore the natbib block. But that only resolves the issue when I'm not using citepr
>oc.
>
>I wonder if include-after behavior for straight pdf output should actually be li
>ke the modified latex template I just described. Should $body have the citeproc-
>generated bibliography appended to it or should the include-after applied before
> the bibliography is inserted into the document? I expected that the latter woul
>d be how things worked, but maybe there are many good reasons for the former to
>be the typical behavior.
>
>Hope my issue and questions made sense.
>
>Thanks!
>Tahir
>
>   --
>   You received this message because you are subscribed to the Google
>   Groups "pandoc-discuss" group.
>   To unsubscribe from this group and stop receiving emails from it, send
>   an email to [2]pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
>   To post to this group, send email to
>   [3]pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
>   To view this discussion on the web visit
>   [4]https://groups.google.com/d/msgid/pandoc-discuss/12a3b4c1-e64e-4f0d-
>   ba1b-545311045f86%40googlegroups.com.
>   For more options, visit [5]https://groups.google.com/d/optout.
>
>References
>
>   1. https://gist.github.com/majorgreys/af344eb9824b947f393b
>   2. mailto:pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
>   3. mailto:pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
>   4. https://groups.google.com/d/msgid/pandoc-discuss/12a3b4c1-e64e-4f0d-ba1b-545311045f86-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org?utm_medium=email&utm_source=footer
>   5. https://groups.google.com/d/optout


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Issues with using include-before/include-after when output is pdf
       [not found]     ` <20150723162035.GF31766-nFAEphtLEs/fysO+viCLMa55KtNWUUjk@public.gmane.org>
@ 2015-08-24 16:27       ` Tahir B
       [not found]         ` <7cc8e08e-14fd-4d56-b258-036540acba31-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Tahir B @ 2015-08-24 16:27 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 1740 bytes --]

Hi John --

I am finally getting back to try writing such a filter. I am opting to use 
the python pandocfilters package to intercept this with toJSONFilter. But I 
don't seem to be getting it.

I think I have it close but don't know how to handle the lines in the 
metadata include-after before the start of the reference header.

But when I run pandoc with the filter, I get pandoc: The key "MetaList" was 
not found

How should I be handling the metadata lines in the jsonfilter? How do I 
prepend this before the reference Header object?

Thanks!

from pandocfilters import toJSONFilter, RawBlock, Header
import sys


def latex(x):
    return RawBlock('latex', x)


def references_includeafter(key, value, format, meta):
    if key == 'Header':
        [level, [ident, _, _], content] = value
        if ident == "references":
            if format == "latex":
                # insert include-after lines before start of reference 
header
                includeafter = meta.get('include-after', {})
                print >> sys.stderr, str(includeafter)
                return includeafter

if __name__ == "__main__":
    toJSONFilter(references_includeafter)



-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/7cc8e08e-14fd-4d56-b258-036540acba31%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 3746 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Issues with using include-before/include-after when output is pdf
       [not found]         ` <7cc8e08e-14fd-4d56-b258-036540acba31-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2015-08-24 17:14           ` John MACFARLANE
       [not found]             ` <20150824171445.GB45262-4kKid1p5UN4xFjuZnxJpBp3lxR28IOakuDuwTybUTCk@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: John MACFARLANE @ 2015-08-24 17:14 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

First, are you using a recent pandoc version?

Second, let's start simple.  Use

                   includeafter = meta.get('include-after', {})
                   print >> sys.stderr, str(includeafter)
                   return None

'return None' will cause the header object to be returned
unchanged.  This way you can verify that it is finding
the includeafter list.  Once you verify that, we can move
forward to actually modifying the document.

+++ Tahir B [Aug 24 15 09:27 ]:
>   Hi John --
>   I am finally getting back to try writing such a filter. I am opting to
>   use the python pandocfilters package to intercept this with
>   toJSONFilter. But I don't seem to be getting it.
>   I think I have it close but don't know how to handle the lines in the
>   metadata include-after before the start of the reference header.
>   But when I run pandoc with the filter, I get pandoc: The key "MetaList"
>   was not found
>   How should I be handling the metadata lines in the jsonfilter? How do I
>   prepend this before the reference Header object?
>   Thanks!
>   from pandocfilters import toJSONFilter, RawBlock, Header
>   import sys
>   def latex(x):
>       return RawBlock('latex', x)
>   def references_includeafter(key, value, format, meta):
>       if key == 'Header':
>           [level, [ident, _, _], content] = value
>           if ident == "references":
>               if format == "latex":
>                   # insert include-after lines before start of reference
>   header
>                   includeafter = meta.get('include-after', {})
>                   print >> sys.stderr, str(includeafter)
>                   return includeafter
>   if __name__ == "__main__":
>       toJSONFilter(references_includeafter)
>
>   --
>   You received this message because you are subscribed to the Google
>   Groups "pandoc-discuss" group.
>   To unsubscribe from this group and stop receiving emails from it, send
>   an email to [1]pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
>   To post to this group, send email to
>   [2]pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
>   To view this discussion on the web visit
>   [3]https://groups.google.com/d/msgid/pandoc-discuss/7cc8e08e-14fd-4d56-
>   b258-036540acba31%40googlegroups.com.
>   For more options, visit [4]https://groups.google.com/d/optout.
>
>References
>
>   1. mailto:pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
>   2. mailto:pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
>   3. https://groups.google.com/d/msgid/pandoc-discuss/7cc8e08e-14fd-4d56-b258-036540acba31-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org?utm_medium=email&utm_source=footer
>   4. https://groups.google.com/d/optout


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Issues with using include-before/include-after when output is pdf
       [not found]             ` <20150824171445.GB45262-4kKid1p5UN4xFjuZnxJpBp3lxR28IOakuDuwTybUTCk@public.gmane.org>
@ 2015-08-24 17:28               ` Tahir B
       [not found]                 ` <5b01e8e8-d59b-4589-a46c-ecdbc010df4d-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Tahir B @ 2015-08-24 17:28 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 1484 bytes --]

It seems like the script I have found the "reference" Header object 
perfectly fine.

I can replace the Header object in the output latex.

But I don't know how to take the include-after metadata, convert it into 
the raw commands, and then prepend it before the \section{References} would 
be written.

I'm using the most recent pandoc version, 1.15.0.6.

On Monday, August 24, 2015 at 1:15:01 PM UTC-4, John MacFarlane wrote:
>
> First, are you using a recent pandoc version? 
>
> Second, let's start simple.  Use 
>
>                    includeafter = meta.get('include-after', {}) 
>                    print >> sys.stderr, str(includeafter) 
>                    return None 
>
> 'return None' will cause the header object to be returned 
> unchanged.  This way you can verify that it is finding 
> the includeafter list.  Once you verify that, we can move 
> forward to actually modifying the document. 
>

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/5b01e8e8-d59b-4589-a46c-ecdbc010df4d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 2210 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Issues with using include-before/include-after when output is pdf
       [not found]                 ` <5b01e8e8-d59b-4589-a46c-ecdbc010df4d-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2015-08-24 17:42                   ` Tahir B
  0 siblings, 0 replies; 6+ messages in thread
From: Tahir B @ 2015-08-24 17:42 UTC (permalink / raw)
  To: pandoc-discuss


[-- Attachment #1.1: Type: text/plain, Size: 1450 bytes --]

Ok, I think I got it now... but not sure if there isn't a better way to 
translate the include-after lines into a latex raw block.

John and others, is there a better way to do this?

def references_includeafter(key, value, format, meta):
    if key == 'Header':
        [level, [ident, i1, i2], content] = value
        if ident == "references":
            if format == "latex":
                # insert include-after lines before start of reference 
header
                includeafter = meta.get('include-after', {})
                rawinserts = []
                if includeafter:
                    for metainline in includeafter.get('c', []):
                        for rawinline in metainline.get('c', []):
                            rawinserts.append(rawinline['c'][1])
                return [latex('\n'.join(rawinserts)), Header(level, [ident, 
i1, i2], content)]

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/bac1db0f-8627-4da3-b164-aa481309d73c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

[-- Attachment #1.2: Type: text/html, Size: 2776 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-08-24 17:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-07-23 16:12 Issues with using include-before/include-after when output is pdf Tahir B
     [not found] ` <12a3b4c1-e64e-4f0d-ba1b-545311045f86-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2015-07-23 16:20   ` John MacFarlane
     [not found]     ` <20150723162035.GF31766-nFAEphtLEs/fysO+viCLMa55KtNWUUjk@public.gmane.org>
2015-08-24 16:27       ` Tahir B
     [not found]         ` <7cc8e08e-14fd-4d56-b258-036540acba31-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2015-08-24 17:14           ` John MACFARLANE
     [not found]             ` <20150824171445.GB45262-4kKid1p5UN4xFjuZnxJpBp3lxR28IOakuDuwTybUTCk@public.gmane.org>
2015-08-24 17:28               ` Tahir B
     [not found]                 ` <5b01e8e8-d59b-4589-a46c-ecdbc010df4d-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2015-08-24 17:42                   ` Tahir B

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).