public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* Fw: Fixing lua filter to number paragraphs
       [not found] <78BBgUlgdEJOaNOIxhfkTKPgf07yZREVfvlbeq1kqYQ59CCPSpaXEX4T_806rUzuPjbb5aIvpmynEu04PsBHsJTnWtkNNiG5dZQYfDGsO0Y=@proton.me>
@ 2022-09-23 23:09 ` 'Mark Johnno' via pandoc-discuss
  2022-09-24  5:39   ` Bastien DUMONT
  0 siblings, 1 reply; 4+ messages in thread
From: 'Mark Johnno' via pandoc-discuss @ 2022-09-23 23:09 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

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 hints online. I am hoping someone can help me.
 
That is the error message I get:
 
! Undefined control sequence.
<argument> ... \hspace {\z@ }\ignorespaces \color
 
{lightgray}\tiny {[1]}\end...
l.72 \paragraphnumber{[1]}
 
I had some error messages in the past, usually due to missing squared brackets 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.
 
I can convert the document from .md to .pdf (without the filter); that is the command I use:

$ pandoc file.md --pdf-engine=xelatex -o file.pdf

...but when I add count-para.lua filter:
 
$ pandoc file.md --pdf-engine=xelatex --lua-filter=count-para.lua -o file.pdf
 
I get the error message mentioned above.
 
I also tried with another document. I get the same error message.
 
I tried contacting the author of the filter, in vain.
 
Do you have a hint about how I could troubleshoot or fix this issue?
 
Does the filter need to be updated?
 
$ pandoc -v
pandoc 2.5
Compiled with pandoc-types 1.17.5.4, texmath 0.11.2.2, skylighting 0.7.7
 
I use Trisquel GNU/Linux 10.0.1.
 
This is the filter:

