From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/31452 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Bastien DUMONT Newsgroups: gmane.text.pandoc Subject: Re: Fw: Fixing lua filter to number paragraphs Date: Sat, 24 Sep 2022 05:39:08 +0000 Message-ID: References: <78BBgUlgdEJOaNOIxhfkTKPgf07yZREVfvlbeq1kqYQ59CCPSpaXEX4T_806rUzuPjbb5aIvpmynEu04PsBHsJTnWtkNNiG5dZQYfDGsO0Y=@proton.me> Reply-To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12967"; mail-complaints-to="usenet@ciao.gmane.io" To: 'Mark Johnno' via pandoc-discuss Original-X-From: pandoc-discuss+bncBDCINCES2QJRBWNQXKMQMGQE5A6HSXA-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Sat Sep 24 07:40:46 2022 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-wm1-f56.google.com ([209.85.128.56]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1obxu9-0003EL-Ld for gtp-pandoc-discuss@m.gmane-mx.org; Sat, 24 Sep 2022 07:40:45 +0200 Original-Received: by mail-wm1-f56.google.com with SMTP id d5-20020a05600c34c500b003b4fb42ccdesf3734011wmq.8 for ; Fri, 23 Sep 2022 22:40:45 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1663998045; cv=pass; d=google.com; s=arc-20160816; b=JbJhPSyetsBJJnmiXdn1RSrDwYKIUHZi/v4NCHSNp1fGbyaJCADrsQSkZMsJwda3v5 8OzN7wyVmQUB9+6HmhvI0D5A5sVhyiP/Q668mqB7glKNVYn7yFTy4qxmPu6sx4Cy50JM paSuHmHY/16LBMv/koFl96J7SgeJNDvdQsxrpsW0CsVeAr80VTMCbqyf4u9KUqG6OPyg D032Vxs3Pq6aZe7KdiomUR9HeEXV/CRKO5c+JSlZibt0pECu4qzpmKcP3tu92t/ngEcq /5eTYvDncp4DrDQDNnFz4+zbl32BL7Kx0QRpKtk3XHFgVO1J66DJmjlqpxj4bkT8QG2J KR6g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:reply-to:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:to:from:date:sender:dkim-signature; bh=XULdnsxAKjq1SQ5/pTEC1ZEzNPJAR5IwvAxW2vvjXNM=; b=u1RYVW17TXmh7JnIO2HO23/UAQt/c5S457YL+960ovCejDKTHXMsHyYfBROf6Alp3b 2/Nr0YTWnoebDTc0fmubfqi0yWaPcnIJAujTV92DDy6esaLjIsu+2wH9gd4Zi/9KJvbM gjWJdS5tvOT4WRq9UGx+KypW2ZfDVfx0DONaF9K5hmhOrzJPJj6yqzbNJXi6jrpDphet 7P3SHTpT9REruIuxJklgokA1PGZbrRK+SXwuIpPr+PU7ypaYGM78711rRrrnkcNJl+Aj 2j+P9Wggazgz1lnBm/GntU2OaWx5QQ3HTcFUT3SYUvT1xMCa/evlj9C4jIvlQaNiPE1O cNcQ== ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@posteo.net header.s=2017 header.b=qozmj7Nd; spf=pass (google.com: domain of bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org designates 185.67.36.66 as permitted sender) smtp.mailfrom=bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=posteo.net DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=20210112; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :list-id:mailing-list:precedence:reply-to :x-original-authentication-results:x-original-sender:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:to:from:date:sender:from:to:cc :subject:date; bh=XULdnsxAKjq1SQ5/pTEC1ZEzNPJAR5IwvAxW2vvjXNM=; b=N3dld05SoyyfLLGN2xO95oa3n60v7HYbd0zM1UpueAwijmSgXrnMGfMWSF77TV6qax 0MJF8Ou0v7gdXvYA/yrOTtr8SqBtvDk5eWbdv4jmcybB2h0OSszzLiqTwrwzRcfmuMMJ zQwvid8QCIVM9F0MgOVp74zKn2p3F5DS8s+zy3NqRPMybEsQniGk780SQAH0jQctES5X tbcjD51FyPnxh7O440y8rlc7pGv0n2j+ClDWN7zWxkzLp7ybWnDqxS49z1NfNBFgwuok LK12zHfvqEhWDxIhG3cGFNrx3339+EIIaEr8DKmvFOKxhyPpEjLbbEEtAZYU0kmaA X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=list-unsubscribe:list-subscribe:list-archive:list-help:list-post :x-spam-checked-in-group:list-id:mailing-list:precedence:reply-to :x-original-authentication-results:x-original-sender:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:to:from:date:x-gm-message-state :sender:from:to:cc:subject:date; bh=XULdnsxAKjq1SQ5/pTEC1ZEzNPJAR5IwvAxW2vvjXNM=; b=j3xqOpIcvcyEZ0RTunRyuBFNFcRKYo4H5Fhn/zAuM5XKDlDFUBZ4Cktu8VMamTeQM2 EoqnvF8LTh4A6hVdSMX83/sZeHmPu8J0f/cyYys66Erf2chtsDsJRbZ/A72k/wvsoQN/ ZyQ6TuMjQOtzrhoGoad1Y9dDGIPUArgiOmQqxuIgHpPqci5JvauRnt9SHB4MFZNmE8mQ /r6C1lzKWuzM0RA47EU/CpvNF4oW/PnfsXPOwlzzAgo6W+YseVWboetulZArXXgWtLjW Ri+sJXKd/YDwbrB2qIxp Original-Sender: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org X-Gm-Message-State: ACrzQf3g++GI+DD38Xk76lJCuswcMqn/i+TzmsG5PuQttJxQAQaGv2eG /mKQpWu8unevK2r28Vd9xOM= X-Google-Smtp-Source: AMsMyM7LY9Q2y997p68vjVnYyVyW7IU0YgGdbKW5qih965dX4hikFfAgh2VMMD6nKLfroPn6chhmMw== X-Received: by 2002:a5d:628e:0:b0:228:6961:aa6f with SMTP id k14-20020a5d628e000000b002286961aa6fmr7490762wru.36.1663998045227; Fri, 23 Sep 2022 22:40:45 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:a05:600c:268f:b0:3b4:62fa:43a7 with SMTP id 15-20020a05600c268f00b003b462fa43a7ls2197627wmt.3.-pod-control-gmail; Fri, 23 Sep 2022 22:40:40 -0700 (PDT) X-Received: by 2002:a1c:4b0d:0:b0:3b4:76ae:f7a5 with SMTP id y13-20020a1c4b0d000000b003b476aef7a5mr8396575wma.23.1663998040651; Fri, 23 Sep 2022 22:40:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663998040; cv=none; d=google.com; s=arc-20160816; b=qFC16ehi61/t5q4p4WM+KjZ9r2lOmH8OaFZLHxRWG4Z31pR1qAA9m9dcvgPL07fyD3 E6FgUdjiK9ktn1P2z64PZo4EuI4Ud9aSZ71bnsbum1/6gE8ymiPqSRvzvpxQGxauD7No dcJ5UnWsZL7JvQPt8MWpgI8uVxoVm12dymMdXmUj0IExTneNmE1e0cgKazLm+UVKn+dZ WKVmvyaaWV2bnmM/c8D4RGtICposKE2NtldMszG5/Ar+0I2eb4ODAcTHZID9OufW9SDD 3x/nWKOCoG96OnNOL22e4NKd5VoiH7wv5odIwDZEgKxzG7uH2Xu4SwmTMMV1/fsBmc8K Me9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:to:from:date :dkim-signature; bh=BmRzEtKSwoQ9mXFszk03T+b70XqHnMlNr+XH0NYrhzM=; b=UgXUjjFi8Kkk9gkbCaz7/1gYX+ncIXIwn7f8z5gvbG8+gUppp2n14C2pHLRzri2VfP bT9Pfvov21Ly9keE0MPV5a5jGaBndsvFn/2hyQuY+VJMZATG8qmceTGxAOMM6+0ZNMDS 1rQz5S1pKNbTe4Oh4DhRHKxir+O7LWlYr/v1qeay4Rvm8RZsflXvM5cVmtwP6eP/WqN8 aETXinyfo024cCIYmStl6F1AvbwH7R29scLqx4jRxdd+on8fislA1KrLOKItA/g7u04E GbDLfQlXXSeeHlfOaapxQvHSJQEniq+aJwwoetuR+iVruYQmLnEWkShLi/1AfoN0uzI9 2J3A== ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@posteo.net header.s=2017 header.b=qozmj7Nd; spf=pass (google.com: domain of bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org designates 185.67.36.66 as permitted sender) smtp.mailfrom=bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=posteo.net Original-Received: from mout02.posteo.de (mout02.posteo.de. [185.67.36.66]) by gmr-mx.google.com with ESMTPS id az14-20020a05600c600e00b003b499f88f7esi124315wmb.1.2022.09.23.22.40.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Sep 2022 22:40:40 -0700 (PDT) Received-SPF: pass (google.com: domain of bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org designates 185.67.36.66 as permitted sender) client-ip=185.67.36.66; Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 4F7E2240124 for ; Sat, 24 Sep 2022 07:40:40 +0200 (CEST) Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4MZHtH5s2kz9rxD for ; Sat, 24 Sep 2022 07:40:39 +0200 (CEST) Content-Disposition: inline In-Reply-To: X-Original-Sender: bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@posteo.net header.s=2017 header.b=qozmj7Nd; spf=pass (google.com: domain of bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org designates 185.67.36.66 as permitted sender) smtp.mailfrom=bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=posteo.net 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.io gmane.text.pandoc:31452 Archived-At: The error means that the command \color is not defined, i.e. the package th= at defines it is not loaded. It should be fixed by adding this after addTex= Preamble("\\reversemarginpar"): addTexPreamble("\\usepackage{\\color}") Le Friday 23 September 2022 =C3=A0 11:09:42PM, 'Mark Johnno' via pandoc-dis= cuss a =C3=A9crit : > Hi, I have been using a lua filter for a few months with no issue, howeve= r, for the last few days, I've not been able to produce a PDF. I can't find= hints online. I am hoping someone can help me. > =20 > That is the error message I get: > =20 > ! Undefined control sequence. > ... \hspace {\z@ }\ignorespaces \color > =20 > {lightgray}\tiny {[1]}\end... > l.72 \paragraphnumber{[1]} > =20 > I had some error messages in the past, usually due to missing squared bra= ckets which I resolved by using --trace to check where parsing was slowing = down (that is where the brackets were missing), but this time --trace does = not provide any hints. > =20 > I can convert the document from .md to .pdf (without the filter); that is= the command I use: >=20 > $ pandoc file.md --pdf-engine=3Dxelatex -o file.pdf >=20 > ...but when I add count-para.lua filter: > =20 > $ pandoc file.md --pdf-engine=3Dxelatex --lua-filter=3Dcount-para.lua -o = file.pdf > =20 > I get the error message mentioned above. > =20 > I also tried with another document. I get the same error message. > =20 > I tried contacting the author of the filter, in vain. > =20 > Do you have a hint about how I could troubleshoot or fix this issue? > =20 > Does the filter need to be updated? > =20 > $ pandoc -v > pandoc 2.5 > Compiled with pandoc-types 1.17.5.4, texmath 0.11.2.2, skylighting 0.7.7 > =20 > I use Trisquel GNU/Linux 10.0.1. > =20 > This is the filter: >=20 > --[[ > Make all 'regular' paragraphs into a div and assign a numeric ID > Format this number in the margin > Copyright =C2=A9 2021 Michael Cysouw=20 > Permission to use, copy, modify, and/or distribute this software for any > purpose with or without fee is hereby granted, provided that the above > copyright notice and this permission notice appear in all copies. > THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES > WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF > MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR > ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES > WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN > ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF > OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. > ]] >=20 > local count =3D 0 > local chapter =3D 0 > local indexUserID =3D {} >=20 > ------------------------------ > -- Options with default values > ------------------------------ >=20 > local resetAtChapter =3D false > local enclosing =3D "[]" > local chapterSep =3D "." > local refName =3D "paragraph " > local addPageNr =3D true >=20 > function getUserSettings (meta) >=20 > if meta.resetAtChapter ~=3D nil then > resetAtChapter =3D meta.resetAtChapter > end >=20 > if meta.enclosing ~=3D nil then > enclosing =3D pandoc.utils.stringify(meta.enclosing) > end >=20 > if meta.chapterSep ~=3D nil then > chapterSep =3D pandoc.utils.stringify(meta.chapterSep) > end >=20 > if meta.refName ~=3D nil then > refName =3D pandoc.utils.stringify(meta.refName) > if FORMAT:match "latex" then > if refName =3D=3D "#" then refName =3D "\\#" end > end > end >=20 > if meta.addPageNr ~=3D nil then > addPageNr =3D meta.addPageNr > end >=20 > end >=20 > ------------------------ > -- Add global formatting > ------------------------ >=20 > function addFormatting (meta) >=20 > local tmp =3D pandoc.MetaList{meta['header-includes']} > if meta['header-includes'] ~=3D nil then > tmp =3D meta['header-includes'] > end > =20 > if FORMAT:match "html" then > local css =3D [[=20 > > > ]] > tmp[#tmp+1] =3D pandoc.MetaBlocks(pandoc.RawBlock("html", css)) > end > =20 > function addTexPreamble (tex) > tmp[#tmp+1] =3D pandoc.MetaBlocks(pandoc.RawBlock("tex", tex)) > end >=20 > if FORMAT:match "latex" then > addTexPreamble("\\usepackage{marginnote}") > addTexPreamble("\\reversemarginpar") > addTexPreamble("\\newcommand{\\paragraphnumber}[1]{\\marginnote{\\col= or{lightgray}\\tiny{#1}}[0pt]}") > end > =20 > meta['header-includes'] =3D tmp > return(meta) > end >=20 > ------------------------- > -- count Para and add Div > ------------------------- >=20 > function countPara (doc) >=20 > for i=3D1,#doc.blocks do >=20 > -- optionally reset counter > if doc.blocks[i].tag =3D=3D "Header" > and doc.blocks[i].level =3D=3D 1 > and doc.blocks[i].classes[1] ~=3D "unnumbered"=20 > and resetAtChapter > then > chapter =3D chapter + 1 > count =3D 0 > end >=20 > -- get Para, but not if there is an Image inside > if doc.blocks[i].tag =3D=3D "Para" > and doc.blocks[i].content[1].tag ~=3D "Image" > then >=20 > -- count paragraphs > count =3D count + 1=09 > local ID =3D count > if resetAtChapter then=20 > ID =3D chapter..chapterSep..count=20 > end >=20 > -- format number to insert > local number =3D ID > if enclosing:len() =3D=3D 1 then > number =3D enclosing..ID..enclosing > else > number =3D enclosing:sub(1,1)..ID..enclosing:sub(2,2) > end >=20 > -- check for user-inserted ids at the start of the paragraph > local firstElem =3D pandoc.utils.stringify(doc.blocks[i].content[1]= ) > local userID =3D firstElem:match("{#(.*)}") > if userID ~=3D nil then > -- add to index > indexUserID[userID] =3D ID > -- remove reference from text > table.remove(doc.blocks[i].content, 1) > -- remove possible space > if doc.blocks[i].content[1].tag =3D=3D "Space" then > table.remove(doc.blocks[i].content, 1) > end > end >=20 > -- insert number > if FORMAT:match "latex" then > -- use marginnote for formatting number in margin > local texCount =3D "\\paragraphnumber{"..number.."}" > if userID ~=3D nil then > -- add target for link to the number > texCount =3D "\\hypertarget{"..userID.."}{\n"..texCount.."\\lab= el{"..userID.."}}" > end > table.insert(doc.blocks[i].content, 1, pandoc.RawInline("tex", te= xCount)) > else > table.insert(doc.blocks[i].content, 1, pandoc.Space()) > table.insert(doc.blocks[i].content, 1, pandoc.Span(number, pandoc= .Attr(ID, {"paragraph-number"}))) > end >=20 > end > end > return doc > end >=20 > ------------------------------ > -- set in-text cross-references > ------------------------------ >=20 > function setCrossRefs (cite) >=20 > local userID =3D cite.citations[1].id > local paraID =3D indexUserID[userID]=20 >=20 > -- ignore other "cite" elements > if paraID ~=3D nil then > =20 > -- make in-document cross-references > if FORMAT:match "latex" then >=20 > local texInsert =3D refName.."\\hyperlink{"..userID.."}{"..paraID..= "}" > if addPageNr then > texInsert =3D texInsert.." on page~\\pageref{"..userID.."}" > end > return pandoc.RawInline("tex", texInsert) >=20 > else > return pandoc.Link(refName..paraID, "#"..paraID) > end >=20 > end > end >=20 > -------------------- > -- basic Pandoc loop > -------------------- >=20 > return { > { Meta =3D addFormatting }, > { Meta =3D getUserSettings }, > { Pandoc =3D countPara }, > { Cite =3D setCrossRefs } > } >=20 > --=20 > 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/msgi= d/pandoc-discuss/e2suTdCtcLJ3u0PBmkSX9YRRukwnvuWJPhOFU1iL8lR84w_f8f9j1UrjpH= EW_3oHRO5aC_mDpkazLs5dfMXA1EKkXvf4eZs3_tgIXsFq1uU%3D%40proton.me. --=20 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 e= mail 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/Yy6X/FXIPVN1zij3%40localhost.