* Mathjax and TOC does not work with HTML custom lua writer
@ 2022-03-24 10:54 AustinLe
[not found] ` <b5250fc3-b431-4d07-9dcb-bb81ca43f825n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
0 siblings, 1 reply; 5+ messages in thread
From: AustinLe @ 2022-03-24 10:54 UTC (permalink / raw)
To: pandoc-discuss
[-- Attachment #1.1: Type: text/plain, Size: 1358 bytes --]
I was trying to generate the same HTML from Markdown with as one with `-s
-t html` using the default `sample.lua` writer and `default.html5` but
found that the table of contents is missing and math formulas does not
render correctly. This is the command I was using:
```
pandoc --standalone --toc --mathjax --citeproc -f markdown
--template=default.html5 -t sample.lua my-markdown.md -o index.html
--variable document-css --variable highlighting-css --variable
displaymath-css --variable csl-css --variable csl-entry-spacing
```
Pandoc version:
```
> pandoc -v
pandoc 2.17.1.1
Compiled with pandoc-types 1.22.1, texmath 0.12.4, skylighting 0.12.2,
citeproc 0.6.0.1, ipynb 0.2
User data directory: /share/home/leh/.pandoc
Copyright (C) 2006-2022 John MacFarlane. Web: https://pandoc.org
This is free software; see the source for copying conditions. There is no
warranty, not even for merchantability or fitness for a particular purpose.
```
--
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/b5250fc3-b431-4d07-9dcb-bb81ca43f825n%40googlegroups.com.
[-- Attachment #1.2: Type: text/html, Size: 1793 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Mathjax and TOC does not work with HTML custom lua writer
[not found] ` <b5250fc3-b431-4d07-9dcb-bb81ca43f825n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
@ 2022-03-24 18:35 ` John MacFarlane
[not found] ` <m2zglfjj1b.fsf-jF64zX8BO0+FqBokazbCQ6OPv3vYUT2dxr7GGTnW70NeoWH0uzbU5w@public.gmane.org>
0 siblings, 1 reply; 5+ messages in thread
From: John MacFarlane @ 2022-03-24 18:35 UTC (permalink / raw)
To: AustinLe, pandoc-discuss
sample.lua is just what it says...an example.
You'll need to construct a TOC manually in Lua if you want one.
And you'll have to modify sample.lua to produce the math output
you want.
For small changes a Lua filter is probably what you want.
AustinLe <lhoangan.nl-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
> I was trying to generate the same HTML from Markdown with as one with `-s
> -t html` using the default `sample.lua` writer and `default.html5` but
> found that the table of contents is missing and math formulas does not
> render correctly. This is the command I was using:
> ```
> pandoc --standalone --toc --mathjax --citeproc -f markdown
> --template=default.html5 -t sample.lua my-markdown.md -o index.html
> --variable document-css --variable highlighting-css --variable
> displaymath-css --variable csl-css --variable csl-entry-spacing
> ```
> Pandoc version:
> ```
>> pandoc -v
> pandoc 2.17.1.1
> Compiled with pandoc-types 1.22.1, texmath 0.12.4, skylighting 0.12.2,
> citeproc 0.6.0.1, ipynb 0.2
> User data directory: /share/home/leh/.pandoc
> Copyright (C) 2006-2022 John MacFarlane. Web: https://pandoc.org
> This is free software; see the source for copying conditions. There is no
> warranty, not even for merchantability or fitness for a particular purpose.
> ```
>
> --
> 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/b5250fc3-b431-4d07-9dcb-bb81ca43f825n%40googlegroups.com.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Mathjax and TOC does not work with HTML custom lua writer
[not found] ` <m2zglfjj1b.fsf-jF64zX8BO0+FqBokazbCQ6OPv3vYUT2dxr7GGTnW70NeoWH0uzbU5w@public.gmane.org>
@ 2022-03-24 19:26 ` Hoàng-Ân Lê
[not found] ` <CAKY_PKtOFRs085OJCCaAqjHyjo7BPSstUojaxGqE8vC3HFNrhg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
0 siblings, 1 reply; 5+ messages in thread
From: Hoàng-Ân Lê @ 2022-03-24 19:26 UTC (permalink / raw)
To: John MacFarlane; +Cc: pandoc-discuss
[-- Attachment #1: Type: text/plain, Size: 2651 bytes --]
Well, I trust in the "that is very similar to that of pandoc's HTML
writer". So I was confused when it's not that similar. I actually had to
come up with all the elements that I thought could be different and went on
to manually check the generated code one by one.
Could you elaborate how TOC and Mathjax could be done?
On Thu, 24 Mar 2022 at 19:35, John MacFarlane <jgm-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org> wrote:
>
> sample.lua is just what it says...an example.
> You'll need to construct a TOC manually in Lua if you want one.
> And you'll have to modify sample.lua to produce the math output
> you want.
>
>
> For small changes a Lua filter is probably what you want.
>
> AustinLe <lhoangan.nl-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
>
> > I was trying to generate the same HTML from Markdown with as one with
> `-s
> > -t html` using the default `sample.lua` writer and `default.html5` but
> > found that the table of contents is missing and math formulas does not
> > render correctly. This is the command I was using:
> > ```
> > pandoc --standalone --toc --mathjax --citeproc -f markdown
> > --template=default.html5 -t sample.lua my-markdown.md -o index.html
> > --variable document-css --variable highlighting-css --variable
> > displaymath-css --variable csl-css --variable csl-entry-spacing
> > ```
> > Pandoc version:
> > ```
> >> pandoc -v
> > pandoc 2.17.1.1
> > Compiled with pandoc-types 1.22.1, texmath 0.12.4, skylighting 0.12.2,
> > citeproc 0.6.0.1, ipynb 0.2
> > User data directory: /share/home/leh/.pandoc
> > Copyright (C) 2006-2022 John MacFarlane. Web: https://pandoc.org
> > This is free software; see the source for copying conditions. There is no
> > warranty, not even for merchantability or fitness for a particular
> purpose.
> > ```
> >
> > --
> > 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/b5250fc3-b431-4d07-9dcb-bb81ca43f825n%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/CAKY_PKtOFRs085OJCCaAqjHyjo7BPSstUojaxGqE8vC3HFNrhg%40mail.gmail.com.
[-- Attachment #2: Type: text/html, Size: 4081 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Mathjax and TOC does not work with HTML custom lua writer
[not found] ` <CAKY_PKtOFRs085OJCCaAqjHyjo7BPSstUojaxGqE8vC3HFNrhg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2022-03-25 2:30 ` John MacFarlane
[not found] ` <m2fsn6ix1n.fsf-jF64zX8BO0+FqBokazbCQ6OPv3vYUT2dxr7GGTnW70NeoWH0uzbU5w@public.gmane.org>
0 siblings, 1 reply; 5+ messages in thread
From: John MacFarlane @ 2022-03-25 2:30 UTC (permalink / raw)
To: Hoàng-Ân Lê; +Cc: pandoc-discuss
Hoàng-Ân Lê <lhoangan.nl-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
> Well, I trust in the "that is very similar to that of pandoc's HTML
> writer". So I was confused when it's not that similar. I actually had to
> come up with all the elements that I thought could be different and went on
> to manually check the generated code one by one.
>
> Could you elaborate how TOC and Mathjax could be done?
With math, it should be fine as it is, as long as your
template sets up mathjax to parse math between \(..\) and
\[..\] delimiters.
Pandoc's HTML writer inserts a snippet into the HTML header
(where the $math$ variable is) that loads mathjax and sets
appropriate options. You can have your custom writer set
the math variable to something appropriate.
See https://pandoc.org/custom-writers.html#template-variables
The TOC is more complex. You'd have to construct it yourself
programatically. For example, you could build a Lua table
and add to it every time you encounter a Header element.
Then, in the Doc function, construct an HTML TOC based
on this table, and add it to the document body. I can't
go into more detail -- if this is enough to get you started,
great.
--
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/m2fsn6ix1n.fsf%40MacBook-Pro-2.hsd1.ca.comcast.net.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Mathjax and TOC does not work with HTML custom lua writer
[not found] ` <m2fsn6ix1n.fsf-jF64zX8BO0+FqBokazbCQ6OPv3vYUT2dxr7GGTnW70NeoWH0uzbU5w@public.gmane.org>
@ 2022-03-25 9:38 ` William Lupton
0 siblings, 0 replies; 5+ messages in thread
From: William Lupton @ 2022-03-25 9:38 UTC (permalink / raw)
To: Hoàng-Ân Lê; +Cc: pandoc-discuss
[-- Attachment #1.1: Type: text/plain, Size: 2495 bytes --]
the attached toc.lua might be helpful (please see the comments at the top
of the file: this is a fragment extracted from an HTML writer that also
does some other things, so you'll have to delete some sections, but it
should be easily adaptable); cheers, w.
On Fri, 25 Mar 2022 at 02:30, John MacFarlane <jgm-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org> wrote:
> Hoàng-Ân Lê <lhoangan.nl-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
>
> > Well, I trust in the "that is very similar to that of pandoc's HTML
> > writer". So I was confused when it's not that similar. I actually had to
> > come up with all the elements that I thought could be different and went
> on
> > to manually check the generated code one by one.
> >
> > Could you elaborate how TOC and Mathjax could be done?
>
> With math, it should be fine as it is, as long as your
> template sets up mathjax to parse math between \(..\) and
> \[..\] delimiters.
>
> Pandoc's HTML writer inserts a snippet into the HTML header
> (where the $math$ variable is) that loads mathjax and sets
> appropriate options. You can have your custom writer set
> the math variable to something appropriate.
> See https://pandoc.org/custom-writers.html#template-variables
>
> The TOC is more complex. You'd have to construct it yourself
> programatically. For example, you could build a Lua table
> and add to it every time you encounter a Header element.
> Then, in the Doc function, construct an HTML TOC based
> on this table, and add it to the document body. I can't
> go into more detail -- if this is enough to get you started,
> great.
>
> --
> 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/m2fsn6ix1n.fsf%40MacBook-Pro-2.hsd1.ca.comcast.net
> .
>
--
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/CAEe_xxhi%3Dr9L8CxbimMiLYmLSP9A4hm7bg%3D9S0jg_0k-vibaKA%40mail.gmail.com.
[-- Attachment #1.2: Type: text/html, Size: 3589 bytes --]
[-- Attachment #2: toc.lua --]
[-- Type: application/octet-stream, Size: 5825 bytes --]
-- this code has been pulled from a pandoc lua custom writer; there are some
-- unresolved references that relate to optional features that will have to
-- be disabled; however, it should be possible to reuse the basic mechanism
-- note: I have recently realised that the generated HTML incorrectly closes
-- list items before adding nested lists; this doesn't seem to affect how the
-- ToC is rendered, but it should still be fixed
-- Table to store headers, so can generate table of contents
local headers = {}
-- Table to store footnotes, so they can be included at the end
local footnotes = {}
-- Helper function to add a ToC of the specified style; the add argument is as
-- for splitlines()
local function tableofcontents(style, add, metadata)
-- XXX styles are experimental; maybe it's better to pass in the table
-- rather than the style name
local maxlev = tonumber(meta['toc-depth'])
local styles = {
contents = {header=true, contents=false, list='ul', item='li',
maxlev=maxlev, unlisted='unlisted', sep='', navid=nil},
navigation = {header=nil, contents=true, list='', list0='p', item='',
maxlev=1, unlisted='same-file', sep=' | ', navid=nil},
tocfull = {header=nil, contents=true, list='ul', item='li',
maxlev=maxlev, unlisted='unlisted', sep='',
navid='TOCFULL'},
}
style = style or 'contents'
local buffer = {}
if add == nil then
add = function(s)
table.insert(buffer, s)
end
end
-- helper for opening and closing lists
local lev = 0
local function openclose(header_lev)
local elem = styles[style].list
local elem0 = styles[style].list0 or elem
while lev > header_lev do
lev = lev - 1
local elem_ = lev == 0 and elem0 or elem
if #elem_ > 0 then
add(string.rep(' ', lev) .. '</' .. elem_ .. '>')
end
end
while lev < header_lev do
local elem_ = lev == 0 and elem0 or elem
if #elem_ > 0 then
add(string.rep(' ', lev) .. '<' .. elem_ .. '>')
end
lev = lev + 1
end
end
-- helper for adding items
local first = true
local function additem(id, s)
local elem = styles[style].item
local sep = styles[style].sep
sep = first and string.rep(' ', #sep) or sep
local ind = #sep == 0 and string.rep(' ', lev) or ''
local open = #elem > 0 and '<' .. elem .. '>' or ''
local close = #elem > 0 and '</' .. elem .. '>' or ''
add(string.format('%s%s%s<a href="#%s">%s</a>%s', ind, sep, open, id,
s, close))
first = false
end
-- optionally insert an entry at the start as a contents link
-- XXX should use variables for id and s
local before = {}
if styles[style].contents then
before = {{lev=1, attr={id=contents_name},
s=filelabel(contents_name)}}
idtonum[contents_name] = filenum.number(0)
end
-- if footnotes, insert an entry at the end as a footnotes link
-- XXX should use variables for id and s
local after = {}
if #footnotes > 0 then
after = {{lev=1, attr={id=footnotes_name},
s=filelabel(footnotes_name)}}
idtonum[footnotes_name] = filenum.number(-1)
end
-- count the actual number of items
-- XXX this logic is (unfortunately) duplicated below; should use a
-- visitor pattern
local maxlev = styles[style].maxlev
local unlisted_class = styles[style].unlisted or 'unlisted'
local total = 0
for _, headers_ in ipairs({before, headers, after}) do
for _, header in ipairs(headers_) do
local new_file = utils.contains(header.attr.class, 'new-file')
local unlisted = utils.contains(header.attr.class, unlisted_class)
if ((maxlev == nil or header.lev <= maxlev or new_file) and
(not unlisted)) then
total = total + 1
end
end
end
-- only output the ToC if it contains at least two items
if total >= #before + 2 then
-- optionally insert a ToC header
-- XXX tocTitle should be defined alongside pandoc-crossref lofTitle,
-- lotTitle etc.
if styles[style].header then
local tocTitle = metadata.tocTitle or '<h3 class="unnumbered ' ..
'unlisted" id="table-of-contents">Table of Contents</h3>'
add(tocTitle)
add('')
end
-- use the <nav> tag (this is what the pandoc HTML writer does)
-- XXX maxlev seems off by one sometimes? need to investigate
local navid = styles[style].navid
add(navid and '<nav id="' .. navid .. '">' or '<nav>')
for _, headers_ in ipairs({before, headers, after}) do
for _, header in ipairs(headers_) do
local new_file = utils.contains(header.attr.class, 'new-file')
local unlisted = utils.contains(header.attr.class,
unlisted_class)
if ((maxlev == nil or header.lev <= maxlev or new_file) and
(not unlisted)) then
openclose(header.lev)
additem(header.attr.id, header.s)
end
end
end
openclose(0)
add('</nav>')
add('')
end
return buffer
end
-- lots of things omitted here --
-- lev is an integer, the header level.
function Header(lev, s, attr)
-- save for later ToC generation
table.insert(headers, {lev=lev, s=s, attr=attr})
-- the rest is omitted --
end
-- lots more omitted here --
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-03-25 9:38 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-24 10:54 Mathjax and TOC does not work with HTML custom lua writer AustinLe
[not found] ` <b5250fc3-b431-4d07-9dcb-bb81ca43f825n-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>
2022-03-24 18:35 ` John MacFarlane
[not found] ` <m2zglfjj1b.fsf-jF64zX8BO0+FqBokazbCQ6OPv3vYUT2dxr7GGTnW70NeoWH0uzbU5w@public.gmane.org>
2022-03-24 19:26 ` Hoàng-Ân Lê
[not found] ` <CAKY_PKtOFRs085OJCCaAqjHyjo7BPSstUojaxGqE8vC3HFNrhg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2022-03-25 2:30 ` John MacFarlane
[not found] ` <m2fsn6ix1n.fsf-jF64zX8BO0+FqBokazbCQ6OPv3vYUT2dxr7GGTnW70NeoWH0uzbU5w@public.gmane.org>
2022-03-25 9:38 ` William Lupton
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).