Skip to content

Commit

Permalink
language options
Browse files Browse the repository at this point in the history
  • Loading branch information
wjschne committed Mar 4, 2024
1 parent 51f6007 commit c6866af
Show file tree
Hide file tree
Showing 20 changed files with 566 additions and 57 deletions.
3 changes: 2 additions & 1 deletion .quartoignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ template_manuscript.pdf
site_libs/
_extensions/wjschne/embedpdf/
_extensions/embedpdf/
apa-cv.csl
apa-cv.csl
writing.qmd
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@
- Figure and Tables in .pdf jou mode should fit automatically.
- Typst version that would allow for easy customization

# Version 3.3.1 (2024-03-04)

- Implemented [language
options](https://wjschne.github.io/apaquarto/options.html#language-options)
for internationalization and customization.

# Version 3.3.0 (2024-02-29)

- Added better documentation of [apaquarto template
Expand Down
4 changes: 4 additions & 0 deletions NEWS.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ engine: knitr
- Figure and Tables in .pdf jou mode should fit automatically.
- Typst version that would allow for easy customization

# Version 3.4.0 (2024-03-04)

- Implemented [language options](https://wjschne.github.io/apaquarto/options.html#language-options) for internationalization and customization.

# Version 3.3.0 (2024-02-29)

- Added better documentation of [apaquarto template options](https://wjschne.github.io/apaquarto/)
Expand Down
4 changes: 3 additions & 1 deletion _extensions/wjschne/apaquarto/_extension.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
title: My Document in APA Style, Seventh Edition
author: W. Joel Schneider
version: 3.3.0
version: 3.4.0
quarto-required: ">=1.4.549"
contributes:
formats:
Expand All @@ -16,6 +16,8 @@ contributes:
fig-width: 6.5
fig-height: 6.5
filters:
- at: pre-ast
path: apalanguage.lua
- at: pre-ast
path: apafloatstoend.lua
- at: pre-ast
Expand Down
4 changes: 3 additions & 1 deletion _extensions/wjschne/apaquarto/apa.css
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,6 @@ blockquote p:nth-child(1) {text-indent: 0}
border-bottom: none;
}

.tabwid {padding: 0}
.tabwid {padding: 0}

.Abstract p {text-indent: 0}
19 changes: 16 additions & 3 deletions _extensions/wjschne/apaquarto/apaandcite.lua
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
local andreplacement = "and"

local function get_and(m)
if m.language and m.language["citation-last-author-separator"] then
andreplacement = pandoc.utils.stringify(m.language["citation-last-author-separator"])
end
end

---From Samuel Dodson
---https://github.com/citation-style-language/styles/issues/3748#issuecomment-430871259
function Cite(elem)
local function replace_and(elem)
if elem.citations[1].mode == "AuthorInText" then
elem.content = pandoc.walk_inline(elem, {
Str = function(el)
return pandoc.Str(string.gsub(el.text, "&", "and"))
return pandoc.Str(string.gsub(el.text, "&", andreplacement))
end})
return elem.content
end
return pandoc.Cite(elem.content, elem.citations)
end
end

return {
{ Meta = get_and },
{ Cite = replace_and }
}
32 changes: 29 additions & 3 deletions _extensions/wjschne/apaquarto/apacaption.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
local caption_formatter = function(p)
-- Get names for Figure and Table in language specified in lang field
local figureword = "Figure"
local tableword = "Table"

local function gettablefig(m)
-- Get names for Figure and Table specified in language field
if m.language then
if m.language["crossref-fig-title"] then
figureword = pandoc.utils.stringify(m.language["crossref-fig-title"])
end

if m.language["crossref-tbl-title"] then
tableword = pandoc.utils.stringify(m.language["crossref-tbl-title"])
end
else

end
end

if pandoc.utils.stringify(p.content[1]) == "Figure" or pandoc.utils.stringify(p.content[1]) == "Table" then

-- Format caption
local caption_formatter = function(p)
if pandoc.utils.stringify(p.content[1]) == figureword or pandoc.utils.stringify(p.content[1]) == tableword then
--print(p.content[1])
local figuretitle = pandoc.Para({})
local figurecaption = pandoc.Para({})

Expand All @@ -24,7 +45,7 @@ local caption_formatter = function(p)
end
end

Div = function(div)
local divcaption = function(div)
if div.identifier:find("^tbl%-") or div.identifier:find("^fig%-") then
if FORMAT == "html" then
div.content = div.content:walk {Plain = caption_formatter}
Expand All @@ -38,3 +59,8 @@ Div = function(div)

end

return {
{Meta = gettablefig},
{Div = divcaption}
}

53 changes: 53 additions & 0 deletions _extensions/wjschne/apaquarto/apalanguage.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
-- from quarto-cli/src/resources/pandoc/datadir/init.lua
-- global quarto params
local paramsJson = quarto.base64.decode(os.getenv("QUARTO_FILTER_PARAMS"))
local quartoParams = quarto.json.decode(paramsJson)

local function param(name, default)
local value = quartoParams[name]
if value == nil then
if quartoParams.language then
value = quartoParams.language[name]
end
if value == nil then
value = default
end
end
return value
end

local fields = {
{field = "crossref-fig-title", default = "Figure"},
{field = "crossref-tbl-title", default = "Table"},
{field = "citation-last-author-separator", default = "and"},
{field = "citation-masked-author", default = "Masked Author"},
{field = "citation-masked-title", default = "Masked Title"},
{field = "citation-masked-date", default = "n.d."},
{field = "figure-table-note", default = "Note"},
{field = "section-title-abstract", default = "Abstract"},
{field = "section-title-references", default = "References"},
{field = "title-block-author-note", default = "Author Note"},
{field = "title-block-correspondence-note", default = "Correspondence concerning this article should be addressed to"},
{field = "title-block-keywords", default = "Keywords"},
{field = "title-block-role-introduction", default = "Author roles were classified using the Contributor Role Taxonomy (CRediT; https://credit.niso.org/) as follows:"},
}

Meta = function(m)
if not m.language then
m.language = {}
end

if not m.language["figure-table-note"] then
if param("callout-note-title") then
m.language["figure-table-note"] = param("callout-note-title")
end
end

for i,x in ipairs(fields) do
if not m.language[x.field] then
m.language[x.field] = param(x.field, x.default)
end
end

return m
end
40 changes: 20 additions & 20 deletions _extensions/wjschne/apaquarto/apamasked.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@ local function getmasked(meta)
end


local convert2meta = false
for i, v in ipairs(meta.bibliography or {}) do
if pandoc.utils.type(v) == "Inline" then
convert2meta = true
end
end

if convert2meta then
local orig_bib = meta.bibliography
meta.bibliography = pandoc.MetaList{orig_bib}
end


if meta.bibliography then
local maskedfile = "_extensions/wjschne/apaquarto/maskedbibliography.bib"
meta.bibliography:insert({pandoc.Str(maskedfile)})
else
meta.bibliography = {{pandoc.Str(maskedfile)}}
end
return (meta)
--local convert2meta = false
--for i, v in ipairs(meta.bibliography or {}) do
-- if pandoc.utils.type(v) == "Inline" then
-- convert2meta = true
-- end
--end
--
--if convert2meta then
-- local orig_bib = meta.bibliography
-- meta.bibliography = pandoc.MetaList{orig_bib}
--end
--
--
--if meta.bibliography then
-- local maskedfile = "_extensions/wjschne/apaquarto/maskedbibliography.bib"
-- meta.bibliography:insert({pandoc.Str(maskedfile)})
-- else
-- meta.bibliography = {{pandoc.Str(maskedfile)}}
--end
--return (meta)

end

Expand Down
27 changes: 21 additions & 6 deletions _extensions/wjschne/apaquarto/apanote.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
if FORMAT ~= "latex" then
function Div (elem)
if elem.attributes["apa-note"] then
if FORMAT == "latex" then
return
end

local beginapanote = "Note"

local function getnote(m)
if m.language and m.language["figure-table-note"] then
beginapanote = pandoc.utils.stringify(m.language["figure-table-note"])
end
end

local function apanote(elem)
if elem.attributes["apa-note"] then
hasnote = true
elem.content:walk {
Div = function(div)
Expand All @@ -10,7 +21,7 @@ if FORMAT ~= "latex" then
end
}
if hasnote then
local apanotepara = pandoc.Para({pandoc.Emph(pandoc.Str("Note.")), pandoc.Space()})
local apanotepara = pandoc.Para({pandoc.Emph(pandoc.Str(beginapanote)), pandoc.Str("."),pandoc.Space()})
apanotepara.content:extend(quarto.utils.string_to_inlines(elem.attributes["apa-note"]))
local apanote = pandoc.Div(apanotepara)

Expand All @@ -19,5 +30,9 @@ if FORMAT ~= "latex" then
return {elem, apanote}
end
end
end
end
end

return {
{Meta = getnote},
{Div = apanote}
}
Binary file modified _extensions/wjschne/apaquarto/apaquarto.docx
Binary file not shown.
35 changes: 32 additions & 3 deletions _extensions/wjschne/apaquarto/citeprocr.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

-- Counter for citation
local n_citations = 0

local referenceword = "References"
local maskedauthor = "Masked Citation"
local maskedtitle = "Masked Title"
local maskeddate = "n.d."

return {
--{FloatRefTarget = function(float)},
Expand All @@ -19,6 +22,24 @@ return {
zerocitations = true
end
meta.zerocitations = zerocitations
if meta.language then
if meta.language["section-title-references"] then
referenceword = pandoc.utils.stringify(meta.language["section-title-references"])
end
if meta.language["citation-masked-author"] then
maskedauthor = pandoc.utils.stringify(meta.language["citation-masked-author"])
end
if meta.language["citation-masked-title"] then
maskedtitle = pandoc.utils.stringify(meta.language["citation-masked-title"])
end
if meta.language["citation-masked-source"] then
maskedsource = pandoc.utils.stringify(meta.language["citation-masked-source"])
end
if meta.language["citation-masked-date"] then
maskeddate = pandoc.utils.stringify(meta.language["citation-masked-date"])
end
end

return meta
end

Expand All @@ -32,17 +53,25 @@ return {
},
{
Header = function(h)
if n_citations == 0 and pandoc.utils.stringify(h.content) == "References" then
if n_citations == 0 and pandoc.utils.stringify(h.content) == referenceword then
return {}
end
end
},
{
Pandoc = function(doc)
doc.meta.references = pandoc.utils.references(doc)
maskedref = {
author = pandoc.List:new({ {literal = maskedauthor}}),
id = "maskedreference",
issued = {literal = maskeddate},
title = pandoc.Inlines(maskedtitle),
type = "book"
}
doc.meta.references:insert(maskedref)
doc.meta.bibliography = nil
return pandoc.utils.citeproc(doc)
end
end

}
}
Expand Down
Loading

0 comments on commit c6866af

Please sign in to comment.