--[[
Make all 'regular' paragraphs into a div and assign a numeric ID
Format this number in the margin
Copyright © 2021 Michael Cysouw 
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 = 0
local chapter = 0
local indexUserID = {}

------------------------------
-- Options with default values
------------------------------

local resetAtChapter = false
local enclosing = "[]"
local chapterSep = "."
local refName = "paragraph "
local addPageNr = true

function getUserSettings (meta)

  if meta.resetAtChapter ~= nil then
    resetAtChapter = meta.resetAtChapter
  end

  if meta.enclosing ~= nil then
    enclosing = pandoc.utils.stringify(meta.enclosing)
  end

  if meta.chapterSep ~= nil then
    chapterSep = pandoc.utils.stringify(meta.chapterSep)
  end

  if meta.refName ~= nil then
    refName = pandoc.utils.stringify(meta.refName)
    if FORMAT:match "latex" then
      if refName == "#" then refName = "\\#" end
    end
  end

  if meta.addPageNr ~= nil then
    addPageNr = meta.addPageNr
  end

end

------------------------
-- Add global formatting
------------------------

function addFormatting (meta)

  local tmp = pandoc.MetaList{meta['header-includes']}
  if meta['header-includes'] ~= nil then
    tmp = meta['header-includes']
  end
  
  if FORMAT:match "html" then
    local css = [[ 
<!-- CSS added by lua-filter 'count-para' -->
<style>
.paragraph-number { 
  float: left;
  margin-left: -5em;
  width: 4.5em;
  text-align: right;
  color: grey;
  font-size: x-small;
  padding-top: 5px;
}
</style>
    ]]
    tmp[#tmp+1] = pandoc.MetaBlocks(pandoc.RawBlock("html", css))
  end
  
  function addTexPreamble (tex)
    tmp[#tmp+1] = 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
  
  meta['header-includes'] = tmp
  return(meta)
end

-------------------------
-- count Para and add Div
-------------------------

function countPara (doc)

  for i=1,#doc.blocks do

    -- optionally reset counter
    if  doc.blocks[i].tag == "Header"
        and doc.blocks[i].level == 1
        and doc.blocks[i].classes[1] ~= "unnumbered" 
        and resetAtChapter
    then
        chapter = chapter + 1
        count = 0
    end

    -- get Para, but not if there is an Image inside
    if  doc.blocks[i].tag == "Para"
        and doc.blocks[i].content[1].tag ~= "Image"
    then

      -- count paragraphs
      count = count + 1	
      local ID = count
      if resetAtChapter then 
        ID = chapter..chapterSep..count 
      end

      -- format number to insert
      local number = ID
      if enclosing:len() == 1 then
        number = enclosing..ID..enclosing
      else
        number = enclosing:sub(1,1)..ID..enclosing:sub(2,2)
      end

      -- check for user-inserted ids at the start of the paragraph
      local firstElem = pandoc.utils.stringify(doc.blocks[i].content[1])
      local userID = firstElem:match("{#(.*)}")
      if userID ~= nil then
        -- add to index
        indexUserID[userID] = ID
        -- remove reference from text
        table.remove(doc.blocks[i].content, 1)
        -- remove possible space
        if doc.blocks[i].content[1].tag == "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 = "\\paragraphnumber{"..number.."}"
        if userID ~= nil then
          -- add target for link to the number
          texCount = "\\hypertarget{"..userID.."}{\n"..texCount.."\\label{"..userID.."}}"
        end
        table.insert(doc.blocks[i].content, 1, pandoc.RawInline("tex", texCount))
      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

    end
  end
  return doc
end

------------------------------
-- set in-text cross-references
------------------------------

function setCrossRefs (cite)

  local userID = cite.citations[1].id
  local paraID = indexUserID[userID] 

  -- ignore other "cite" elements
  if paraID ~= nil then
  
    -- make in-document cross-references
    if FORMAT:match "latex" then

      local texInsert = refName.."\\hyperlink{"..userID.."}{"..paraID.."}"
      if addPageNr then
        texInsert = 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 = addFormatting },
  { Meta = getUserSettings },
  { Pandoc = countPara },
  { Cite = setCrossRefs }
}

-- 
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/e2suTdCtcLJ3u0PBmkSX9YRRukwnvuWJPhOFU1iL8lR84w_f8f9j1UrjpHEW_3oHRO5aC_mDpkazLs5dfMXA1EKkXvf4eZs3_tgIXsFq1uU%3D%40proton.me.


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

* Re: Fw: Fixing lua filter to number paragraphs
  2022-09-23 23:09 ` Fw: Fixing lua filter to number paragraphs 'Mark Johnno' via pandoc-discuss
@ 2022-09-24  5:39   ` Bastien DUMONT
  2022-09-24  6:04     ` AW: " denis.maier-NSENcxR/0n0
  0 siblings, 1 reply; 4+ messages in thread
From: Bastien DUMONT @ 2022-09-24  5:39 UTC (permalink / raw)
  To: 'Mark Johnno' via pandoc-discuss

The error means that the command \color is not defined, i.e. the package that defines it is not loaded. It should be fixed by adding this after addTexPreamble("\\reversemarginpar"):

addTexPreamble("\\usepackage{\\color}")

Le Friday 23 September 2022 à 11:09:42PM, 'Mark Johnno' via pandoc-discuss a écrit :
> 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 hints online. I am hoping someone can help me.
>  
> That is the error message I get:
>  
> ! Undefined control sequence.
> <argument> ... \hspace {\z@ }\ignorespaces \color
>  
> {lightgray}\tiny {[1]}\end...
> l.72 \paragraphnumber{[1]}
>  
> I had some error messages in the past, usually due to missing squared brackets 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.
>  
> I can convert the document from .md to .pdf (without the filter); that is the command I use:
> 
> $ pandoc file.md --pdf-engine=xelatex -o file.pdf
> 
> ...but when I add count-para.lua filter:
>  
> $ pandoc file.md --pdf-engine=xelatex --lua-filter=count-para.lua -o file.pdf
>  
> I get the error message mentioned above.
>  
> I also tried with another document. I get the same error message.
>  
> I tried contacting the author of the filter, in vain.
>  
> Do you have a hint about how I could troubleshoot or fix this issue?
>  
> Does the filter need to be updated?
>  
> $ pandoc -v
> pandoc 2.5
> Compiled with pandoc-types 1.17.5.4, texmath 0.11.2.2, skylighting 0.7.7
>  
> I use Trisquel GNU/Linux 10.0.1.
>  
> This is the filter:
> 
> --[[
> Make all 'regular' paragraphs into a div and assign a numeric ID
> Format this number in the margin
> Copyright © 2021 Michael Cysouw 
> 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 = 0
> local chapter = 0
> local indexUserID = {}
> 
> ------------------------------
> -- Options with default values
> ------------------------------
> 
> local resetAtChapter = false
> local enclosing = "[]"
> local chapterSep = "."
> local refName = "paragraph "
> local addPageNr = true
> 
> function getUserSettings (meta)
> 
>   if meta.resetAtChapter ~= nil then
>     resetAtChapter = meta.resetAtChapter
>   end
> 
>   if meta.enclosing ~= nil then
>     enclosing = pandoc.utils.stringify(meta.enclosing)
>   end
> 
>   if meta.chapterSep ~= nil then
>     chapterSep = pandoc.utils.stringify(meta.chapterSep)
>   end
> 
>   if meta.refName ~= nil then
>     refName = pandoc.utils.stringify(meta.refName)
>     if FORMAT:match "latex" then
>       if refName == "#" then refName = "\\#" end
>     end
>   end
> 
>   if meta.addPageNr ~= nil then
>     addPageNr = meta.addPageNr
>   end
> 
> end
> 
> ------------------------
> -- Add global formatting
> ------------------------
> 
> function addFormatting (meta)
> 
>   local tmp = pandoc.MetaList{meta['header-includes']}
>   if meta['header-includes'] ~= nil then
>     tmp = meta['header-includes']
>   end
>   
>   if FORMAT:match "html" then
>     local css = [[ 
> <!-- CSS added by lua-filter 'count-para' -->
> <style>
> .paragraph-number { 
>   float: left;
>   margin-left: -5em;
>   width: 4.5em;
>   text-align: right;
>   color: grey;
>   font-size: x-small;
>   padding-top: 5px;
> }
> </style>
>     ]]
>     tmp[#tmp+1] = pandoc.MetaBlocks(pandoc.RawBlock("html", css))
>   end
>   
>   function addTexPreamble (tex)
>     tmp[#tmp+1] = 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
>   
>   meta['header-includes'] = tmp
>   return(meta)
> end
> 
> -------------------------
> -- count Para and add Div
> -------------------------
> 
> function countPara (doc)
> 
>   for i=1,#doc.blocks do
> 
>     -- optionally reset counter
>     if  doc.blocks[i].tag == "Header"
>         and doc.blocks[i].level == 1
>         and doc.blocks[i].classes[1] ~= "unnumbered" 
>         and resetAtChapter
>     then
>         chapter = chapter + 1
>         count = 0
>     end
> 
>     -- get Para, but not if there is an Image inside
>     if  doc.blocks[i].tag == "Para"
>         and doc.blocks[i].content[1].tag ~= "Image"
>     then
> 
>       -- count paragraphs
>       count = count + 1	
>       local ID = count
>       if resetAtChapter then 
>         ID = chapter..chapterSep..count 
>       end
> 
>       -- format number to insert
>       local number = ID
>       if enclosing:len() == 1 then
>         number = enclosing..ID..enclosing
>       else
>         number = enclosing:sub(1,1)..ID..enclosing:sub(2,2)
>       end
> 
>       -- check for user-inserted ids at the start of the paragraph
>       local firstElem = pandoc.utils.stringify(doc.blocks[i].content[1])
>       local userID = firstElem:match("{#(.*)}")
>       if userID ~= nil then
>         -- add to index
>         indexUserID[userID] = ID
>         -- remove reference from text
>         table.remove(doc.blocks[i].content, 1)
>         -- remove possible space
>         if doc.blocks[i].content[1].tag == "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 = "\\paragraphnumber{"..number.."}"
>         if userID ~= nil then
>           -- add target for link to the number
>           texCount = "\\hypertarget{"..userID.."}{\n"..texCount.."\\label{"..userID.."}}"
>         end
>         table.insert(doc.blocks[i].content, 1, pandoc.RawInline("tex", texCount))
>       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
> 
>     end
>   end
>   return doc
> end
> 
> ------------------------------
> -- set in-text cross-references
> ------------------------------
> 
> function setCrossRefs (cite)
> 
>   local userID = cite.citations[1].id
>   local paraID = indexUserID[userID] 
> 
>   -- ignore other "cite" elements
>   if paraID ~= nil then
>   
>     -- make in-document cross-references
>     if FORMAT:match "latex" then
> 
>       local texInsert = refName.."\\hyperlink{"..userID.."}{"..paraID.."}"
>       if addPageNr then
>         texInsert = 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 = addFormatting },
>   { Meta = getUserSettings },
>   { Pandoc = countPara },
>   { Cite = setCrossRefs }
> }
> 
> -- 
> 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/e2suTdCtcLJ3u0PBmkSX9YRRukwnvuWJPhOFU1iL8lR84w_f8f9j1UrjpHEW_3oHRO5aC_mDpkazLs5dfMXA1EKkXvf4eZs3_tgIXsFq1uU%3D%40proton.me.

-- 
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/Yy6X/FXIPVN1zij3%40localhost.


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

* AW: Fw: Fixing lua filter to number paragraphs
  2022-09-24  5:39   ` Bastien DUMONT
@ 2022-09-24  6:04     ` denis.maier-NSENcxR/0n0
       [not found]       ` <9c110d41d7b24b39b98b999c78d6210b-NSENcxR/0n0@public.gmane.org>
  0 siblings, 1 reply; 4+ messages in thread
From: denis.maier-NSENcxR/0n0 @ 2022-09-24  6:04 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

Or maybe the xcolor package.
________________________________________
Von: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> im Auftrag von Bastien DUMONT <bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org>
Gesendet: Samstag, 24. September 2022 07:39:08
An: 'Mark Johnno' via pandoc-discuss
Betreff: Re: Fw: Fixing lua filter to number paragraphs

The error means that the command \color is not defined, i.e. the package that defines it is not loaded. It should be fixed by adding this after addTexPreamble("\\reversemarginpar"):

addTexPreamble("\\usepackage{\\color}")

Le Friday 23 September 2022 à 11:09:42PM, 'Mark Johnno' via pandoc-discuss a écrit :
> 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 hints online. I am hoping someone can help me.
>
> That is the error message I get:
>
> ! Undefined control sequence.
> <argument> ... \hspace {\z@ }\ignorespaces \color
>
> {lightgray}\tiny {[1]}\end...
> l.72 \paragraphnumber{[1]}
>
> I had some error messages in the past, usually due to missing squared brackets 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.
>
> I can convert the document from .md to .pdf (without the filter); that is the command I use:
>
> $ pandoc file.md --pdf-engine=xelatex -o file.pdf
>
> ...but when I add count-para.lua filter:
>
> $ pandoc file.md --pdf-engine=xelatex --lua-filter=count-para.lua -o file.pdf
>
> I get the error message mentioned above.
>
> I also tried with another document. I get the same error message.
>
> I tried contacting the author of the filter, in vain.
>
> Do you have a hint about how I could troubleshoot or fix this issue?
>
> Does the filter need to be updated?
>
> $ pandoc -v
> pandoc 2.5
> Compiled with pandoc-types 1.17.5.4, texmath 0.11.2.2, skylighting 0.7.7
>
> I use Trisquel GNU/Linux 10.0.1.
>
> This is the filter:
>
> --[[
> Make all 'regular' paragraphs into a div and assign a numeric ID
> Format this number in the margin
> Copyright © 2021 Michael Cysouw
> 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 = 0
> local chapter = 0
> local indexUserID = {}
>
> ------------------------------
> -- Options with default values
> ------------------------------
>
> local resetAtChapter = false
> local enclosing = "[]"
> local chapterSep = "."
> local refName = "paragraph "
> local addPageNr = true
>
> function getUserSettings (meta)
>
>   if meta.resetAtChapter ~= nil then
>     resetAtChapter = meta.resetAtChapter
>   end
>
>   if meta.enclosing ~= nil then
>     enclosing = pandoc.utils.stringify(meta.enclosing)
>   end
>
>   if meta.chapterSep ~= nil then
>     chapterSep = pandoc.utils.stringify(meta.chapterSep)
>   end
>
>   if meta.refName ~= nil then
>     refName = pandoc.utils.stringify(meta.refName)
>     if FORMAT:match "latex" then
>       if refName == "#" then refName = "\\#" end
>     end
>   end
>
>   if meta.addPageNr ~= nil then
>     addPageNr = meta.addPageNr
>   end
>
> end
>
> ------------------------
> -- Add global formatting
> ------------------------
>
> function addFormatting (meta)
>
>   local tmp = pandoc.MetaList{meta['header-includes']}
>   if meta['header-includes'] ~= nil then
>     tmp = meta['header-includes']
>   end
>
>   if FORMAT:match "html" then
>     local css = [[
> <!-- CSS added by lua-filter 'count-para' -->
> <style>
> .paragraph-number {
>   float: left;
>   margin-left: -5em;
>   width: 4.5em;
>   text-align: right;
>   color: grey;
>   font-size: x-small;
>   padding-top: 5px;
> }
> </style>
>     ]]
>     tmp[#tmp+1] = pandoc.MetaBlocks(pandoc.RawBlock("html", css))
>   end
>
>   function addTexPreamble (tex)
>     tmp[#tmp+1] = 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
>
>   meta['header-includes'] = tmp
>   return(meta)
> end
>
> -------------------------
> -- count Para and add Div
> -------------------------
>
> function countPara (doc)
>
>   for i=1,#doc.blocks do
>
>     -- optionally reset counter
>     if  doc.blocks[i].tag == "Header"
>         and doc.blocks[i].level == 1
>         and doc.blocks[i].classes[1] ~= "unnumbered"
>         and resetAtChapter
>     then
>         chapter = chapter + 1
>         count = 0
>     end
>
>     -- get Para, but not if there is an Image inside
>     if  doc.blocks[i].tag == "Para"
>         and doc.blocks[i].content[1].tag ~= "Image"
>     then
>
>       -- count paragraphs
>       count = count + 1
>       local ID = count
>       if resetAtChapter then
>         ID = chapter..chapterSep..count
>       end
>
>       -- format number to insert
>       local number = ID
>       if enclosing:len() == 1 then
>         number = enclosing..ID..enclosing
>       else
>         number = enclosing:sub(1,1)..ID..enclosing:sub(2,2)
>       end
>
>       -- check for user-inserted ids at the start of the paragraph
>       local firstElem = pandoc.utils.stringify(doc.blocks[i].content[1])
>       local userID = firstElem:match("{#(.*)}")
>       if userID ~= nil then
>         -- add to index
>         indexUserID[userID] = ID
>         -- remove reference from text
>         table.remove(doc.blocks[i].content, 1)
>         -- remove possible space
>         if doc.blocks[i].content[1].tag == "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 = "\\paragraphnumber{"..number.."}"
>         if userID ~= nil then
>           -- add target for link to the number
>           texCount = "\\hypertarget{"..userID.."}{\n"..texCount.."\\label{"..userID.."}}"
>         end
>         table.insert(doc.blocks[i].content, 1, pandoc.RawInline("tex", texCount))
>       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
>
>     end
>   end
>   return doc
> end
>
> ------------------------------
> -- set in-text cross-references
> ------------------------------
>
> function setCrossRefs (cite)
>
>   local userID = cite.citations[1].id
>   local paraID = indexUserID[userID]
>
>   -- ignore other "cite" elements
>   if paraID ~= nil then
>
>     -- make in-document cross-references
>     if FORMAT:match "latex" then
>
>       local texInsert = refName.."\\hyperlink{"..userID.."}{"..paraID.."}"
>       if addPageNr then
>         texInsert = 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 = addFormatting },
>   { Meta = getUserSettings },
>   { Pandoc = countPara },
>   { Cite = setCrossRefs }
> }
>
> --
> 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/e2suTdCtcLJ3u0PBmkSX9YRRukwnvuWJPhOFU1iL8lR84w_f8f9j1UrjpHEW_3oHRO5aC_mDpkazLs5dfMXA1EKkXvf4eZs3_tgIXsFq1uU%3D%40proton.me.

--
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/Yy6X/FXIPVN1zij3%40localhost.

-- 
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/9c110d41d7b24b39b98b999c78d6210b%40unibe.ch.


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

* Re: AW: Fw: Fixing lua filter to number paragraphs
       [not found]       ` <9c110d41d7b24b39b98b999c78d6210b-NSENcxR/0n0@public.gmane.org>
@ 2022-09-24 14:29         ` 'Mark Johnno' via pandoc-discuss
  0 siblings, 0 replies; 4+ messages in thread
From: 'Mark Johnno' via pandoc-discuss @ 2022-09-24 14:29 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

Adding: addTexPreamble("\\usepackage{xcolor}")

and switching \\color (on the following line) to 'gray' from 'lightgray' fixed the issue; Pandoc issued error "! LaTeX Error: Undefined color 'Lightgray'".

When I tried adding addTexPreamble("\\usepackage{color}") instead of xcolor, pandoc issued "Undefined color" for both gray and lightgray (black worked fine.)

Anyway, the filter works fine with 'xcolor' and 'gray'. Thanks a lot for your help, and for replying so quickly.


------- Original Message -------
On Saturday, September 24th, 2022 at 8:04 AM, <denis.maier-NSENcxR/0n0@public.gmane.org> wrote:


> Or maybe the xcolor package.
> ________________________________________
> Von: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org im Auftrag von Bastien DUMONT bastien.dumont-VwIFZPTo/vqsTnJN9+BGXg@public.gmane.org
>
> Gesendet: Samstag, 24. September 2022 07:39:08
> An: 'Mark Johnno' via pandoc-discuss
> Betreff: Re: Fw: Fixing lua filter to number paragraphs
>
> The error means that the command \color is not defined, i.e. the package that defines it is not loaded. It should be fixed by adding this after addTexPreamble("\\reversemarginpar"):
>
> addTexPreamble("\\usepackage{\\color}")
>
> Le Friday 23 September 2022 à 11:09:42PM, 'Mark Johnno' via pandoc-discuss a écrit :
>
> > 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 hints online. I am hoping someone can help me.
> >
> > That is the error message I get:
> >
> > ! Undefined control sequence.
> > <argument> ... \hspace {\z@ }\ignorespaces \color
> >
> > {lightgray}\tiny {[1]}\end...
> > l.72 \paragraphnumber{[1]}
> >
> > I had some error messages in the past, usually due to missing squared brackets 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.
> >
> > I can convert the document from .md to .pdf (without the filter); that is the command I use:
> >
> > $ pandoc file.md --pdf-engine=xelatex -o file.pdf
> >
> > ...but when I add count-para.lua filter:
> >
> > $ pandoc file.md --pdf-engine=xelatex --lua-filter=count-para.lua -o file.pdf
> >
> > I get the error message mentioned above.
> >
> > I also tried with another document. I get the same error message.
> >
> > I tried contacting the author of the filter, in vain.
> >
> > Do you have a hint about how I could troubleshoot or fix this issue?
> >
> > Does the filter need to be updated?
> >
> > $ pandoc -v
> > pandoc 2.5
> > Compiled with pandoc-types 1.17.5.4, texmath 0.11.2.2, skylighting 0.7.7
> >
> > I use Trisquel GNU/Linux 10.0.1.
> >
> > This is the filter:
> >
> > --[[
> > Make all 'regular' paragraphs into a div and assign a numeric ID
> > Format this number in the margin
> > Copyright © 2021 Michael Cysouw
> > 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 = 0
> > local chapter = 0
> > local indexUserID = {}
> >
> > ------------------------------
> > -- Options with default values
> > ------------------------------
> >
> > local resetAtChapter = false
> > local enclosing = "[]"
> > local chapterSep = "."
> > local refName = "paragraph "
> > local addPageNr = true
> >
> > function getUserSettings (meta)
> >
> > if meta.resetAtChapter ~= nil then
> > resetAtChapter = meta.resetAtChapter
> > end
> >
> > if meta.enclosing ~= nil then
> > enclosing = pandoc.utils.stringify(meta.enclosing)
> > end
> >
> > if meta.chapterSep ~= nil then
> > chapterSep = pandoc.utils.stringify(meta.chapterSep)
> > end
> >
> > if meta.refName ~= nil then
> > refName = pandoc.utils.stringify(meta.refName)
> > if FORMAT:match "latex" then
> > if refName == "#" then refName = "\\#" end
> > end
> > end
> >
> > if meta.addPageNr ~= nil then
> > addPageNr = meta.addPageNr
> > end
> >
> > end
> >
> > ------------------------
> > -- Add global formatting
> > ------------------------
> >
> > function addFormatting (meta)
> >
> > local tmp = pandoc.MetaList{meta['header-includes']}
> > if meta['header-includes'] ~= nil then
> > tmp = meta['header-includes']
> > end
> >
> > if FORMAT:match "html" then
> > local css = [[
> > <!-- CSS added by lua-filter 'count-para' -->
> > <style>
> > .paragraph-number {
> > float: left;
> > margin-left: -5em;
> > width: 4.5em;
> > text-align: right;
> > color: grey;
> > font-size: x-small;
> > padding-top: 5px;
> > }
> > </style>
> > ]]
> > tmp[#tmp+1] = pandoc.MetaBlocks(pandoc.RawBlock("html", css))
> > end
> >
> > function addTexPreamble (tex)
> > tmp[#tmp+1] = 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
> >
> > meta['header-includes'] = tmp
> > return(meta)
> > end
> >
> > -------------------------
> > -- count Para and add Div
> > -------------------------
> >
> > function countPara (doc)
> >
> > for i=1,#doc.blocks do
> >
> > -- optionally reset counter
> > if doc.blocks[i].tag == "Header"
> > and doc.blocks[i].level == 1
> > and doc.blocks[i].classes[1] ~= "unnumbered"
> > and resetAtChapter
> > then
> > chapter = chapter + 1
> > count = 0
> > end
> >
> > -- get Para, but not if there is an Image inside
> > if doc.blocks[i].tag == "Para"
> > and doc.blocks[i].content[1].tag ~= "Image"
> > then
> >
> > -- count paragraphs
> > count = count + 1
> > local ID = count
> > if resetAtChapter then
> > ID = chapter..chapterSep..count
> > end
> >
> > -- format number to insert
> > local number = ID
> > if enclosing:len() == 1 then
> > number = enclosing..ID..enclosing
> > else
> > number = enclosing:sub(1,1)..ID..enclosing:sub(2,2)
> > end
> >
> > -- check for user-inserted ids at the start of the paragraph
> > local firstElem = pandoc.utils.stringify(doc.blocks[i].content[1])
> > local userID = firstElem:match("{#(.*)}")
> > if userID ~= nil then
> > -- add to index
> > indexUserID[userID] = ID
> > -- remove reference from text
> > table.remove(doc.blocks[i].content, 1)
> > -- remove possible space
> > if doc.blocks[i].content[1].tag == "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 = "\\paragraphnumber{"..number.."}"
> > if userID ~= nil then
> > -- add target for link to the number
> > texCount = "\\hypertarget{"..userID.."}{\n"..texCount.."\\label{"..userID.."}}"
> > end
> > table.insert(doc.blocks[i].content, 1, pandoc.RawInline("tex", texCount))
> > 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
> >
> > end
> > end
> > return doc
> > end
> >
> > ------------------------------
> > -- set in-text cross-references
> > ------------------------------
> >
> > function setCrossRefs (cite)
> >
> > local userID = cite.citations[1].id
> > local paraID = indexUserID[userID]
> >
> > -- ignore other "cite" elements
> > if paraID ~= nil then
> >
> > -- make in-document cross-references
> > if FORMAT:match "latex" then
> >
> > local texInsert = refName.."\\hyperlink{"..userID.."}{"..paraID.."}"
> > if addPageNr then
> > texInsert = 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 = addFormatting },
> > { Meta = getUserSettings },
> > { Pandoc = countPara },
> > { Cite = setCrossRefs }
> > }
> >
> > --
> > 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/e2suTdCtcLJ3u0PBmkSX9YRRukwnvuWJPhOFU1iL8lR84w_f8f9j1UrjpHEW_3oHRO5aC_mDpkazLs5dfMXA1EKkXvf4eZs3_tgIXsFq1uU%3D%40proton.me.
>
>
> --
> 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/Yy6X/FXIPVN1zij3%40localhost.
>
> --
> 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/9c110d41d7b24b39b98b999c78d6210b%40unibe.ch.

-- 
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/axV6QnqR5SkO9D_rwl31egbgvuBl-BmXlRk7xZoo9RA9vIgCBDP26_hB222btu1xx6XACuL_rBVbkf5SMquJfQ25dKwdtM2UrYWVBz0KaJE%3D%40proton.me.


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

end of thread, other threads:[~2022-09-24 14:29 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <78BBgUlgdEJOaNOIxhfkTKPgf07yZREVfvlbeq1kqYQ59CCPSpaXEX4T_806rUzuPjbb5aIvpmynEu04PsBHsJTnWtkNNiG5dZQYfDGsO0Y=@proton.me>
2022-09-23 23:09 ` Fw: Fixing lua filter to number paragraphs 'Mark Johnno' via pandoc-discuss
2022-09-24  5:39   ` Bastien DUMONT
2022-09-24  6:04     ` AW: " denis.maier-NSENcxR/0n0
     [not found]       ` <9c110d41d7b24b39b98b999c78d6210b-NSENcxR/0n0@public.gmane.org>
2022-09-24 14:29         ` 'Mark Johnno' via pandoc-discuss

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