Skip to content

Commit

Permalink
Merge branch 'main' of github.com:crsh/papaja
Browse files Browse the repository at this point in the history
  • Loading branch information
crsh committed Oct 11, 2024
2 parents cfcf51e + cd34c78 commit 3bfd0ff
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 30 deletions.
58 changes: 42 additions & 16 deletions inst/lua/docx_fixes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,56 @@ function Header (elem)
return elem
end

function Image (img)
local caption = img.caption
function Figure (fig)
if fig.caption and #fig.caption.long > 0 then

if caption[1] ~= nil then
caption[1] = pandoc.Emph(caption[1])
caption[3] = pandoc.Emph(string.gsub(pandoc.utils.stringify(caption[3]), ":", ". "))
local caption = fig.caption.long[1].content

if #caption >= 4 then
caption[2] = pandoc.Emph(caption[2])
-- Remove the colon from the 4th element (if it's a string)
if caption[4] and pandoc.utils.stringify(caption[4]):match(":") then
caption[4] = pandoc.Str(string.gsub(pandoc.utils.stringify(caption[4]), ":", "."))
end
end

-- Assign the modified caption back to the table
fig.caption.long[1].content = caption
end
return img

-- Return the modified table
return fig
end

function Table (tbl)
local caption = tbl.caption.long[1].content
-- Check if tbl.caption.long is not empty
if tbl.caption and #tbl.caption.long > 0 then

if caption[1] ~= nil then
caption[3] = pandoc.Str(string.gsub(pandoc.utils.stringify(caption[3]), ":", ""))
caption[4] = pandoc.LineBreak()
local caption = tbl.caption.long[1].content

for i = 5, (#caption) do
caption[i] = pandoc.Emph(caption[i])
-- Modify the caption only if there are enough elements
if #caption >= 4 then
-- Remove the colon from the 4th element (if it's a string)
if caption[4] and pandoc.utils.stringify(caption[4]):match(":") then
caption[4] = pandoc.Str(string.gsub(pandoc.utils.stringify(caption[4]), ":", ""))
end

-- Add a line break as the 5th element
if #caption >= 5 then
caption[5] = pandoc.LineBreak()
else
table.insert(caption, 5, pandoc.LineBreak())
end

for i = 6, (#caption) do
caption[i] = pandoc.Emph(caption[i])
end
end
end

tbl.caption.long[1].content = caption
-- Assign the modified caption back to the table
tbl.caption.long[1].content = caption
end

return tbl
-- Return the modified table
return tbl
end

Original file line number Diff line number Diff line change
Expand Up @@ -171,26 +171,34 @@ \subsection{}


$if(csl-refs)$
% definitions for citeproc citations
\NewDocumentCommand\citeproctext{}{}
\NewDocumentCommand\citeproc{mm}{%
\begingroup\def\citeproctext{#2}\cite{#1}\endgroup}
\makeatletter
% allow citations to break across lines
\let\@cite@ofmt\@firstofone
% avoid brackets around text for \cite:
\def\@biblabel#1{}
\def\@cite#1#2{{#1\if@tempswa , #2\fi}}
\makeatother
\newlength{\cslhangindent}
\setlength{\cslhangindent}{1.5em}
\newlength{\csllabelwidth}
\setlength{\csllabelwidth}{3em}
\newenvironment{CSLReferences}[2] % #1 hanging-ident, #2 entry spacing
{% don't indent paragraphs
\setlength{\parindent}{0pt}
\newenvironment{CSLReferences}[2] % #1 hanging-indent, #2 entry-spacing
{\begin{list}{}{%
\setlength{\itemindent}{0pt}
\setlength{\leftmargin}{0pt}
\setlength{\parsep}{0pt}
% turn on hanging indent if param 1 is 1
\ifodd #1 \everypar{\setlength{\hangindent}{\cslhangindent}}\ignorespaces\fi
% set entry spacing
\ifnum #2 > 0
\setlength{\parskip}{#2\baselineskip}
\ifodd #1
\setlength{\leftmargin}{\cslhangindent}
\setlength{\itemindent}{-1\cslhangindent}
\fi
}%
{}
\usepackage{calc}
\newcommand{\CSLBlock}[1]{#1\hfill\break}
\newcommand{\CSLLeftMargin}[1]{\parbox[t]{\csllabelwidth}{#1}}
\newcommand{\CSLRightInline}[1]{\parbox[t]{\linewidth - \csllabelwidth}{#1}\break}
\newcommand{\CSLIndent}[1]{\hspace{\cslhangindent}#1}
% set entry spacing
\setlength{\itemsep}{#2\baselineskip}}}
{\end{list}}
$endif$

\begin{document}
Expand Down

0 comments on commit 3bfd0ff

Please sign in to comment.