public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* latex macros expansion as a Lua filter?
@ 2023-01-17 19:17 bapt a
       [not found] ` <a5d780b9-2dcc-4cc4-bade-29bae4777811n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: bapt a @ 2023-01-17 19:17 UTC (permalink / raw)
  To: pandoc-discuss


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

Hi,

I've found it useful in some situations to expand all custom LaTeX macros 
(such as `\newcommand{\Curl}{\nabla\times}`, for example) in a document 
before rendering it. 
For example, with Quarto being used to produce a book in both pdf and html 
formats, the macros stored in a file `_macros.tex` are processed 
differently in the LaTeX path (simply including `_macros.tex` in the 
preamble) and in the Html version (where Mathjax needs to be given such 
macros for every page that it renders; it doesn't work to provide it once 
for the whole book/website). 

An alternative that sounds quite robust would be to run something like 
de-macro (https://www.ctan.org/tex-archive/support/de-macro) on the source 
document before it is rendered: the macros are still used for convenience 
of writing in the input file, but they get expanded explicitly before LaTeX 
or Mathjax is asked to render.

Unfortunately, de-macro is a Python script, and might be a little fragile 
as it processes whole documents with regex. I wonder if achieving the same 
thing would be easier with a Lua filter in pandoc? Presumably, having 
already all the equations isolated in the AST makes life a bit easier, and 
I believe there is already a mechanism in pandoc to process and expand 
`\newcommand` directives for non-latex output. Is this mechanism available 
to a Lua filter that could be used in a Quarto workflow?

Many thanks,

baptiste




-- 
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/a5d780b9-2dcc-4cc4-bade-29bae4777811n%40googlegroups.com.

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

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

* Re: latex macros expansion as a Lua filter?
       [not found] ` <a5d780b9-2dcc-4cc4-bade-29bae4777811n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2023-01-17 21:06   ` John MacFarlane
       [not found]     ` <2951DE27-E21B-4C3B-BFEA-BF370ECF50EA-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: John MacFarlane @ 2023-01-17 21:06 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

