将额外的Lua-Filter添加到YAML中

发布于 2025-01-18 12:02:46 字数 1388 浏览 0 评论 0原文

我正在尝试在YAML中添加一个额外的Lua-Filter:

---
title: "TITLE"
subtitle: "SUBTITLE"
date: "07/04/2022" 
output:
  pdf_document:
    pandoc_args: 
      - --lua-filter=/Users/user/.local/share/pandoc/filters/wordcount.lua
    latex_engine: pdflatex
    includes:
      in_header: style.sty
    #keep_tex:  true
  bookdown::pdf_book:
    citation_package: biblatex
bibliography: literature.bib
csl: my.csl
lang: de
fontsize: 12pt
---

好的,现在,当我尝试编织文档时,我会得到这个erorr:

/usr/local/bin/pandoc +RTS -K512m -RTS mother.knit.md --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output mother.tex --lua-filter /Users/user/Library/R/x86_64/4.1/library/rmarkdown/rmarkdown/lua/pagebreak.lua --lua-filter /Users/user/Library/R/x86_64/4.1/library/rmarkdown/rmarkdown/lua/latex-div.lua --self-contained --highlight-style tango --pdf-engine pdflatex --include-in-header style.sty --variable graphics --lua-filter=/Users/user/.local/share/pandoc/filters/wordcount.lua --variable 'geometry:margin=1in' --citeproc
655 words in body
4171 characters in body
4791 characters in body (including spaces)
Error in readLines(con, warn = FALSE) : cannot open the connection
In addition: Warning message:
In readLines(con, warn = FALSE) :
  cannot open file 'mother.tex': No such file or directory

母亲.tex怎么了?为什么没有创建它?

希望有人可以帮忙。已经谢谢。

I'm trying to add an additional lua-filter into the YAML:

---
title: "TITLE"
subtitle: "SUBTITLE"
date: "07/04/2022" 
output:
  pdf_document:
    pandoc_args: 
      - --lua-filter=/Users/user/.local/share/pandoc/filters/wordcount.lua
    latex_engine: pdflatex
    includes:
      in_header: style.sty
    #keep_tex:  true
  bookdown::pdf_book:
    citation_package: biblatex
bibliography: literature.bib
csl: my.csl
lang: de
fontsize: 12pt
---

ok, now when I try to knit the document I'm getting this erorr:

/usr/local/bin/pandoc +RTS -K512m -RTS mother.knit.md --to latex --from markdown+autolink_bare_uris+tex_math_single_backslash --output mother.tex --lua-filter /Users/user/Library/R/x86_64/4.1/library/rmarkdown/rmarkdown/lua/pagebreak.lua --lua-filter /Users/user/Library/R/x86_64/4.1/library/rmarkdown/rmarkdown/lua/latex-div.lua --self-contained --highlight-style tango --pdf-engine pdflatex --include-in-header style.sty --variable graphics --lua-filter=/Users/user/.local/share/pandoc/filters/wordcount.lua --variable 'geometry:margin=1in' --citeproc
655 words in body
4171 characters in body
4791 characters in body (including spaces)
Error in readLines(con, warn = FALSE) : cannot open the connection
In addition: Warning message:
In readLines(con, warn = FALSE) :
  cannot open file 'mother.tex': No such file or directory

What is wrong with the mother.tex? Why it's not been created?

Hope someone can help. Thanks already.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

七禾 2025-01-25 12:02:46

好的,我有点努力为WordCout:Process参数找到正确的位置。

但是,对于那些试图实现解决方法的人的解决方案可能是以下内容:

https://github.com/pandoc/lua-filters/blob/04e2d663d663dcb374d2c79ad1a42a42a30714843cb4843cb440/wordcount/wordcount/wordcount/wordcount/wordcount/wordcount/wordcount.lua--

“ 43-45

-- counts words in a document

words = 0
characters = 0
characters_and_spaces = 0
process_anyway = false

