From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.text.pandoc/31450 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: "'Mark Johnno' via pandoc-discuss" Newsgroups: gmane.text.pandoc Subject: Fw: Fixing lua filter to number paragraphs Date: Fri, 23 Sep 2022 23:09:42 +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="21286"; mail-complaints-to="usenet@ciao.gmane.io" To: "pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org" Original-X-From: pandoc-discuss+bncBCIZTRNTTYMBBP7ZXCMQMGQETPVQQLI-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Sat Sep 24 01:09:56 2022 Return-path: Envelope-to: gtp-pandoc-discuss@m.gmane-mx.org Original-Received: from mail-lf1-f59.google.com ([209.85.167.59]) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1obrnw-0005NG-FP for gtp-pandoc-discuss@m.gmane-mx.org; Sat, 24 Sep 2022 01:09:56 +0200 Original-Received: by mail-lf1-f59.google.com with SMTP id q16-20020a05651232b000b0049787a1b6b0sf462922lfe.19 for ; Fri, 23 Sep 2022 16:09:56 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1663974596; cv=pass; d=google.com; s=arc-20160816; b=G35cF2tmo7udXLen39etB2r2CWeP33NqlbZLE/hfax0yZBxSnmyIrOH/KiFPv3epGR 3ca+sX2rm8t4kbj6544593GA9/sHk53//Fu+kNCWYfa0zKlwcj+0V20l5IKuOfeHMkaV ayk3OBhEgd6++zXYdBOXGCthh5Ox6lFeCbBLBikwkNUYNO6SerRKM+z7FqQIRXVlnpmG jgR7C3iBdb6ofDOinKq74Nf91bxfV2TfAzPg+/VOklOvvfTatDYaOempKrcQBPnvTK5a 5xI18OwHmlQnNZQBXbIuF3UwoaesK2exwhp0tEbiv72A1I1ud4L6RJxezuDx1DWa4fsP jJXw== 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:content-transfer-encoding :mime-version:feedback-id:references:in-reply-to:message-id:subject :from:to:date:dkim-signature; bh=QN/HJkQDTJLf11U01Ae379hbNPEuXXNiKGjKlqU+aHE=; b=WISZGURA0BhVsyE5ljyEBGtXPspfWVwJaVcCpAjyfRUCwgTGlOgDa007pPxvAcKVyf Jid2zerrfkybA5+DZt36Qa1qMwFiQ6cfQ3OpO+dlN4f7uPT38ffVMjLl2suJIPe0+Fd9 ovU1y3CtZuK67nUk6bCPAUy3p12wODQlmJMZGtFhzkt4dNATa3lvSqDq/2IFP+W9CkpR g8VXvWfgchc2q5/i/hnUkgAl0o4fwRZLA3yFAwkScvMr2+ABPqy2UhlbRVL6Oq8J2o0W qBaQHHgiLHNHXNiqm7adpJW6k5wikle3nGcEUtgWJNhXG4N0QK/t6IsSccmshSNzkWiA 7dVQ== ARC-Authentication-Results: i=2; gmr-mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=LH45ERQk; spf=pass (google.com: domain of lua8ds-6EK1v4hiKcSzQB+pC5nmwQ@public.gmane.org designates 185.70.40.27 as permitted sender) smtp.mailfrom=lua8ds-6EK1v4hiKcSzQB+pC5nmwQ@public.gmane.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me 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 :content-transfer-encoding:mime-version:feedback-id:references :in-reply-to:message-id:subject:from:to:date:from:to:cc:subject:date; bh=QN/HJkQDTJLf11U01Ae379hbNPEuXXNiKGjKlqU+aHE=; b=fnpPC2nw8pggcdryb1rUjuZfvXokdW2DTGH0nmBrO1Oz2XgvvqZLqfvwYcwVmA7ck/ XY2ls9oS4M/sXDpl/lueqqzkJ5+P6zKVSQMH2RTm8QDnRVdBJL7Y90LSNztUT25QDtv/ XFpgG34x8+XZ1/Iwd2sQJbeqEcRbVyQo57M4CvORnppIYq3DDCMkG4sfxJA/HxxDudun xel+GwzLIZg3OT5Z99QUdrvO///Zm2fYz/SCu3khwEwovwZ60Mepobtvid5s2gs+dNeO xDJs8OCK6LqNw0CyYKCuZit/cYPky0DTsKjJkiPEEnT38rmmTmUcJ9PtIsYhiHBhDnYi kAVg== 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 :content-transfer-encoding:mime-version:feedback-id:references :in-reply-to:message-id:subject:from:to:date:x-gm-message-state:from :to:cc:subject:date; bh=QN/HJkQDTJLf11U01Ae379hbNPEuXXNiKGjKlqU+aHE=; b=juBE6XcQTXlhVkxZDf1JJy8+SlxqfmLltLl771xUaaLiKI7/uGldcXa8Vdq3ox3o7C J8/mBVb+sOOvs7kgrCmhw4NKsEeFScKW+Q0JJamhlpdk4XuUBKjHOUsCOmRfBPoqiXPs FkUEqtSxjRh11iQUQwcyLIJ/+kTEN0PhjE3A36OAV2STIMPuVgJRP3DAe78J6zYd+QQR CI52buNg0BSjJXNdCPH/I6CJXQTr7OWWRRQTnXHJve78I7i/oKdYAixIn7/G0U6CzuD/ cy34VBkQJJPh5sI97WyGh+ugRDt6lfLDLcb X-Gm-Message-State: ACrzQf3rUIITFPlqxozDtQwHqE3fxF2Mk6W2iTXlP7c49V0rC+P9+xUZ Y9sXOZcPsNCW8oHc6uQZWPQ= X-Google-Smtp-Source: AMsMyM6zEUGSXz4YsO5gpT7fqFmTMFOxAwWu3Ub6J3nHwRf0xOS+5dqO1MW7KCRoJ8e5xb+wipKVdQ== X-Received: by 2002:ac2:5208:0:b0:497:aadf:eac7 with SMTP id a8-20020ac25208000000b00497aadfeac7mr4359845lfl.315.1663974595831; Fri, 23 Sep 2022 16:09:55 -0700 (PDT) X-BeenThere: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Original-Received: by 2002:ac2:58ed:0:b0:494:6c7d:cf65 with SMTP id v13-20020ac258ed000000b004946c7dcf65ls1050003lfo.2.-pod-prod-gmail; Fri, 23 Sep 2022 16:09:51 -0700 (PDT) X-Received: by 2002:a05:6512:1285:b0:499:af40:afaa with SMTP id u5-20020a056512128500b00499af40afaamr4075066lfs.540.1663974590952; Fri, 23 Sep 2022 16:09:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663974590; cv=none; d=google.com; s=arc-20160816; b=DuIfP7yYjYZAglJK00B6wkATAziXvYnaM8L8FTwwLYIkqi4DqxADJYURR1nki5Hrae vpeWeo3ii530zJAiD48XGv6qFl8L9vGgedQCI1Il4AOQyQ1pysbO5f/UakdlqyfOzpu4 VNEwi5CEEujmjAVFHQnS/dzfL42Egp8ZrJj7YDomtNT2uwTW0BOcEoyZcymxfBW8XxHR Fypr+mR1YWfrI9ImbCPQR+Jdm6YKseALv7RPQtcHGaRZfanF66oMlcN1Nr3A2cxhZzWl YXZnFmdYeoBk28K5ycetvSxS4AI2EsyktuSYNSghbHZfUmPGtSwJV2aCjJLEKhK1pCvR SicQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:feedback-id:references :in-reply-to:message-id:subject:from:to:dkim-signature:date; bh=8bAflLARBklGq7uc4QDHP9Abb6xd5pOyUbX3Kt7dKp0=; b=aTc2WXVaaQsHm6T8QLWsqpSpqdF1pBOziW/G24EEHCFv5VZFEZn+ivAsI/PuFGwWPX jpGVfpTf7n+58WmItAS++ex+CxYEKpTgt+sKwcMStsW6w1KULHmoqmdCgHAyLpTFMz3x X1o5T8G6HceRMN4XrVavrWk8rE9moHJReVEVGcbzdyskrreexw1b5t6ZusVKgzXD9n4y gtJNOdlsQOSCu3xu77mdVqL37PAxsi86mbDFBq/uzZDkvQSY/BC5/FdbLNXkeau9EnCY pxTwCrRbTBYRDe58h48nbNo5q9TC2tAgAvfm0ra/zejRuX13TasoHsL0LpBpIfV4omHy hRRg== ARC-Authentication-Results: i=1; gmr-mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=LH45ERQk; spf=pass (google.com: domain of lua8ds-6EK1v4hiKcSzQB+pC5nmwQ@public.gmane.org designates 185.70.40.27 as permitted sender) smtp.mailfrom=lua8ds-6EK1v4hiKcSzQB+pC5nmwQ@public.gmane.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Original-Received: from mail-4027.protonmail.ch (mail-4027.protonmail.ch. [185.70.40.27]) by gmr-mx.google.com with ESMTPS id v7-20020a056512348700b00492ce810d43si277232lfr.10.2022.09.23.16.09.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Sep 2022 16:09:50 -0700 (PDT) Received-SPF: pass (google.com: domain of lua8ds-6EK1v4hiKcSzQB+pC5nmwQ@public.gmane.org designates 185.70.40.27 as permitted sender) client-ip=185.70.40.27; In-Reply-To: <78BBgUlgdEJOaNOIxhfkTKPgf07yZREVfvlbeq1kqYQ59CCPSpaXEX4T_806rUzuPjbb5aIvpmynEu04PsBHsJTnWtkNNiG5dZQYfDGsO0Y=@proton.me> Feedback-ID: 55774685:user:proton X-Original-Sender: lua8ds-6EK1v4hiKcSzQB+pC5nmwQ@public.gmane.org X-Original-Authentication-Results: gmr-mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b=LH45ERQk; spf=pass (google.com: domain of lua8ds-6EK1v4hiKcSzQB+pC5nmwQ@public.gmane.org designates 185.70.40.27 as permitted sender) smtp.mailfrom=lua8ds-6EK1v4hiKcSzQB+pC5nmwQ@public.gmane.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me X-Original-From: Mark Johnno 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:31450 Archived-At: Hi, I have been using a lua filter for a few months with no issue, however,= for the last few days, I've not been able to produce a PDF. I can't find h= ints 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 brack= ets which I resolved by using --trace to check where parsing was slowing do= wn (that is where the brackets were missing), but this time --trace does no= t provide any hints. =20 I can convert the document from .md to .pdf (without the filter); that is t= he command I use: $ pandoc file.md --pdf-engine=3Dxelatex -o file.pdf ...but when I add count-para.lua filter: =20 $ pandoc file.md --pdf-engine=3Dxelatex --lua-filter=3Dcount-para.lua -o fi= le.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: --[[ 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. ]] local count =3D 0 local chapter =3D 0 local indexUserID =3D {} ------------------------------ -- Options with default values ------------------------------ local resetAtChapter =3D false local enclosing =3D "[]" local chapterSep =3D "." local refName =3D "paragraph " local addPageNr =3D true function getUserSettings (meta) if meta.resetAtChapter ~=3D nil then resetAtChapter =3D meta.resetAtChapter end if meta.enclosing ~=3D nil then enclosing =3D pandoc.utils.stringify(meta.enclosing) end if meta.chapterSep ~=3D nil then chapterSep =3D pandoc.utils.stringify(meta.chapterSep) end 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 if meta.addPageNr ~=3D nil then addPageNr =3D meta.addPageNr end end ------------------------ -- Add global formatting ------------------------ function addFormatting (meta) 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 if FORMAT:match "latex" then addTexPreamble("\\usepackage{marginnote}") addTexPreamble("\\reversemarginpar") addTexPreamble("\\newcommand{\\paragraphnumber}[1]{\\marginnote{\\color= {lightgray}\\tiny{#1}}[0pt]}") end =20 meta['header-includes'] =3D tmp return(meta) end ------------------------- -- count Para and add Div ------------------------- function countPara (doc) for i=3D1,#doc.blocks do -- 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 -- 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 -- count paragraphs count =3D count + 1=09 local ID =3D count if resetAtChapter then=20 ID =3D chapter..chapterSep..count=20 end -- 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 -- 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 -- 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.."\\label= {"..userID.."}}" end table.insert(doc.blocks[i].content, 1, pandoc.RawInline("tex", texC= ount)) else table.insert(doc.blocks[i].content, 1, pandoc.Space()) table.insert(doc.blocks[i].content, 1, pandoc.Span(number, pandoc.A= ttr(ID, {"paragraph-number"}))) end end end return doc end ------------------------------ -- set in-text cross-references ------------------------------ function setCrossRefs (cite) local userID =3D cite.citations[1].id local paraID =3D indexUserID[userID]=20 -- ignore other "cite" elements if paraID ~=3D nil then =20 -- make in-document cross-references if FORMAT:match "latex" then local texInsert =3D refName.."\\hyperlink{"..userID.."}{"..paraID.."}= " if addPageNr then texInsert =3D texInsert.." on page~\\pageref{"..userID.."}" end return pandoc.RawInline("tex", texInsert) else return pandoc.Link(refName..paraID, "#"..paraID) end end end -------------------- -- basic Pandoc loop -------------------- return { { Meta =3D addFormatting }, { Meta =3D getUserSettings }, { Pandoc =3D countPara }, { Cite =3D setCrossRefs } } --=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/e2suTdCtcLJ3u0PBmkSX9YRRukwnvuWJPhOFU1iL8lR84w_f8f9j1UrjpHEW= _3oHRO5aC_mDpkazLs5dfMXA1EKkXvf4eZs3_tgIXsFq1uU%3D%40proton.me.