* How to add a `\usepackage` in a Lua filter meant to support LaTeX? @ 2020-11-19 19:27 ` Norman Ramsey [not found] ` <2e27c210-a276-4319-abd7-c81d5db7f7d7n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 0 siblings, 1 reply; 8+ messages in thread From: Norman Ramsey @ 2020-11-19 19:27 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1.1: Type: text/plain, Size: 2036 bytes --] I've got a Lua filter that is meant to render certain document elements in a `boxedminipage` environment. To accomplish this feat, I give the element in a suitable `div`, and a Lua filter inserts the LaTeX environment. The document itself remains universal, but the Lua filter is resolutely intended for LaTeX. The filter adds a raw `\usepackage{boxedminipage2e}` to the `header-includes` of the metadata, but unfortunately when `-V header-includes=...` appears on the command line, it takes precedence and the document metadata is ignored. I thought of trying to use `-M header-includes=...` instead of `-V header-includes=...`, but that comes with its own problems: using the `-M` option, the argument on the command line is escaped. It is not clear to me if there is a mechanism I can use to put raw LaTeX in that spot. The issue of the command line overriding metadata has been discussed at some length on the issue tracker (https://github.com/jgm/pandoc/issues/3139) and in pandoc-discuss, where a related issue is laid out in the last post (https://groups.google.com/g/pandoc-discuss/c/N6WhlmSPXbY/m/UYJJBdZwAAAJ). The discussion thread in pandoc-discuss is now two and a half years old, and it seemed to be in favor of a change. But as of pandoc version 2.11.1.1, no change appears to have been made, and issue #3139 remains open. Is there a workaround I can add to my Lua filter that will make it work in a self-contained way even in the presence of assignments to the `header-includes` variable on the command line? And is there any thought of #3139 being resolved one way or the other? -- 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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/2e27c210-a276-4319-abd7-c81d5db7f7d7n%40googlegroups.com. [-- Attachment #1.2: Type: text/html, Size: 2442 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
[parent not found: <2e27c210-a276-4319-abd7-c81d5db7f7d7n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>]
* AW: How to add a `\usepackage` in a Lua filter meant to support LaTeX? [not found] ` <2e27c210-a276-4319-abd7-c81d5db7f7d7n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> @ 2020-11-19 19:50 ` denis.maier-FfwAq0itz3ofv37vnLkPlQ [not found] ` <e6b951c36db0463983df5a4c381693ea-FfwAq0itz3ofv37vnLkPlQ@public.gmane.org> 2020-11-19 20:10 ` John MacFarlane ` (2 subsequent siblings) 3 siblings, 1 reply; 8+ messages in thread From: denis.maier-FfwAq0itz3ofv37vnLkPlQ @ 2020-11-19 19:50 UTC (permalink / raw) To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw I don't know how that would work with a filter, but wouldn't a custom template be an easier solution? Or what speaks against this? Best, Denis ________________________________________ Von: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> im Auftrag von Norman Ramsey <fellswalker-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> Gesendet: Donnerstag, 19. November 2020 20:27:18 An: pandoc-discuss Betreff: How to add a `\usepackage` in a Lua filter meant to support LaTeX? I've got a Lua filter that is meant to render certain document elements in a `boxedminipage` environment. To accomplish this feat, I give the element in a suitable `div`, and a Lua filter inserts the LaTeX environment. The document itself remains universal, but the Lua filter is resolutely intended for LaTeX. The filter adds a raw `\usepackage{boxedminipage2e}` to the `header-includes` of the metadata, but unfortunately when `-V header-includes=...` appears on the command line, it takes precedence and the document metadata is ignored. I thought of trying to use `-M header-includes=...` instead of `-V header-includes=...`, but that comes with its own problems: using the `-M` option, the argument on the command line is escaped. It is not clear to me if there is a mechanism I can use to put raw LaTeX in that spot. The issue of the command line overriding metadata has been discussed at some length on the issue tracker (https://github.com/jgm/pandoc/issues/3139) and in pandoc-discuss, where a related issue is laid out in the last post (https://groups.google.com/g/pandoc-discuss/c/N6WhlmSPXbY/m/UYJJBdZwAAAJ). The discussion thread in pandoc-discuss is now two and a half years old, and it seemed to be in favor of a change. But as of pandoc version 2.11.1.1, no change appears to have been made, and issue #3139 remains open. Is there a workaround I can add to my Lua filter that will make it work in a self-contained way even in the presence of assignments to the `header-includes` variable on the command line? And is there any thought of #3139 being resolved one way or the other? -- 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<mailto:pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>. To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/2e27c210-a276-4319-abd7-c81d5db7f7d7n%40googlegroups.com<https://groups.google.com/d/msgid/pandoc-discuss/2e27c210-a276-4319-abd7-c81d5db7f7d7n%40googlegroups.com?utm_medium=email&utm_source=footer>. -- 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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/e6b951c36db0463983df5a4c381693ea%40ub.unibe.ch. ^ permalink raw reply [flat|nested] 8+ messages in thread
[parent not found: <e6b951c36db0463983df5a4c381693ea-FfwAq0itz3ofv37vnLkPlQ@public.gmane.org>]
* Re: How to add a `\usepackage` in a Lua filter meant to support LaTeX? [not found] ` <e6b951c36db0463983df5a4c381693ea-FfwAq0itz3ofv37vnLkPlQ@public.gmane.org> @ 2020-11-19 21:08 ` Norman Ramsey [not found] ` <6f859587-fd58-46b5-b94b-a21bebe3e6fcn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 0 siblings, 1 reply; 8+ messages in thread From: Norman Ramsey @ 2020-11-19 21:08 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1.1: Type: text/plain, Size: 4769 bytes --] I can work out a solution for my own personal use. But other people are using my infrastructure. Ideally I'd like to be able to tell them, "If you want this effect, use this filter." Asking them also to use a custom template is not only a greater burden, but it's a solution that doesn't compose in the same way that filters do. You can think of the problem I'm trying to solve like this: I want to extend Pandoc with a new capability. The capability is going to be supported by new markup, new CSS (for the HTML writer), and new LaTeX packages (for the LaTeX/PDF writer). But I'm writing more than one extension, and I want my extensions to coexist peacefully with other extensions. I can manage stuff like name-space collisions for element classes. But a custom template become non-compositional. One of the many issues I looked at today mentioned the idea of extending the standard template with a `filter-header-includes` variable, or even a `filter-header-includes.writer` variable. As the OP in that thread observed, it's a bit clunky, but with discipline from filter authors, it could work. The key would be this: filter authors would need to rely on and invariant saying that variable is not set on the command line. @jgm, I'm not sure whether you considered such an extension to the default templates? (Pardon my poor memory, but I got deep into the weeds.) On Thursday, November 19, 2020 at 2:50:51 PM UTC-5 denis...-FfwAq0itz3ofv37vnLkPlQ@public.gmane.org wrote: > I don't know how that would work with a filter, but wouldn't a custom > template be an easier solution? Or what speaks against this? > > Best, > Denis > > > ________________________________________ > Von: pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> im Auftrag > von Norman Ramsey <fells...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > Gesendet: Donnerstag, 19. November 2020 20:27:18 > An: pandoc-discuss > Betreff: How to add a `\usepackage` in a Lua filter meant to support LaTeX? > > I've got a Lua filter that is meant to render certain document elements in > a `boxedminipage` environment. To accomplish this feat, I give the element > in a suitable `div`, and a Lua filter inserts the LaTeX environment. The > document itself remains universal, but the Lua filter is resolutely > intended for LaTeX. > > The filter adds a raw `\usepackage{boxedminipage2e}` to the > `header-includes` of the metadata, but unfortunately when `-V > header-includes=...` appears on the command line, it takes precedence and > the document metadata is ignored. > > I thought of trying to use `-M header-includes=...` instead of `-V > header-includes=...`, but that comes with its own problems: using the `-M` > option, the argument on the command line is escaped. It is not clear to me > if there is a mechanism I can use to put raw LaTeX in that spot. > > The issue of the command line overriding metadata has been discussed at > some length on the issue tracker ( > https://github.com/jgm/pandoc/issues/3139) and in pandoc-discuss, where a > related issue is laid out in the last post ( > https://groups.google.com/g/pandoc-discuss/c/N6WhlmSPXbY/m/UYJJBdZwAAAJ). > The discussion thread in pandoc-discuss is now two and a half years old, > and it seemed to be in favor of a change. But as of pandoc version > 2.11.1.1, no change appears to have been made, and issue #3139 remains open. > > Is there a workaround I can add to my Lua filter that will make it work in > a self-contained way even in the presence of assignments to the > `header-includes` variable on the command line? And is there any thought of > #3139 being resolved one way or the other? > > -- > 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<mailto: > pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>. > To view this discussion on the web visit > https://groups.google.com/d/msgid/pandoc-discuss/2e27c210-a276-4319-abd7-c81d5db7f7d7n%40googlegroups.com > < > https://groups.google.com/d/msgid/pandoc-discuss/2e27c210-a276-4319-abd7-c81d5db7f7d7n%40googlegroups.com?utm_medium=email&utm_source=footer > >. > -- 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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/6f859587-fd58-46b5-b94b-a21bebe3e6fcn%40googlegroups.com. [-- Attachment #1.2: Type: text/html, Size: 7060 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
[parent not found: <6f859587-fd58-46b5-b94b-a21bebe3e6fcn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>]
* Re: How to add a `\usepackage` in a Lua filter meant to support LaTeX? [not found] ` <6f859587-fd58-46b5-b94b-a21bebe3e6fcn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> @ 2020-11-20 10:22 ` krulis....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org 0 siblings, 0 replies; 8+ messages in thread From: krulis....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org @ 2020-11-20 10:22 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1.1: Type: text/plain, Size: 5643 bytes --] I totally agree with the question author: For my personal use I have highly customized LaTeX template. But actually for some projects I could go with only a little customizations like question author: Adding package in CLI and use filter to modify writer to write LaTeX source that uses the package. For some use-cases, this option could be very helpfull, if it would avoid collision with `header-includes` (that is sometimes "blocked" as writes question author). As mentioned, other formats could benefit from that as well. Regards, Tomas Dne čtvrtek 19. listopadu 2020 v 22:08:22 UTC+1 uživatel fells...@gmail.com napsal: > I can work out a solution for my own personal use. But other people are > using my infrastructure. Ideally I'd like to be able to tell them, "If you > want this effect, use this filter." Asking them also to use a custom > template is not only a greater burden, but it's a solution that doesn't > compose in the same way that filters do. You can think of the problem I'm > trying to solve like this: I want to extend Pandoc with a new capability. > The capability is going to be supported by new markup, new CSS (for the > HTML writer), and new LaTeX packages (for the LaTeX/PDF writer). But I'm > writing more than one extension, and I want my extensions to coexist > peacefully with other extensions. I can manage stuff like name-space > collisions for element classes. But a custom template become > non-compositional. > > One of the many issues I looked at today mentioned the idea of extending > the standard template with a `filter-header-includes` variable, or even a > `filter-header-includes.writer` variable. As the OP in that thread > observed, it's a bit clunky, but with discipline from filter authors, it > could work. The key would be this: filter authors would need to rely on > and invariant saying that variable is not set on the command line. @jgm, > I'm not sure whether you considered such an extension to the default > templates? (Pardon my poor memory, but I got deep into the weeds.) > > > On Thursday, November 19, 2020 at 2:50:51 PM UTC-5 denis...-FfwAq0itz3ofv37vnLkPlQ@public.gmane.org > wrote: > >> I don't know how that would work with a filter, but wouldn't a custom >> template be an easier solution? Or what speaks against this? >> >> Best, >> Denis >> >> >> ________________________________________ >> Von: pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <pandoc-...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> im >> Auftrag von Norman Ramsey <fells...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> >> Gesendet: Donnerstag, 19. November 2020 20:27:18 >> An: pandoc-discuss >> Betreff: How to add a `\usepackage` in a Lua filter meant to support >> LaTeX? >> >> I've got a Lua filter that is meant to render certain document elements >> in a `boxedminipage` environment. To accomplish this feat, I give the >> element in a suitable `div`, and a Lua filter inserts the LaTeX >> environment. The document itself remains universal, but the Lua filter is >> resolutely intended for LaTeX. >> >> The filter adds a raw `\usepackage{boxedminipage2e}` to the >> `header-includes` of the metadata, but unfortunately when `-V >> header-includes=...` appears on the command line, it takes precedence and >> the document metadata is ignored. >> >> I thought of trying to use `-M header-includes=...` instead of `-V >> header-includes=...`, but that comes with its own problems: using the `-M` >> option, the argument on the command line is escaped. It is not clear to me >> if there is a mechanism I can use to put raw LaTeX in that spot. >> >> The issue of the command line overriding metadata has been discussed at >> some length on the issue tracker ( >> https://github.com/jgm/pandoc/issues/3139) and in pandoc-discuss, where >> a related issue is laid out in the last post ( >> https://groups.google.com/g/pandoc-discuss/c/N6WhlmSPXbY/m/UYJJBdZwAAAJ). >> >> The discussion thread in pandoc-discuss is now two and a half years old, >> and it seemed to be in favor of a change. But as of pandoc version >> 2.11.1.1, no change appears to have been made, and issue #3139 remains >> open. >> >> Is there a workaround I can add to my Lua filter that will make it work >> in a self-contained way even in the presence of assignments to the >> `header-includes` variable on the command line? And is there any thought of >> #3139 being resolved one way or the other? >> >> -- >> 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<mailto: >> pandoc-discus...-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/pandoc-discuss/2e27c210-a276-4319-abd7-c81d5db7f7d7n%40googlegroups.com >> < >> https://groups.google.com/d/msgid/pandoc-discuss/2e27c210-a276-4319-abd7-c81d5db7f7d7n%40googlegroups.com?utm_medium=email&utm_source=footer>. >> >> > -- 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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/649e3b33-6e0f-4144-8796-2175ee76f3a8n%40googlegroups.com. [-- Attachment #1.2: Type: text/html, Size: 7942 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to add a `\usepackage` in a Lua filter meant to support LaTeX? [not found] ` <2e27c210-a276-4319-abd7-c81d5db7f7d7n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 2020-11-19 19:50 ` AW: " denis.maier-FfwAq0itz3ofv37vnLkPlQ @ 2020-11-19 20:10 ` John MacFarlane 2020-11-20 15:54 ` BPJ 2020-11-20 19:43 ` John MacFarlane 3 siblings, 0 replies; 8+ messages in thread From: John MacFarlane @ 2020-11-19 20:10 UTC (permalink / raw) To: Norman Ramsey, pandoc-discuss You can always use a custom template. Other than that, I'm not sure. I see the need for this, and need to think more about #3139 -- it's the kind of change that might have unexpected consequences. Norman Ramsey <fellswalker-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes: > I've got a Lua filter that is meant to render certain document elements in > a `boxedminipage` environment. To accomplish this feat, I give the element > in a suitable `div`, and a Lua filter inserts the LaTeX environment. The > document itself remains universal, but the Lua filter is resolutely > intended for LaTeX. > > The filter adds a raw `\usepackage{boxedminipage2e}` to the > `header-includes` of the metadata, but unfortunately when `-V > header-includes=...` appears on the command line, it takes precedence and > the document metadata is ignored. > > I thought of trying to use `-M header-includes=...` instead of `-V > header-includes=...`, but that comes with its own problems: using the `-M` > option, the argument on the command line is escaped. It is not clear to me > if there is a mechanism I can use to put raw LaTeX in that spot. > > The issue of the command line overriding metadata has been discussed at > some length on the issue tracker > (https://github.com/jgm/pandoc/issues/3139) and in pandoc-discuss, where a > related issue is laid out in the last post > (https://groups.google.com/g/pandoc-discuss/c/N6WhlmSPXbY/m/UYJJBdZwAAAJ). > The discussion thread in pandoc-discuss is now two and a half years old, > and it seemed to be in favor of a change. But as of pandoc version > 2.11.1.1, no change appears to have been made, and issue #3139 remains open. > > Is there a workaround I can add to my Lua filter that will make it work in > a self-contained way even in the presence of assignments to the > `header-includes` variable on the command line? And is there any thought > of #3139 being resolved one way or the other? > > -- > 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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/2e27c210-a276-4319-abd7-c81d5db7f7d7n%40googlegroups.com. ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to add a `\usepackage` in a Lua filter meant to support LaTeX? [not found] ` <2e27c210-a276-4319-abd7-c81d5db7f7d7n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 2020-11-19 19:50 ` AW: " denis.maier-FfwAq0itz3ofv37vnLkPlQ 2020-11-19 20:10 ` John MacFarlane @ 2020-11-20 15:54 ` BPJ 2020-11-20 19:43 ` John MacFarlane 3 siblings, 0 replies; 8+ messages in thread From: BPJ @ 2020-11-20 15:54 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1: Type: text/plain, Size: 1915 bytes --] On 2020-11-19 20:27, Norman Ramsey wrote: > I've got a Lua filter that is meant to render certain document elements in > a `boxedminipage` environment. To accomplish this feat, I give the element > in a suitable `div`, and a Lua filter inserts the LaTeX environment. The > document itself remains universal, but the Lua filter is resolutely > intended for LaTeX. > > The filter adds a raw `\usepackage{boxedminipage2e}` to the > `header-includes` of the metadata, but unfortunately when `-V > header-includes=...` appears on the command line, it takes precedence and > the document metadata is ignored. However you can, if the filter appends any includes done in the filter to any existing meta.header-includes list combine it with header-includes defined in a *metadata file* via option --metadata-file=FILE or metadadata-files: in a defaults file using the usual idiom: `````````yaml header-includes: - | ````{=latex} \usepackage{relsize} ```` ````````` Alternatively you may even have a filter collect files and inject their contents into the metadata header includes. Two proof-of-concept filters attached: 1. `inject-includes.lua` shows how you may inject includes dynamically in a filter, either creating the meta.header-includes list or appending them to an existing one. 2. `inject-includes-files.lua` shows how you may inject the contents of a directory `header-includes` into the meta.header-includes list and thus get the best of both worlds! :-) -- 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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/3648902d-0ed0-be10-02c6-e5527d6eaaa4%40gmail.com. [-- Attachment #2: inject-includes.lua --] [-- Type: text/x-lua, Size: 2376 bytes --] -- inject-includes.lua -- A proof-of-concept Pandoc filter showing how you may create -- header-includes from inside a filter. -- -- NOTE: this only works if you do *not* use the -H/--include-in-header -- option on the command line or include-in-header: in a defaults file. -- However you can, since the filter appends any includes done in -- the filter to any existing meta.header-includes list combine it with -- header-includes defined in a *metadata file* via -- option --metadata-file=FILE or metadadata-files: in a defaults file -- using the usual idiom: -- -- header-includes: -- - | -- ````{=latex} -- \usepackage{relsize} -- ```` local includes = pandoc.MetaList{} local function inject_include (include, format) -- Fall back to the current output format as raw format -- NOTE: this is a bit risky if you do injects for multiple -- output formats in the same filter! format = format or FORMAT -- Do the actual header include injection includes[#includes+1] = pandoc.MetaBlocks{pandoc.RawBlock(format, include)} end -- If you know you are going to need certain header includes inject them here inject_include( '\\usepackage[margins=raggedright]{floatrow}', 'latex' ) local function add_includes (meta) -- Get an alias so we don't need to type the long name local hinc = 'header-includes' if not meta[hinc] then meta[hinc] = includes else -- Make sure meta.header-includes is a MetaList -- or bail out if it is not. if 'table' ~= type(meta[hinc]) or 'MetaList' ~= meta[hinc].tag then error "Expected meta.header-includes to be list" end meta[hinc]:extend(includes) end return meta end -- If you need to inject includes dynamically do e.g. this: local use_relsize = false -- Reusable template. -- We use `\textlarger` but text will be smaller if number is negative, -- e.g. `\textlarger[-1]` == `\textsmaller[1]`! local relsize_format = '\\textlarger[%d]' local function do_relsize (span) local size = span.attributes.rs -- I like short class/attr names! :-) if not size then return nil end if not use_relsize then inject_include('\\usepackage{relsize}', 'latex') use_relsize = true end size = pandoc.RawInline('latex',relsize_format:format(size)) return {size,span} -- curlies included by pandoc! end return { { Span = do_relsize }, { Meta = add_includes }, } [-- Attachment #3: inject-includes-files.lua --] [-- Type: text/x-lua, Size: 3318 bytes --] -- inject-includes.lua -- A proof-of-concept Pandoc filter showing how you may collect -- header-include files' contents and inject them into document -- metadata from inside a filter. -- -- This is useful if you want to both include metadata from files -- *and* inject header-includes from filters, since if you use -- the -H/--include-in-header option or `include-in-header:` in a -- defaults file meta.header-includes will be ignored. -- -- The workaround is to let a filter locate header-includes files -- from a directory `header-includes` and/or files with names of -- the form `header-include.EXT in the working directory -- and inject their contents into meta.header-includes. -- Pandoc's builtin mechanisms for header-includes files -- must *not* be used! -- -- Files are only included if their extension agrees with the -- current output format. An extension agrees when it is -- identical to pandoc's output format name or is included in -- a table mapping extensions to "agreeing" formats. -- See `local extension` in the filter code below. local function qw (str,pat) pat = tostring(pat or '%S+') str = tostring(str) local lst = {} for s in str:gmatch(pat) do lst[#lst+1] = s end return lst end local function set (list) if 'table' ~= type(list) then list = qw(list) end local set = {} for _,v in ipairs(list) do set[v] = true end return set end local extension = { -- Maps extensions to formats which should have files -- with that extension included. ltx = set"latex beamer", tex = set"latex beamer", html = set"html html5 html4 epub", -- still more? } local function get_includes (format) -- Fall back to the current output format as raw format format = format or FORMAT local includes = pandoc.MetaList{} local includes_dirs = { { dir = '.', pat = '^header-include%.(%w+)$', }, { dir = 'header-includes', pat = '^..-%.(%w+)$', }, } for _,d in ipairs(includes_dirs) do -- Leave to Windows users to figure out how -- to do this on windows. pandoc.system.os -- could be consulted to determine the os local ls = pandoc.pipe("ls",{d.dir},"") -- Seems ls output is returned one line per item for _,f in ipairs(qw(ls,'[^\n]+')) do ext = f:match(d.pat) if ext and(extension[ext] and extension[ext][format]) or(ext == format) then f = d.dir .. '/' .. f local handle = assert( io.open(f), "Couldn't open " .. f ) local include = handle:read'a' handle:close() if "" ~= include then includes[#includes+1] = pandoc.MetaBlocks{ pandoc.RawBlock(format, include) } end end end end if #includes > 0 then return includes end return nil end function Meta (meta) local includes = get_includes(FORMAT) if not includes then return nil end -- Get an alias so we don't need to type the long name local hinc = 'header-includes' if not meta[hinc] then meta[hinc] = includes else -- Make sure meta.header-includes is a MetaList -- or bail out if it is not. if 'table' ~= type(meta[hinc]) or 'MetaList' ~= meta[hinc].tag then error "Expected meta.header-includes to be list" end meta[hinc]:extend(includes) end return meta end ^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: How to add a `\usepackage` in a Lua filter meant to support LaTeX? [not found] ` <2e27c210-a276-4319-abd7-c81d5db7f7d7n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> ` (2 preceding siblings ...) 2020-11-20 15:54 ` BPJ @ 2020-11-20 19:43 ` John MacFarlane [not found] ` <m21rgnhkzz.fsf-jF64zX8BO08an7k8zZ43ob9bIa4KchGshsV+eolpW18@public.gmane.org> 3 siblings, 1 reply; 8+ messages in thread From: John MacFarlane @ 2020-11-20 19:43 UTC (permalink / raw) To: Norman Ramsey, pandoc-discuss Norman Ramsey <fellswalker-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes: > I've got a Lua filter that is meant to render certain document elements in > a `boxedminipage` environment. To accomplish this feat, I give the element > in a suitable `div`, and a Lua filter inserts the LaTeX environment. The > document itself remains universal, but the Lua filter is resolutely > intended for LaTeX. > > The filter adds a raw `\usepackage{boxedminipage2e}` to the > `header-includes` of the metadata, but unfortunately when `-V > header-includes=...` appears on the command line, it takes precedence and > the document metadata is ignored. > > I thought of trying to use `-M header-includes=...` instead of `-V > header-includes=...`, but that comes with its own problems: using the `-M` > option, the argument on the command line is escaped. It is not clear to me > if there is a mechanism I can use to put raw LaTeX in that spot. Why couldn't the filter add to the metadata `header-includes` RawBlock (Format "latex") "\\usepackage{boxedminipage2e}" ? Wouldn't that be a solution? ^ permalink raw reply [flat|nested] 8+ messages in thread
[parent not found: <m21rgnhkzz.fsf-jF64zX8BO08an7k8zZ43ob9bIa4KchGshsV+eolpW18@public.gmane.org>]
* Re: How to add a `\usepackage` in a Lua filter meant to support LaTeX? [not found] ` <m21rgnhkzz.fsf-jF64zX8BO08an7k8zZ43ob9bIa4KchGshsV+eolpW18@public.gmane.org> @ 2020-11-20 21:04 ` Norman Ramsey 0 siblings, 0 replies; 8+ messages in thread From: Norman Ramsey @ 2020-11-20 21:04 UTC (permalink / raw) To: pandoc-discuss [-- Attachment #1.1: Type: text/plain, Size: 1355 bytes --] On Friday, November 20, 2020 at 2:44:01 PM UTC-5 John MacFarlane wrote: > Norman Ramsey <fells...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes: > > > The filter adds a raw `\usepackage{boxedminipage2e}` to the > > `header-includes` of the metadata, but unfortunately when `-V > > header-includes=...` appears on the command line, it takes precedence > and > > the document metadata is ignored. > > > Why couldn't the filter add to the metadata `header-includes` > RawBlock (Format "latex") "\\usepackage{boxedminipage2e}" > ? > > Wouldn't that be a solution? > It’s a solution that works only some of the time. Unfortunately some of my clients have Makefiles that use the `-V` option to set the `header-includes` variable on the command line, and in that case the metadata `header-includes` is ignored. Hence my interest in open issue #3139 (if I am remembering the issue number correctly). -- 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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/f4c096c5-8631-4a32-bf91-9a5487c3c682n%40googlegroups.com. [-- Attachment #1.2: Type: text/html, Size: 1946 bytes --] ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2020-11-20 21:04 UTC | newest] Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <AQHWvqoEJV35v23+VkitO4uJW9kmTKnP3L8H> 2020-11-19 19:27 ` How to add a `\usepackage` in a Lua filter meant to support LaTeX? Norman Ramsey [not found] ` <2e27c210-a276-4319-abd7-c81d5db7f7d7n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 2020-11-19 19:50 ` AW: " denis.maier-FfwAq0itz3ofv37vnLkPlQ [not found] ` <e6b951c36db0463983df5a4c381693ea-FfwAq0itz3ofv37vnLkPlQ@public.gmane.org> 2020-11-19 21:08 ` Norman Ramsey [not found] ` <6f859587-fd58-46b5-b94b-a21bebe3e6fcn-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> 2020-11-20 10:22 ` krulis....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org 2020-11-19 20:10 ` John MacFarlane 2020-11-20 15:54 ` BPJ 2020-11-20 19:43 ` John MacFarlane [not found] ` <m21rgnhkzz.fsf-jF64zX8BO08an7k8zZ43ob9bIa4KchGshsV+eolpW18@public.gmane.org> 2020-11-20 21:04 ` Norman Ramsey
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).