From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/22502 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Oscar Levin Newsgroups: gmane.text.pandoc Subject: Re: A writer for PreTeXt Date: Thu, 11 Apr 2019 06:12:44 -0700 (PDT) Message-ID: References: <9b82655a-3067-4696-8123-5b0b99496a70@googlegroups.com> <4b209782-0203-41f8-be61-707985d10afa@googlegroups.com> <008eebaf-2dd4-32c6-9d68-63fc99fa1e27@gmail.com> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_295_309871719.1554988364940" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="143777"; mail-complaints-to="usenet@blaine.gmane.org" To: pandoc-discuss Original-X-From: pandoc-discuss+bncBD3O3UV33AKBBTX2XTSQKGQEUSBK7OY-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Thu Apr 11 15:12:50 2019 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane.org Original-Received: from mail-ot1-f61.google.com ([209.85.210.61]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1hEZVZ-000bDL-C5 for gtp-pandoc-discuss@m.gmane.org; Thu, 11 Apr 2019 15:12:49 +0200 Original-Received: by mail-ot1-f61.google.com with SMTP id f11sf2851903otl.20 for ; Thu, 11 Apr 2019 06:12:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20161025; h=sender:date:from:to:message-id:in-reply-to:references:subject :mime-version:x-original-sender:reply-to:precedence:mailing-list :list-id:list-post:list-help:list-archive:list-subscribe :list-unsubscribe; bh=BbtOURFmL22VI3w87+WgXEDu5oZuiMc5AzZm+1Ailv8=; b=daIAdS7nqGd3WjIV4AuV50ckn8W5hq6YjkH1BvB3791TlXuSrdXVsukxnTFKZz1by5 hTlg+/W03hOlzk3d+xdHkgwpfG39d/Y7Ffy5fr44t2TG7lX3QA/WnXvhahVyivStSrCT nDnL1Qw+qgU0KrE61oZ9Qhe/8nYNh6XQhMC1erHE6peDJIAiOlUpAoVNN0Mq8CbdLN+3 /PptZIKM2F+burx4NI5yQ6laUo8kCE0SRvVFymaNsF7XLUoK8AHsikL0GqGElGsQkGAF neL0SoTN+6Ej5ehMjAqXLEVsS+sj9pEHNzLe6xJ90AMVa5qEJznxee0y9VqxYFbPNZbh EdFA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:message-id:in-reply-to:references:subject:mime-version :x-original-sender:reply-to:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-subscribe:list-unsubscribe; bh=BbtOURFmL22VI3w87+WgXEDu5oZuiMc5AzZm+1Ailv8=; b=Pm3zjdgTxTXwGfzwOgNlTi/VkU/DWkafoboUNGJGg1csXmidlUiPjt/FDMZE5gpDJY WQB8zHsaWrY0mwttEbVIeJ5VW7op/nI575kdAsam7f/YQTp/ljlcYRjfvvHLb9ur2N6h XadQRFHTCl2rUySvGa6ZN0G3nrp1ibUWB4nkuAR9KhJPDf/9sStzpIwhs9bhUGWB5Kg3 N4rViAFEC7x4Ao2OfiiCupR7yJiT7QGeXE5ZkuoiH5cOnD1Cm22UK4AShg56Op/RK0cf 3owbLXgSml/RJpGlQTa5WwQrfYW7n5dPB16+1OESwET7b11/0eS8nqSm7//B4DkDglvT nAaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=sender:x-gm-message-state:date:from:to:message-id:in-reply-to :references:subject:mime-version:x-original-sender:reply-to :precedence:mailing-list:list-id:x-spam-checked-in-group:list-post :list-help:list-archive:list-subscribe:list-unsubscribe; bh=BbtOURFmL22VI3w87+WgXEDu5oZuiMc5AzZm+1Ailv8=; b=bwYw7STfoDAABMad4CLDiyBfqbj87p4B+N7aGMi1RglAksn6GtGDHjy6+jTlsX4Saz IoUVRZfNl0LmPVc2RU2usWb9czhQu1IqW/yXdZA5V15YDTlyRGOG2h+C9M5BOz+pU0Iq zJzJ644EmfJOHQZaeEdoHw60whz36qq2X/T6Ifx47i1Jl1QhQzIG0SFrRKKejbB8weOQ lAJ3fh30aHwcpLlPuOBPmo8Y1oMLXU+YAINkbFEBlG6Duxht36VMT0EboXHLWeyuYu9G xx3o6IczY9t+qsS27VybzSsLNn7PieW8XUTbLuks4VPQIdErVyroIprzFpIMrrohVAEp /cig== Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: APjAAAUTKFqPZL95arVBX9cBKPLFtTG+J+EXBe5ISunXrfdqs2NZytKd 3NKA5mcl6RDhFFvgUXcruAs= X-Google-Smtp-Source: APXvYqwGD6sgvVs81YWXNRaAVmu5XipdKyWpDWeLsBUmKVyz+i1YmsedyOXDM4m7S3oMARKiePKPgg== X-Received: by 2002:a9d:694c:: with SMTP id p12mr33138561oto.242.1554988367016; Thu, 11 Apr 2019 06:12:47 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a9d:2021:: with SMTP id n30ls221376ota.4.gmail; Thu, 11 Apr 2019 06:12:46 -0700 (PDT) X-Received: by 2002:a05:6830:1153:: with SMTP id x19mr33638410otq.74.1554988365583; Thu, 11 Apr 2019 06:12:45 -0700 (PDT) In-Reply-To: <008eebaf-2dd4-32c6-9d68-63fc99fa1e27-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> X-Original-Sender: OscarLevin-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org Precedence: list Mailing-list: list pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org; contact pandoc-discuss+owners-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org List-ID: X-Google-Group-Id: 1007024079513 List-Post: , List-Help: , List-Archive: , List-Unsubscribe: , Xref: news.gmane.org gmane.text.pandoc:22502 Archived-At: ------=_Part_295_309871719.1554988364940 Content-Type: multipart/alternative; boundary="----=_Part_296_1370267258.1554988364940" ------=_Part_296_1370267258.1554988364940 Content-Type: text/plain; charset="UTF-8" Thanks. This sounds like it will be a big help. I'll give it a shot. Oscar. On Thursday, April 11, 2019 at 4:48:23 AM UTC-6, BP Jonsson wrote: > > You need to familiarize yourself with how different elements are > represnted in the Pandoc AST. In my experience the best way to do > that is not to read the documentation (althou8gh you want to do > that too of course[^1]) but to type examples of the kinds of > structures you want to work with in Markdown and study what they > look like in native and json output. A JSON prettyprinter which > adds spacing and indentation is a very good help. Start with > simple things like `[text]{#id .class1 .class2 attr1=val1 > attr2=val2}` and go in to more complicated/nested structures once > you understand them. > > To help me with visualizing the Lua objects I use the table > dumping function[^2] from the Penlight libraries[^3] enhanced by > the following custom function which makes a copy of (the > non-metatable parts of) the lua objects, adding a key for the > element type which otherwise is buried in the metatables: > > ````lua > local pl_pretty = require "pl.pretty" > > -- visualize a (tree of) Lua Pandoc elements > -- without destroying the originals > function showit (x) > if 'table' == type(x) then > local y = {} -- the "copy" > for k, v in pairs(x) do > y[k] = showit(v) -- expand recursively > end > -- show the tag from the metatable > if y._t then > -- if y._t already exists (it shouldn't) don't clobber it > y._t = { _t = y._t, t = x.t } > else > -- otherwise just assign the value of x.t from the > metatable to it > y._t = x.t > end > return y > else > return x > end > end > > function dumpit (x) > pl_pretty.dump(showit(x)) > end > ```` > > I have these living in my `~/.pandoc/init.lua` so that they are > always available. Saying `dumpit(element)` will then pretty-print > the element structure to stderr. > > [^1]: Above all the Lua filter documentation > > but also the element type definitions (which were all we had > before the advent of lua filters. > > < > http://hackage.haskell.org/package/pandoc-types-1.17.5.4/docs/Text-Pandoc-Definition.html#t:Pandoc> > > > (may not be the latest version). > > [^2]: > > > [^3]: > > Den 2019-04-11 kl. 06:43, skrev Oscar Levin: > > Hi John, > > > > Thanks for the hint. I've been trying to wrap my head around all this > > (filters and their relation to custom writers, plus the logical > structure > > of how the writer "walks" the AST, if that is even the right way of > > thinking about it), so far with little luck. Maybe I'm stuck in the > > mindset of how xslt processes xml. I'll keep hacking away. > > > > I found an old custom JATS writer, but that seems abandoned (since there > is > > regular writer for it now): there sections were handled by putting > >
where headers go, and then removing the first > >
and adding one at the end of the document. That approach > would > > not work for me, since I would like . I assume the > > hierarchicalize would allow for this? So far I've been unable to figure > it > > out though. > > > > While I keep thinking about this, here is a little more about PreTeXt. > I'm > > not the author of it, but as I see it, the big advantage over docbook is > > math support (it was previously called MathBook XML). I like it for my > > textbooks because it allows for theorems/proofs, and > exercises/solutions, > > and so on. The HTML output you get (via xslt) can put solutions or > proofs > > in "knowls": a link you click on that expands a box with the content. > > Cross references also work this way (if you reference an earlier > theorem, > > clicking on the link opens a box with the statement of the theorem, for > > example). You can also process the xml into LaTeX for pdf output. > > > > In terms of users, I can only speculate on lower bounds: the "gallery" > of > > textbook projects on the PreTeXt website lists 33 completed books, and I > > know of at least a dozen more books currently under development. The > > github repository (https://github.com/rbeezer/mathbook) has been forked > 82 > > times. I'm not sure what you would consider a reasonable number of > users; > > I would like to see the number of users grow, and I see having an easy > way > > to get people started by converting a latex or word document into > PreTeXt > > as a good step in that direction. > > > > Thanks, > > Oscar. > > > > On Friday, April 5, 2019 at 11:27:19 AM UTC-6, John MacFarlane wrote: > >> > >> > >> To group content into sections, you should be able to > >> use the function hierarchicalize from pandoc.utils: > >> > >> https://pandoc.org/lua-filters.html#utils-hierarchicalize > >> > >> This wraps the function that the Haskell writers use. > >> > >> A regular writer might be considered, but I'd like to > >> know more about PreTeXt. What is the advantage over > >> using, say, plain DocBook? How many users are there? > >> > >> Oscar Levin writes: > >> > >>> I am working on a custom (lua) writer for PreTeXt ( > >> https://pretextbook.org/), > >>> which I use to write open math textbooks. In terms of syntax, PreTeXt > >> is > >>> xml and is very similar to docbook, so a lot of what I need was > easily > >>> modified from the sample.lau custom writer. > >>> > >>> What I haven't been able to figure out is how to wrap sections in > >>
> >>> tags. That is, in the built in docbook writer, if you have a header, > I > >>> think it creates a section with a title around the appropriate > content. > >> Is > >>> there any way to do this with a custom lua writer? > >>> > >>> Perhaps a better approach would be to contribute a new built in writer > >> by > >>> modifying the docbook writer. I think there would be a good number of > >>> people who would find this writer useful. Would such a contribution > be > >>> considered? > >>> > >>> Thanks, > >>> Oscar. > >>> > >> > > > > -- 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/c945d963-d067-4fe0-804d-280dbbed9b91%40googlegroups.com. For more options, visit https://groups.google.com/d/optout. ------=_Part_296_1370267258.1554988364940 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Thanks.=C2=A0 This sounds like it will be a big help.=C2= =A0 I'll give it a shot.

Oscar.

On Thursday, = April 11, 2019 at 4:48:23 AM UTC-6, BP Jonsson wrote:
You need to familiarize yourself with how different = elements are=20
represnted in the Pandoc AST. =C2=A0In my experience the best way to do= =20
that is not to read the documentation (althou8gh you want to do=20
that too of course[^1]) but to type examples of the kinds of=20
structures you want to work with in Markdown and study what they=20
look like in native and json output. =C2=A0A JSON prettyprinter which= =20
adds spacing and indentation is a very good help. =C2=A0Start with=20
simple things like `[text]{#id .class1 .class2 attr1=3Dval1=20
attr2=3Dval2}` and go in to more complicated/nested structures once=20
you understand them.

To help me with visualizing the Lua objects I use the table=20
dumping function[^2] from the Penlight libraries[^3] enhanced by=20
the following custom function which makes a copy of (the=20
non-metatable parts of) the lua objects, adding a key for the=20
element type which otherwise is buried in the metatables:

````lua
local pl_pretty =3D require "pl.pretty"

-- visualize a (tree of) Lua Pandoc elements
-- without destroying the originals
function showit (x)
=C2=A0 =C2=A0 =C2=A0if 'table' =3D=3D type(x) then
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0local y =3D {} -- the "copy"= ;
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0for k, v in pairs(x) do
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0y[k] =3D showit(v) -- e= xpand recursively
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0end
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0-- show the tag from the metatable
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0if y._t then
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0-- if y._t already exis= ts (it shouldn't) don't clobber it
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0y._t =3D { _t =3D y._t,= t =3D x.t }
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0else
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0-- otherwise just assig= n the value of x.t from the=20
metatable to it
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0y._t =3D x.t
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0end
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return y
=C2=A0 =C2=A0 =C2=A0else
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0return x
=C2=A0 =C2=A0 =C2=A0end
end

function dumpit (x)
=C2=A0 =C2=A0 =C2=A0pl_pretty.dump(showit(x))
end
````

I have these living in my `~/.pandoc/init.lua` so that they are=20
always available. =C2=A0Saying `dumpit(element)` will then pretty-print= =20
the element structure to stderr.

[^1]: Above all the Lua filter documentation
=C2=A0 =C2=A0 =C2=A0<http://pandoc.org/lua-filters.html#lua-t= ype-reference>
=C2=A0 =C2=A0 =C2=A0but also the element type definitions (which were a= ll we had=20
before the advent of lua filters.
=C2=A0
<http://hackage.haskell.org/package/pandoc-types-1.17.5.4/docs/Text-Pandoc-Definition.html#t:Pandoc>=20

=C2=A0 =C2=A0 =C2=A0(may not be the latest version).

[^2]:=20
<http://stevedon= ovan.github.io/Penlight/api/libraries/pl.pretty.html>

[^3]: <https://github.com/= stevedonovan/Penlight>

Den 2019-04-11 kl. 06:43, skrev Oscar Levin:
> Hi John,
>=20
> Thanks for the hint. =C2=A0I've been trying to wrap my head ar= ound all this
> (filters and their relation to custom writers, plus the logical st= ructure
> of how the writer "walks" the AST, if that is even the r= ight way of
> thinking about it), so far with little luck. =C2=A0Maybe I'm s= tuck in the
> mindset of how xslt processes xml. =C2=A0I'll keep hacking awa= y.
>=20
> I found an old custom JATS writer, but that seems abandoned (since= there is
> regular writer for it now): there sections were handled by putting
> </section><section> where headers go, and then removin= g the first
> </section> and adding one at the end of the document. =C2=A0= That approach would
> not work for me, since I would like <subsection>. =C2=A0I as= sume the
> hierarchicalize would allow for this? =C2=A0So far I've been u= nable to figure it
> out though.
>=20
> While I keep thinking about this, here is a little more about PreT= eXt. =C2=A0I'm
> not the author of it, but as I see it, the big advantage over docb= ook is
> math support (it was previously called MathBook XML). =C2=A0I like= it for my
> textbooks because it allows for theorems/proofs, and exercises/sol= utions,
> and so on. =C2=A0The HTML output you get (via xslt) can put soluti= ons or proofs
> in "knowls": a link you click on that expands a box with= the content.
> Cross references also work this way (if you reference an earlier t= heorem,
> clicking on the link opens a box with the statement of the theorem= , for
> example). =C2=A0You can also process the xml into LaTeX for pdf ou= tput.
>=20
> In terms of users, I can only speculate on lower bounds: the "= ;gallery" of
> textbook projects on the PreTeXt website lists 33 completed books,= and I
> know of at least a dozen more books currently under development. = =C2=A0The
> github repository (https://github.com/rbe= ezer/mathbook) has been forked 82
> times. =C2=A0I'm not sure what you would consider a reasonable= number of users;
> I would like to see the number of users grow, and I see having an = easy way
> to get people started by converting a latex or word document into = PreTeXt
> as a good step in that direction.
>=20
> Thanks,
> Oscar.
>=20
> On Friday, April 5, 2019 at 11:27:19 AM UTC-6, John MacFarlane wro= te:
>>
>>
>> To group content into sections, you should be able to
>> use the function hierarchicalize from pandoc.utils:
>>
>> https://pandoc.org/lua-filters.html#utils= -hierarchicalize
>>
>> This wraps the function that the Haskell writers use.
>>
>> A regular writer might be considered, but I'd like to
>> know more about PreTeXt. =C2=A0What is the advantage over
>> using, say, plain DocBook? =C2=A0How many users are there?
>>
>> Oscar Levin writes:
>>
>>> I am working on a custom (lua) writer for PreTeXt (
>> https://pretextbook.org/),
>>> which I use to write open math textbooks. =C2=A0In terms o= f syntax, PreTeXt
>> is
>>> xml and =C2=A0is very similar to docbook, so a lot of what= I need was easily
>>> modified from the sample.lau custom writer.
>>>
>>> What I haven't been able to figure out is how to wrap = sections in
>> <section>
>>> tags. =C2=A0That is, in the built in docbook writer, if yo= u have a header, I
>>> think it creates a section with a title around the appropr= iate content.
>> =C2=A0 Is
>>> there any way to do this with a custom lua writer?
>>>
>>> Perhaps a better approach would be to contribute a new bui= lt in writer
>> by
>>> modifying the docbook writer. =C2=A0I think there would be= a good number of
>>> people who would find this writer useful. =C2=A0Would such= a contribution be
>>> considered?
>>>
>>> Thanks,
>>> Oscar.
>>>
>>
>=20

--
You received this message because you are subscribed to the Google Groups &= quot;pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an e= mail to pand= oc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To post to this group, send email to pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org.
To view this discussion on the web visit https://groups.google.com/d/= msgid/pandoc-discuss/c945d963-d067-4fe0-804d-280dbbed9b91%40googlegroups.co= m.
For more options, visit http= s://groups.google.com/d/optout.
------=_Part_296_1370267258.1554988364940-- ------=_Part_295_309871719.1554988364940--