Skip to content

Commit

Permalink
This lua filter will automatically number equations
Browse files Browse the repository at this point in the history
excluding ones with `\nonumber`
  • Loading branch information
Abhi-1U committed Oct 2, 2023
1 parent 3b89ecc commit a3d7489
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions R/article-tools.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ convert_to_markdown <- function(article_dir) {
"issue_checker.lua", package = "texor")
wdtable_filter <- system.file(
"widetable_patcher.lua", package = "texor")
auto_num_eq <- system.file(
"auto_number_equations.lua", package = "texor")
pandoc_opt <- c("-s",
"--resource-path", abs_file_path,
"--lua-filter", error_checker_filter,
Expand Down Expand Up @@ -439,6 +441,8 @@ convert_to_native <- function(article_dir) {
"bookdown_ref.lua", package = "texor")
wdtable_filter <- system.file(
"widetable_patcher.lua", package = "texor")
auto_num_eq <- system.file(
"auto_number_equations.lua", package = "texor")
pandoc_opt <- c("-s",
"--resource-path", abs_file_path,
"--lua-filter", abs_filter,
Expand Down
30 changes: 30 additions & 0 deletions inst/auto_number_equations.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
--[[
AutoNumber Equation filter – tries to autonumber equations.
Copyright: © 2023 Abhishek Ulayil
License: MIT – see LICENSE file for details
--]]
equation_counter =1
function Math(el)
if el.mathtype == "DisplayMath" then
if el.text:match('\\#eq:') then
-- skip equation numbering for equations with dedicated labels,
-- but also add them to the tally of equation
equation_counter = equation_counter + 1
return {pandoc.Str("\n"),el,pandoc.Str("\n")}
elseif el.text:match('\\nonumber') then
-- skip numbering equations with \nonumber
return {pandoc.Str("\n"),el,pandoc.Str("\n")}
else
local text = pandoc.utils.stringify(el.text)
-- insert a label to invoke numbering.
html_label = "eq:".. tostring(equation_counter)
--el.text = [[\label{eq:}]] .. tostring(equation_counter) .. [[}]] .. text
el.text = text .. [[ (\#]] .. html_label .. [[)]]
equation_counter = equation_counter + 1
end
return {pandoc.Str("\n"),el,pandoc.Str("\n")}
--return el
else
return el
end
end

0 comments on commit a3d7489

Please sign in to comment.