Skip to content

Commit b5099f6

Browse files
committed
Update journal extensions before running format extension tests
The static journal extensions (acs, elsevier) in tests were frozen at Sept 2023 versions, causing issues with current Quarto including PDF rendering hangs. Modified render-format-extension.test.ts to update extensions from quarto-journals GitHub repos before running tests. Falls back to committed versions on network failure for CI reliability. Updated committed extension files to current versions: - acs: Added fancy-text and latex-environment dependencies - elsevier: Added Lua filter and restructured partials Tests verify format rendering (HTML/PDF/variants) while extension-render-journals.test.ts tests template scaffolding. Both files serve different purposes. Related to #13647 (cherry picked from commit c3149a9)
1 parent 5055ca5 commit b5099f6

File tree

24 files changed

+9957
-1039
lines changed

24 files changed

+9957
-1039
lines changed
Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,30 @@
1-
name: Elsevier Journal Format
1+
title: ACS Journal Format
2+
author: Charles Teague
3+
version: 0.9.2
24
contributes:
3-
format:
5+
formats:
46
common:
57
csl: american-chemical-society.csl
8+
shortcodes:
9+
- fancy-text
10+
filters:
11+
- latex-environment
12+
environments:
13+
- scheme
14+
- chart
15+
- graph
16+
- tocentry
17+
- acknowledgement
18+
- suppinfo
19+
commands:
20+
- ce
21+
html: default
622
pdf:
7-
template-partials: ["doc-class.tex", "title.tex", "print-affiliation.tex"]
23+
cite-method: natbib
24+
biblio-config: false
25+
format-resources:
26+
- achemso.bst
27+
template-partials:
28+
- "doc-class.tex"
29+
- "title.tex"
30+
- "_affiliation.tex"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
title: Fancy Text
2+
author: Posit Software, PBC
3+
version: 1.1.1
4+
quarto-required: ">=1.2.198"
5+
contributes:
6+
shortcodes:
7+
- fancy-text.lua
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
-- shortcode that provides a nicely formatted 'LaTeX' string
2+
function latex()
3+
if quarto.doc.is_format("pdf") then
4+
return pandoc.RawBlock('tex', '{\\LaTeX}')
5+
elseif quarto.doc.is_format("html") then
6+
return pandoc.Math('InlineMath', "\\LaTeX")
7+
else
8+
return pandoc.Span('LaTeX')
9+
end
10+
end
11+
12+
function tex()
13+
if quarto.doc.is_format("pdf") then
14+
return pandoc.RawBlock('tex', '{\\TeX}')
15+
elseif quarto.doc.is_format("html") then
16+
return pandoc.Math('InlineMath', "\\TeX")
17+
else
18+
return pandoc.Span('TeX')
19+
end
20+
end
21+
22+
-- shortcode that provides a nicely formatted 'bibtex' string
23+
function bibtex()
24+
if quarto.doc.is_format("pdf") then
25+
return pandoc.RawBlock('tex', '\\textsc{Bib}{\\TeX}')
26+
elseif quarto.doc.is_format("html") then
27+
return pandoc.RawBlock('html', '<span style="font-variant: small-caps;">Bib</span><span style="letter-spacing:-2px;">T</span><sub style="font-size: inherit; letter-spacing:-1px;">E</sub>X')
28+
else
29+
return pandoc.Span('BibTeX')
30+
end
31+
end
32+
33+
function ldots()
34+
if quarto.doc.is_format("pdf") then
35+
return pandoc.RawBlock('tex', '\\ldots')
36+
elseif quarto.doc.is_format("html") then
37+
return pandoc.RawBlock('html', '&#8230;')
38+
else
39+
return "..."
40+
end
41+
end
42+
43+
function vdots()
44+
if quarto.doc.is_format("pdf") then
45+
return pandoc.Math('InlineMath', "\\vdots")
46+
elseif quarto.doc.is_format("html") then
47+
return pandoc.RawBlock('html', '&#8942;')
48+
else
49+
return "..."
50+
end
51+
end
52+
53+
function ddots()
54+
if quarto.doc.is_format("pdf") then
55+
return pandoc.Math('InlineMath', "\\ddots")
56+
elseif quarto.doc.is_format("html") then
57+
return pandoc.RawBlock('html', '&#8945;')
58+
else
59+
return "..."
60+
end
61+
end
62+
63+
function pct()
64+
local pct
65+
if quarto.doc.is_format("pdf") then
66+
return pandoc.Math('InlineMath', '\\%')
67+
else
68+
return pandoc.Str("%")
69+
end
70+
end
71+
72+
function R2()
73+
if quarto.doc.is_format("pdf") then
74+
return pandoc.Math('InlineMath', "R^2")
75+
else
76+
return {pandoc.Str("R"), pandoc.Superscript("2")}
77+
end
78+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
title: LaTeX Environment
2+
author: Posit Software, PBC
3+
version: 1.2.1
4+
quarto-required: ">=1.3"
5+
contributes:
6+
filters:
7+
- latex-environment.lua
8+
format:
9+
pdf: default
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
-- environment.lua
2+
-- Copyright (C) 2020 by RStudio, PBC
3+
4+
local classEnvironments = pandoc.MetaMap({})
5+
local classCommands = pandoc.MetaMap({})
6+
7+
-- helper that identifies arrays
8+
local function tisarray(t)
9+
local i = 0
10+
for _ in pairs(t) do
11+
i = i + 1
12+
if t[i] == nil then return false end
13+
end
14+
return true
15+
end
16+
17+
-- reads the environments
18+
local function readEnvironments(meta)
19+
local env = meta['environments']
20+
if env ~= nil then
21+
if tisarray(env) then
22+
-- read an array of strings
23+
for i, v in ipairs(env) do
24+
local value = pandoc.utils.stringify(v)
25+
classEnvironments[value] = value
26+
end
27+
else
28+
-- read key value pairs
29+
for k, v in pairs(env) do
30+
local key = pandoc.utils.stringify(k)
31+
local value = pandoc.utils.stringify(v)
32+
classEnvironments[key] = value
33+
end
34+
end
35+
end
36+
end
37+
38+
local function readCommands(meta)
39+
local env = meta['commands']
40+
if env ~= nil then
41+
if tisarray(env) then
42+
-- read an array of strings
43+
for i, v in ipairs(env) do
44+
local value = pandoc.utils.stringify(v)
45+
classCommands[value] = value
46+
end
47+
else
48+
-- read key value pairs
49+
for k, v in pairs(env) do
50+
local key = pandoc.utils.stringify(k)
51+
local value = pandoc.utils.stringify(v)
52+
classCommands[key] = value
53+
end
54+
end
55+
end
56+
end
57+
58+
local function readEnvsAndCommands(meta)
59+
readEnvironments(meta)
60+
readCommands(meta)
61+
end
62+
63+
-- use the environments from metadata to
64+
-- emit a custom environment for latex
65+
local function writeEnvironments(divEl)
66+
if quarto.doc.is_format("latex") then
67+
for k, v in pairs(classEnvironments) do
68+
if divEl.attr.classes:includes(k) then
69+
-- process this into a latex environment
70+
local beginEnv = '\\begin' .. '{' .. v .. '}'
71+
local endEnv = '\n\\end{' .. v .. '}'
72+
73+
-- check if custom options or arguments are present
74+
-- and add them to the environment accordingly
75+
local opts = divEl.attr.attributes['options']
76+
if opts then
77+
beginEnv = beginEnv .. '[' .. opts .. ']'
78+
end
79+
80+
local args = divEl.attr.attributes['arguments']
81+
if args then
82+
beginEnv = beginEnv .. '{' .. args .. '}'
83+
end
84+
85+
-- if the first and last div blocks are paragraphs then we can
86+
-- bring the environment begin/end closer to the content
87+
if #divEl.content > 0 and divEl.content[1].t == "Para" and divEl.content[#divEl.content].t == "Para" then
88+
table.insert(divEl.content[1].content, 1, pandoc.RawInline('tex', beginEnv .. "\n"))
89+
table.insert(divEl.content[#divEl.content].content, pandoc.RawInline('tex', "\n" .. endEnv))
90+
else
91+
table.insert(divEl.content, 1, pandoc.RawBlock('tex', beginEnv))
92+
table.insert(divEl.content, pandoc.RawBlock('tex', endEnv))
93+
end
94+
return divEl
95+
end
96+
end
97+
end
98+
end
99+
100+
local function buildCommandArgs(opts, format)
101+
local function wrap(o)
102+
return string.format(format, o)
103+
end
104+
local t = pandoc.List()
105+
for str in string.gmatch(opts, "([^"..",".."]+)") do
106+
t:insert(str)
107+
end
108+
return table.concat(t:map(wrap), "")
109+
end
110+
111+
-- use the environments from metadata to
112+
-- emit a custom environment for latex
113+
local function writeCommands(spanEl)
114+
if quarto.doc.is_format("latex") then
115+
for k, v in pairs(classCommands) do
116+
if spanEl.attr.classes:includes(k) then
117+
118+
-- resolve the begin command
119+
local beginCommand = '\\' .. pandoc.utils.stringify(v)
120+
local opts = spanEl.attr.attributes['options']
121+
local args = spanEl.attr.attributes['arguments']
122+
if opts then
123+
beginCommand = beginCommand .. buildCommandArgs(opts, "[%s]")
124+
end
125+
if args then
126+
beginCommand = beginCommand .. buildCommandArgs(args, "{%s}")
127+
end
128+
129+
local beginCommandRaw = pandoc.RawInline('latex', beginCommand .. '{')
130+
131+
-- the end command
132+
local endCommandRaw = pandoc.RawInline('latex', '}')
133+
134+
-- attach the raw inlines to the span contents
135+
local result = spanEl.content
136+
table.insert(result, 1, beginCommandRaw)
137+
table.insert(result, endCommandRaw)
138+
139+
return result
140+
end
141+
end
142+
end
143+
end
144+
145+
-- Run in two passes so we process metadata
146+
-- and then process the divs
147+
return {
148+
{ Meta = readEnvsAndCommands },
149+
{ Div = writeEnvironments, Span = writeCommands }
150+
}

0 commit comments

Comments
 (0)