wordcount = {
  Str = function(el)
    -- we don't count a word if it's entirely punctuation:
    if el.text:match("%P") then
        words = words + 1
    end
    characters = characters + utf8.len(el.text)
    characters_and_spaces = characters_and_spaces + utf8.len(el.text)
  end,

  Space = function(el)
    characters_and_spaces = characters_and_spaces + 1
  end,

  Code = function(el)
    _,n = el.text:gsub("%S+","")
    words = words + n
    text_nospace = el.text:gsub("%s", "")
    characters = characters + utf8.len(text_nospace)
    characters_and_spaces = characters_and_spaces + utf8.len(el.text)
  end,

  CodeBlock = function(el)
    _,n = el.text:gsub("%S+","")
    words = words + n
    text_nospace = el.text:gsub("%s", "")
    characters = characters + utf8.len(text_nospace)
    characters_and_spaces = characters_and_spaces + utf8.len(el.text)
  end
}

-- check if the `wordcount` variable is set to `process-anyway`
--function Meta(meta)
--  if meta.wordcount and (meta.wordcount=="process-anyway"
--    or meta.wordcount=="process" or meta.wordcount=="convert") then
      process_anyway = true
--  end
--end

function Pandoc(el)
    -- skip metadata, just count body:
    pandoc.walk_block(pandoc.Div(el.blocks), wordcount)
    print(words .. " words in body")
    print(characters .. " characters in body")
    print(characters_and_spaces .. " characters in body (including spaces)")
    if not process_anyway then
      os.exit(0)
    end
  end

Ok, I struggled a little bit to find the right position for the wordcout: process argument.

But a solution for those one who try to achive a workaround could be the following:

edit the following file from https://github.com/pandoc/lua-filters/blob/04e2d663dcb374d2c79ad1a42a30714843cb4e40/wordcount/wordcount.lua

notice the comment-out lines in line 39-42 and 43-45

-- counts words in a document

words = 0
characters = 0
characters_and_spaces = 0
process_anyway = false

wordcount = {
  Str = function(el)
    -- we don't count a word if it's entirely punctuation:
    if el.text:match("%P") then
        words = words + 1
    end
    characters = characters + utf8.len(el.text)
    characters_and_spaces = characters_and_spaces + utf8.len(el.text)
  end,

  Space = function(el)
    characters_and_spaces = characters_and_spaces + 1
  end,

  Code = function(el)
    _,n = el.text:gsub("%S+","")
    words = words + n
    text_nospace = el.text:gsub("%s", "")
    characters = characters + utf8.len(text_nospace)
    characters_and_spaces = characters_and_spaces + utf8.len(el.text)
  end,

  CodeBlock = function(el)
    _,n = el.text:gsub("%S+","")
    words = words + n
    text_nospace = el.text:gsub("%s", "")
    characters = characters + utf8.len(text_nospace)
    characters_and_spaces = characters_and_spaces + utf8.len(el.text)
  end
}

-- check if the `wordcount` variable is set to `process-anyway`
--function Meta(meta)
--  if meta.wordcount and (meta.wordcount=="process-anyway"
--    or meta.wordcount=="process" or meta.wordcount=="convert") then
      process_anyway = true
--  end
--end

function Pandoc(el)
    -- skip metadata, just count body:
    pandoc.walk_block(pandoc.Div(el.blocks), wordcount)
    print(words .. " words in body")
    print(characters .. " characters in body")
    print(characters_and_spaces .. " characters in body (including spaces)")
    if not process_anyway then
      os.exit(0)
    end
  end

空城之時有危險 2025-01-25 12:02:46

问题在于过滤器停止转换过程,因此未创建输出。

我假设您正在使用WordCount来自 https:// github。 com/pandoc/lua-filters 。该过滤器将中止文档转换,除非 元数据字段wordCount设置为字符串Processconvert

因此,您可以添加-Metadata = WordCount = Process pandoc_args设置:

    pandoc_args: 
      - --lua-filter=/Users/user/.local/share/pandoc/filters/wordcount.lua
      - --metadata=wordcount=process

或修改过滤器以始终处理文档,无论是否设置了元数据。

The problem is that the filter stops the conversion process, so no output is created.

I'm assuming you are using the wordcount filter from https://github.com/pandoc/lua-filters. That filter will abort the document conversion unless the metadata field wordcount is set to the string process or convert.

So you can add --metadata=wordcount=process this to pandoc_args setting:

    pandoc_args: 
      - --lua-filter=/Users/user/.local/share/pandoc/filters/wordcount.lua
      - --metadata=wordcount=process

or modify the filter to always process the document regardless of whether the metadata field is set or not.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文