[-- Attachment #1: Type: text/plain, Size: 2838 bytes --]

Well, you could use the Lua ‘read’ function to read in a snippet consisting of the macro definitions + the math.
e.g.

pandoc -f latex -t native
\newcommand{\pie}{\pi}
$\pie^2$
^D
[ Para [ Math InlineMath "\\pi^2" ] ]

> On Jan 17, 2023, at 11:17 AM, bapt a <auguieba-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> 
> Hi,
> 
> I've found it useful in some situations to expand all custom LaTeX macros (such as `\newcommand{\Curl}{\nabla\times}`, for example) in a document before rendering it. 
> For example, with Quarto being used to produce a book in both pdf and html formats, the macros stored in a file `_macros.tex` are processed differently in the LaTeX path (simply including `_macros.tex` in the preamble) and in the Html version (where Mathjax needs to be given such macros for every page that it renders; it doesn't work to provide it once for the whole book/website). 
> 
> An alternative that sounds quite robust would be to run something like de-macro (https://www.ctan.org/tex-archive/support/de-macro) on the source document before it is rendered: the macros are still used for convenience of writing in the input file, but they get expanded explicitly before LaTeX or Mathjax is asked to render.
> 
> Unfortunately, de-macro is a Python script, and might be a little fragile as it processes whole documents with regex. I wonder if achieving the same thing would be easier with a Lua filter in pandoc? Presumably, having already all the equations isolated in the AST makes life a bit easier, and I believe there is already a mechanism in pandoc to process and expand `\newcommand` directives for non-latex output. Is this mechanism available to a Lua filter that could be used in a Quarto workflow?
> 
> Many thanks,
> 
> baptiste
> 
> 
> 
> 
> 
> -- 
> 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/a5d780b9-2dcc-4cc4-bade-29bae4777811n%40googlegroups.com <https://groups.google.com/d/msgid/pandoc-discuss/a5d780b9-2dcc-4cc4-bade-29bae4777811n%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/2951DE27-E21B-4C3B-BFEA-BF370ECF50EA%40gmail.com.

[-- Attachment #2: Type: text/html, Size: 5039 bytes --]

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

* Re: latex macros expansion as a Lua filter?
       [not found]     ` <2951DE27-E21B-4C3B-BFEA-BF370ECF50EA-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2023-01-18  0:50       ` bapt a
       [not found]         ` <b1e37c1b-8529-4374-b16c-bfc8f0e44213n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: bapt a @ 2023-01-18  0:50 UTC (permalink / raw)
  To: pandoc-discuss


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

I see, thanks. If I'm understanding this correctly, pandoc already performs 
such macro expansions (for non-latex output), so the only thing preventing 
it in the context of a Quarto html book is that one needs to include the 
macros alongside each chapter, as they are processed separately 
(https://github.com/quarto-dev/quarto-cli/discussions/1045).
It's therefore more of a Quarto feature, to make sure the macros are copied 
over with each chapter, but there's no need for an elaborate filter to 
implement this.

Many thanks,

baptiste



On Wednesday, 18 January 2023 at 10:07:00 UTC+13 fiddlosopher wrote:

> Well, you could use the Lua ‘read’ function to read in a snippet 
> consisting of the macro definitions + the math.
> e.g.
>
> pandoc -f latex -t native
> \newcommand{\pie}{\pi}
> $\pie^2$
> ^D
> [ Para [ Math InlineMath "\\pi^2" ] ]
>
> On Jan 17, 2023, at 11:17 AM, bapt a <augu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> Hi,
>
> I've found it useful in some situations to expand all custom LaTeX macros 
> (such as `\newcommand{\Curl}{\nabla\times}`, for example) in a document 
> before rendering it. 
> For example, with Quarto being used to produce a book in both pdf and html 
> formats, the macros stored in a file `_macros.tex` are processed 
> differently in the LaTeX path (simply including `_macros.tex` in the 
> preamble) and in the Html version (where Mathjax needs to be given such 
> macros for every page that it renders; it doesn't work to provide it once 
> for the whole book/website). 
>
> An alternative that sounds quite robust would be to run something like 
> de-macro (https://www.ctan.org/tex-archive/support/de-macro) on the 
> source document before it is rendered: the macros are still used for 
> convenience of writing in the input file, but they get expanded explicitly 
> before LaTeX or Mathjax is asked to render.
>
> Unfortunately, de-macro is a Python script, and might be a little fragile 
> as it processes whole documents with regex. I wonder if achieving the same 
> thing would be easier with a Lua filter in pandoc? Presumably, having 
> already all the equations isolated in the AST makes life a bit easier, and 
> I believe there is already a mechanism in pandoc to process and expand 
> `\newcommand` directives for non-latex output. Is this mechanism available 
> to a Lua filter that could be used in a Quarto workflow?
>
> Many thanks,
>
> baptiste
>
>
>
>
>
> -- 
> 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 view this discussion on the web visit 
> https://groups.google.com/d/msgid/pandoc-discuss/a5d780b9-2dcc-4cc4-bade-29bae4777811n%40googlegroups.com 
> <https://groups.google.com/d/msgid/pandoc-discuss/a5d780b9-2dcc-4cc4-bade-29bae4777811n%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/b1e37c1b-8529-4374-b16c-bfc8f0e44213n%40googlegroups.com.

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

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

* Re: latex macros expansion as a Lua filter?
       [not found]         ` <b1e37c1b-8529-4374-b16c-bfc8f0e44213n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2023-01-18  3:54           ` John MacFarlane
  0 siblings, 0 replies; 4+ messages in thread
From: John MacFarlane @ 2023-01-18  3:54 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

Yes, if the markdown source includes the macro definitions, the macros in math will be expanded by the parser.

> On Jan 17, 2023, at 4:50 PM, bapt a <auguieba-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> 
> I see, thanks. If I'm understanding this correctly, pandoc already performs such macro expansions (for non-latex output), so the only thing preventing it in the context of a Quarto html book is that one needs to include the macros alongside each chapter, as they are processed separately (https://github.com/quarto-dev/quarto-cli/discussions/1045).
> It's therefore more of a Quarto feature, to make sure the macros are copied over with each chapter, but there's no need for an elaborate filter to implement this.
> 
> Many thanks,
> 
> baptiste
> 
> 
> 
> On Wednesday, 18 January 2023 at 10:07:00 UTC+13 fiddlosopher wrote:
> Well, you could use the Lua ‘read’ function to read in a snippet consisting of the macro definitions + the math.
> e.g.
> 
> pandoc -f latex -t native
> \newcommand{\pie}{\pi}
> $\pie^2$
> ^D
> [ Para [ Math InlineMath "\\pi^2" ] ]
> 
>> On Jan 17, 2023, at 11:17 AM, bapt a <augu...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>> 
>> Hi,
>> 
>> I've found it useful in some situations to expand all custom LaTeX macros (such as `\newcommand{\Curl}{\nabla\times}`, for example) in a document before rendering it. 
>> For example, with Quarto being used to produce a book in both pdf and html formats, the macros stored in a file `_macros.tex` are processed differently in the LaTeX path (simply including `_macros.tex` in the preamble) and in the Html version (where Mathjax needs to be given such macros for every page that it renders; it doesn't work to provide it once for the whole book/website). 
>> 
>> An alternative that sounds quite robust would be to run something like de-macro (https://www.ctan.org/tex-archive/support/de-macro) on the source document before it is rendered: the macros are still used for convenience of writing in the input file, but they get expanded explicitly before LaTeX or Mathjax is asked to render.
>> 
>> Unfortunately, de-macro is a Python script, and might be a little fragile as it processes whole documents with regex. I wonder if achieving the same thing would be easier with a Lua filter in pandoc? Presumably, having already all the equations isolated in the AST makes life a bit easier, and I believe there is already a mechanism in pandoc to process and expand `\newcommand` directives for non-latex output. Is this mechanism available to a Lua filter that could be used in a Quarto workflow?
>> 
>> Many thanks,
>> 
>> baptiste
>> 
>> 
>> 
>> 
>> 
>> -- 
>> 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 view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/a5d780b9-2dcc-4cc4-bade-29bae4777811n%40googlegroups.com.
> 
> 
> -- 
> 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/b1e37c1b-8529-4374-b16c-bfc8f0e44213n%40googlegroups.com.

-- 
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/8FE474B9-67DE-4F0A-96FF-8DB5B522133D%40gmail.com.


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

end of thread, other threads:[~2023-01-18  3:54 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-17 19:17 latex macros expansion as a Lua filter? bapt a
     [not found] ` <a5d780b9-2dcc-4cc4-bade-29bae4777811n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2023-01-17 21:06   ` John MacFarlane
     [not found]     ` <2951DE27-E21B-4C3B-BFEA-BF370ECF50EA-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2023-01-18  0:50       ` bapt a
     [not found]         ` <b1e37c1b-8529-4374-b16c-bfc8f0e44213n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2023-01-18  3:54           ` John MacFarlane

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).