* Formatting references in LaTeX (with a filter?) @ 2014-11-21 17:03 Thomas Hodgson [not found] ` <f5447dbe-4ad6-48f4-9370-422bf830e18b-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 0 siblings, 1 reply; 8+ messages in thread From: Thomas Hodgson @ 2014-11-21 17:03 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw [-- Attachment #1.1: Type: text/plain, Size: 1259 bytes --] I currently put something like this at the end of my markdown files: ``` # References {-} \setlength{\parindent}{-0.2in} \setlength{\leftskip}{0.2in} \setlength{\parskip}{8pt} \vspace*{-0.2in} \noindent ``` This gives me what I want when I use Pandoc to convert the MD to a PDF. I would like to avoid the five lines of LaTeX if possible (just for neatness). If I use `--include-after` the material comes after the bibliography. Should I look in to writing a filter? The first problem thatI saw is that when I looked at the AST I saw that the references are an ordinary header called 'References'. Is it possible to write the filter so that some LaTeX comes immediately after it? -- 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/f5447dbe-4ad6-48f4-9370-422bf830e18b%40googlegroups.com. For more options, visit https://groups.google.com/d/optout. [-- Attachment #1.2: Type: text/html, Size: 1794 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
[parent not found: <f5447dbe-4ad6-48f4-9370-422bf830e18b-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>]
* Re: Formatting references in LaTeX (with a filter?) [not found] ` <f5447dbe-4ad6-48f4-9370-422bf830e18b-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> @ 2014-11-21 18:06 ` John MacFarlane [not found] ` <20141121180633.GF97029-bi+AKbBUZKbivNSvqvJHCtPlBySK3R6THiGdP5j34PU@public.gmane.org> 2014-11-21 18:16 ` Aaron O'Leary 1 sibling, 1 reply; 8+ messages in thread From: John MacFarlane @ 2014-11-21 18:06 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw +++ Thomas Hodgson [Nov 21 14 09:03 ]: >I currently put something like this at the end of my markdown files: > >``` ># References {-} >\setlength{\parindent}{-0.2in} >\setlength{\leftskip}{0.2in} >\setlength{\parskip}{8pt} >\vspace*{-0.2in} >\noindent >``` > >This gives me what I want when I use Pandoc to convert the MD to a PDF. I >would like to avoid the five lines of LaTeX if possible (just for >neatness). If I use `--include-after` the material comes after the >bibliography. Should I look in to writing a filter? The first problem thatI >saw is that when I looked at the AST I saw that the references are an >ordinary header called 'References'. Is it possible to write the filter so >that some LaTeX comes immediately after it? Sure, the easiest approach would be just to write a function with type Pandoc -> Pandoc, like insertLatexLines :: Pandoc -> Pandoc insertLatexLines (Pandoc meta bs) = Pandoc meta (bs ++ [RawBlock (Format "latex") latexLines]) where latexLines = "\\setlength...etc." then toJSONFilter insertLatexLines. Then, just make sure to put this filter BEFORE pandoc-citeproc when you call pandoc: pandoc -F ./insertLatexLines -F pandoc-citeproc ^ permalink raw reply [flat|nested] 8+ messages in thread
[parent not found: <20141121180633.GF97029-bi+AKbBUZKbivNSvqvJHCtPlBySK3R6THiGdP5j34PU@public.gmane.org>]
* Re: Formatting references in LaTeX (with a filter?) [not found] ` <20141121180633.GF97029-bi+AKbBUZKbivNSvqvJHCtPlBySK3R6THiGdP5j34PU@public.gmane.org> @ 2014-11-21 18:28 ` Aaron O'Leary [not found] ` <20141121182803.GA26159-7oEbiFy5NbMJIeqeF16ok3a01M2gRsDTtUK59QYPAWc@public.gmane.org> 0 siblings, 1 reply; 8+ messages in thread From: Aaron O'Leary @ 2014-11-21 18:28 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw On Fri 21 Nov, John MacFarlane wrote: > when you call pandoc: > > pandoc -F ./insertLatexLines -F pandoc-citeproc Today I learned that you can use multiple filters! Thanks! ^ permalink raw reply [flat|nested] 8+ messages in thread
[parent not found: <20141121182803.GA26159-7oEbiFy5NbMJIeqeF16ok3a01M2gRsDTtUK59QYPAWc@public.gmane.org>]
* Re: Formatting references in LaTeX (with a filter?) [not found] ` <20141121182803.GA26159-7oEbiFy5NbMJIeqeF16ok3a01M2gRsDTtUK59QYPAWc@public.gmane.org> @ 2014-11-21 23:00 ` Thomas Hodgson 2014-11-22 15:40 ` BPJ 1 sibling, 0 replies; 8+ messages in thread From: Thomas Hodgson @ 2014-11-21 23:00 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw [-- Attachment #1.1: Type: text/plain, Size: 876 bytes --] Thank-you both. That's just what I was after. On Friday, 21 November 2014 18:28:09 UTC, Aaron O'leary wrote: > > On Fri 21 Nov, John MacFarlane wrote: > > when you call pandoc: > > > > pandoc -F ./insertLatexLines -F pandoc-citeproc > > Today I learned that you can use multiple filters! Thanks! > -- 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/2852f169-02d4-483e-83a5-4b1ea440f751%40googlegroups.com. For more options, visit https://groups.google.com/d/optout. [-- Attachment #1.2: Type: text/html, Size: 1444 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Formatting references in LaTeX (with a filter?) [not found] ` <20141121182803.GA26159-7oEbiFy5NbMJIeqeF16ok3a01M2gRsDTtUK59QYPAWc@public.gmane.org> 2014-11-21 23:00 ` Thomas Hodgson @ 2014-11-22 15:40 ` BPJ [not found] ` <CADAJKhB3Q6L=2=SMaDEpL+5iVyB53KxRfdi=Bz+eVKuGkcj1qg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 1 sibling, 1 reply; 8+ messages in thread From: BPJ @ 2014-11-22 15:40 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw [-- Attachment #1: Type: text/plain, Size: 1932 bytes --] Sure, it saves you a lot of time! A tip: you can use classes on Header/Code/CodeBlock/Span/Div elements and have filters look at them to indicate which filter should act on them; not least an earlier filter can 'call the attention' of a later filter this way, and even have a last filter which removes temporary 'wrapper' spans/divs by giving them a special class which it recognises or by ending such filtering classes in a special character sequence. /bpj Den 21 nov 2014 19:28 skrev "Aaron O'Leary" <aaron.oleary-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: > On Fri 21 Nov, John MacFarlane wrote: > > when you call pandoc: > > > > pandoc -F ./insertLatexLines -F pandoc-citeproc > > Today I learned that you can use multiple filters! Thanks! > > -- > 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/20141121182803.GA26159%40tk422.wireless.leeds.ac.uk > . > For more options, visit https://groups.google.com/d/optout. > -- 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/CADAJKhB3Q6L%3D2%3DSMaDEpL%2B5iVyB53KxRfdi%3DBz%2BeVKuGkcj1qg%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout. [-- Attachment #2: Type: text/html, Size: 3016 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
[parent not found: <CADAJKhB3Q6L=2=SMaDEpL+5iVyB53KxRfdi=Bz+eVKuGkcj1qg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>]
* Re: Formatting references in LaTeX (with a filter?) [not found] ` <CADAJKhB3Q6L=2=SMaDEpL+5iVyB53KxRfdi=Bz+eVKuGkcj1qg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> @ 2014-11-22 16:32 ` nickbart1980-Re5JQEeQqe8AvxtiuMwx3w [not found] ` <1ee3a1f7-2612-4d84-9507-719be1430116-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 0 siblings, 1 reply; 8+ messages in thread From: nickbart1980-Re5JQEeQqe8AvxtiuMwx3w @ 2014-11-22 16:32 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw Cc: bpj-J3H7GcXPSITLoDKTGw+V6w, bpj-J3H7GcXPSITLoDKTGw+V6w [-- Attachment #1.1: Type: text/plain, Size: 2361 bytes --] Could pandoc do this automatically, depending on whether the CSL style file specifies <bibliography hanging-indent="true" …> or <bibliography hanging-indent="false" …> ("false" is the default)? See http://citationstyles.org/downloads/specification.html#whitespace On Saturday, 22 November 2014 15:40:22 UTC, BPJ wrote: > > Sure, it saves you a lot of time! > > A tip: you can use classes on Header/Code/CodeBlock/Span/Div elements and > have filters look at them to indicate which filter should act on them; not > least an earlier filter can 'call the attention' of a later filter this > way, and even have a last filter which removes temporary 'wrapper' > spans/divs by giving them a special class which it recognises or by ending > such filtering classes in a special character sequence. > > /bpj > Den 21 nov 2014 19:28 skrev "Aaron O'Leary" <aaron....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > <javascript:>>: > >> On Fri 21 Nov, John MacFarlane wrote: >> > when you call pandoc: >> > >> > pandoc -F ./insertLatexLines -F pandoc-citeproc >> >> Today I learned that you can use multiple filters! Thanks! >> >> -- >> 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-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <javascript:>. >> To post to this group, send email to pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org >> <javascript:>. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/pandoc-discuss/20141121182803.GA26159%40tk422.wireless.leeds.ac.uk >> . >> For more options, visit https://groups.google.com/d/optout. >> > -- 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/1ee3a1f7-2612-4d84-9507-719be1430116%40googlegroups.com. For more options, visit https://groups.google.com/d/optout. [-- Attachment #1.2: Type: text/html, Size: 4203 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
[parent not found: <1ee3a1f7-2612-4d84-9507-719be1430116-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>]
* Re: Formatting references in LaTeX (with a filter?) [not found] ` <1ee3a1f7-2612-4d84-9507-719be1430116-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> @ 2014-12-02 9:59 ` nickbart1980-Re5JQEeQqe8AvxtiuMwx3w 0 siblings, 0 replies; 8+ messages in thread From: nickbart1980-Re5JQEeQqe8AvxtiuMwx3w @ 2014-12-02 9:59 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw; +Cc: bpj-J3H7GcXPSITLoDKTGw+V6w [-- Attachment #1.1: Type: text/plain, Size: 4949 bytes --] I have been using an approach similar to the one mentioned by the OP, in my case putting `\hangindent1.5em\hangafter1\noindent` (lifted from `hanging.sty`) right after `# References` for some time, too. While this works for most cases, it fails when additional text is inserted after the reference list, e.g., when creating multi-part bibliographies by stitching together latex fragments. The problem is that the scope of `\hangindent1.5em\hangafter1\noindent` is not (and cannot be) limited and thus messes with the formatting of subsequent text. In the case of a multi-part bibliography, e.g., the vertical space before subsequent section headers is greatly reduced. My feeling is that the proper way to deal with the formatting of reference list entries in pandoc is to have the latex writer wrap all reference list entries (but not the `# References` header) in a latex environment, e.g.: `\begin{pandocreferences} ... [reference list entries] \end{pandocreferences}` which could be defined in the default.latex template, adapted from `hanging.sty`, as: `\newenvironment{pandocreferences}[1]{\setlength{\parindent}{\z@} \everypar={\hangindent1.5em\hangafter1\noindent}}{\par}` BTW, I feel this should definitely be part of pandoc's core functionality and should not be relegated to a filter. What's more, this approach could be used to start coping with formatting directives from CSL styles files (well, at least hanging-indent true vs. false), e.g. IF CSL STYLE FILE CONTAINS <bibliography hanging-indent="true" …> THEN `\newenvironment{pandocreferences}[1]{\setlength{\parindent}{\z@} \everypar={\hangindent1.5em\hangafter1\noindent}}{\par}` ELSE `\newenvironment{pandocreferences}[1]{\setlength{\parindent}{\z@} \everypar={\hangindent0em\hangafter1\noindent}}{\par}` ENDIF To implement additional CSL options such as `second-field-align` (http://citationstyles.org/downloads/specification.html#whitespace) it might also be useful to look into the way biblatex formats reference list entries. Apparently it uses `\defbibenvironment` to define a *list* environment, and since `second-field-align` is essentially a list format, and ordinary hanging indent can also be formatted using latex lists, this might have advantages. I have not been able to figure out from manual or source what exactly biblatex does though, but maybe a biblatex expert could help us out ... On Saturday, 22 November 2014 16:32:25 UTC, nickba...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: > > Could pandoc do this automatically, depending on whether the CSL style > file specifies > > <bibliography hanging-indent="true" …> or > > <bibliography hanging-indent="false" …> > > ("false" is the default)? > > See http://citationstyles.org/downloads/specification.html#whitespace > > On Saturday, 22 November 2014 15:40:22 UTC, BPJ wrote: >> >> Sure, it saves you a lot of time! >> >> A tip: you can use classes on Header/Code/CodeBlock/Span/Div elements and >> have filters look at them to indicate which filter should act on them; not >> least an earlier filter can 'call the attention' of a later filter this >> way, and even have a last filter which removes temporary 'wrapper' >> spans/divs by giving them a special class which it recognises or by ending >> such filtering classes in a special character sequence. >> >> /bpj >> Den 21 nov 2014 19:28 skrev "Aaron O'Leary" <aaron....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>: >> >>> On Fri 21 Nov, John MacFarlane wrote: >>> > when you call pandoc: >>> > >>> > pandoc -F ./insertLatexLines -F pandoc-citeproc >>> >>> Today I learned that you can use multiple filters! Thanks! >>> >>> -- >>> 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-discus...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> To post to this group, send email to pandoc-...-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >>> To view this discussion on the web visit >>> https://groups.google.com/d/msgid/pandoc-discuss/20141121182803.GA26159%40tk422.wireless.leeds.ac.uk >>> . >>> For more options, visit https://groups.google.com/d/optout. >>> >> -- 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/1fa6289b-84a2-42cc-9822-65f10d73d472%40googlegroups.com. For more options, visit https://groups.google.com/d/optout. [-- Attachment #1.2: Type: text/html, Size: 6960 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Formatting references in LaTeX (with a filter?) [not found] ` <f5447dbe-4ad6-48f4-9370-422bf830e18b-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 2014-11-21 18:06 ` John MacFarlane @ 2014-11-21 18:16 ` Aaron O'Leary 1 sibling, 0 replies; 8+ messages in thread From: Aaron O'Leary @ 2014-11-21 18:16 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw On Fri 21 Nov, Thomas Hodgson wrote: > Is it possible to write the filter so that some LaTeX comes > immediately after it? In python you can do it like this: import pandocfilters as pf reference_formatting = r"""\setlength{\parindent}{-0.2in} \setlength{\leftskip}{0.2in} \setlength{\parskip}{8pt} \vspace*{-0.2in} \noindent """ format_block = pf.RawBlock('latex', reference_formatting) def ref(key, value, format, meta): if key == 'Header' and value[2][0]['c'] == 'References': return [pf.Header(*value), format_block] if __name__ == '__main__': pf.toJSONFilter(ref) This scans the document looking for a header called 'References', then puts a block of latex after that header. You can add `and format == 'latex'` to the if statement to have it only active when you are outputting latex. ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2014-12-02 9:59 UTC | newest] Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2014-11-21 17:03 Formatting references in LaTeX (with a filter?) Thomas Hodgson [not found] ` <f5447dbe-4ad6-48f4-9370-422bf830e18b-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 2014-11-21 18:06 ` John MacFarlane [not found] ` <20141121180633.GF97029-bi+AKbBUZKbivNSvqvJHCtPlBySK3R6THiGdP5j34PU@public.gmane.org> 2014-11-21 18:28 ` Aaron O'Leary [not found] ` <20141121182803.GA26159-7oEbiFy5NbMJIeqeF16ok3a01M2gRsDTtUK59QYPAWc@public.gmane.org> 2014-11-21 23:00 ` Thomas Hodgson 2014-11-22 15:40 ` BPJ [not found] ` <CADAJKhB3Q6L=2=SMaDEpL+5iVyB53KxRfdi=Bz+eVKuGkcj1qg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org> 2014-11-22 16:32 ` nickbart1980-Re5JQEeQqe8AvxtiuMwx3w [not found] ` <1ee3a1f7-2612-4d84-9507-719be1430116-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 2014-12-02 9:59 ` nickbart1980-Re5JQEeQqe8AvxtiuMwx3w 2014-11-21 18:16 ` Aaron O'Leary
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).