Skip to content

Commit

Permalink
Merge pull request #14 from CLRafaelR/optional-samepage
Browse files Browse the repository at this point in the history
Make samepage optional
  • Loading branch information
cysouw authored Oct 7, 2022
2 parents 2a1e55a + c57d2f6 commit 04ad638
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 24 deletions.
Binary file modified docs/readme.docx
Binary file not shown.
Binary file modified docs/readme.epub
Binary file not shown.
3 changes: 2 additions & 1 deletion docs/readme.html
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ <h2 data-number="4.2" id="interlinear-examples"><span class="header-section-numb
<li>The formatting of the interlinear is harmonised.</li>
</ul>
<!-- -->
<pre><code>::: {.ex formatGloss=true}
<pre><code>::: {.ex formatGloss=true samePage=false}
Completely superfluous preamble, but it works ...

a. Mixing single line examples with interlinear examples.
Expand Down Expand Up @@ -736,6 +736,7 @@ <h3 data-number="4.4.1" id="global-options"><span class="header-section-number">
<p>The following global options are available with <code>pandoc-ling</code>. These can be added to the <a href="https://pandoc.org/MANUAL.html#metadata-blocks">Pandoc metadata</a>. An example of such metadata can be found at the bottom of this <code>readme</code> in the form of a YAML-block. Pandoc allows for various methods to provide metadata (see the link above).</p>
<ul>
<li><strong><code>formatGloss</code></strong> (boolean, default <code>false</code>): should all interlinear examples be consistently formatted? If you use this option, you can simply use capital letters for abbreviations in the gloss, and they will be changed to small caps. The source line is set to italics, and the translations is put into single quotes.</li>
<li><strong><code>samePage</code></strong> (boolean, default <code>true</code>, only for Latex): should examples be kept together on the same page? Can also be overriden for individual examples by adding <code>{.ex samePage=false}</code> at the start of an example (cf. below on <code>local options</code>).</li>
<li><strong><code>xrefSuffixSep</code></strong> (string, defaults to no-break-space): When cross references have a suffix, how should the separator be formatted? The defaults ‘no-break-space’ is a safe options. I personally like a ‘narrow no-break space’ better (Unicode <code>U+202F</code>), but this symbol does not work with all fonts, and might thus lead to errors. For Latex typesetting, all space-like symbols are converted to a Latex thin space <code>\,</code>.</li>
<li><strong><code>restartAtChapter</code></strong> (boolean, default <code>false</code>): should the counting restart for each chapter?
<ul>
Expand Down
Binary file modified docs/readme_expex.pdf
Binary file not shown.
10 changes: 7 additions & 3 deletions docs/readme_expex.tex
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ \subsection{Interlinear examples}\label{interlinear-examples}}
\end{itemize}

\begin{verbatim}
::: {.ex formatGloss=true}
::: {.ex formatGloss=true samePage=false}
Completely superfluous preamble, but it works ...
a. Mixing single line examples with interlinear examples.
Expand All @@ -582,7 +582,6 @@ \subsection{Interlinear examples}\label{interlinear-examples}}
:::
\end{verbatim}

\begin{samepage}
\pex[*=:–)]<ex12> Completely superfluous preamble, but it works
\ldots{}\\
\a Mixing single line examples with interlinear examples.
Expand All @@ -605,7 +604,6 @@ \subsection{Interlinear examples}\label{interlinear-examples}}
\glft `This second sentence does not have a header.'//
\endgl
\xe
\end{samepage}

\hypertarget{cross-referencing-examples}{%
\subsection{Cross-referencing
Expand Down Expand Up @@ -704,6 +702,12 @@ \subsubsection{Global options}\label{global-options}}
this option, you can simply use capital letters for abbreviations in
the gloss, and they will be changed to small caps. The source line is
set to italics, and the translations is put into single quotes.
\item
\textbf{\texttt{samePage}} (boolean, default \texttt{true}, only for
Latex): should examples be kept together on the same page? Can also be
overriden for individual examples by adding
\texttt{\{.ex\ samePage=false\}} at the start of an example (cf.~below
on \texttt{local\ options}).
\item
\textbf{\texttt{xrefSuffixSep}} (string, defaults to no-break-space):
When cross references have a suffix, how should the separator be
Expand Down
Binary file modified docs/readme_gb4e.pdf
Binary file not shown.
10 changes: 7 additions & 3 deletions docs/readme_gb4e.tex
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ \subsection{Interlinear examples}\label{interlinear-examples}}
\end{itemize}

\begin{verbatim}
::: {.ex formatGloss=true}
::: {.ex formatGloss=true samePage=false}
Completely superfluous preamble, but it works ...
a. Mixing single line examples with interlinear examples.
Expand All @@ -601,7 +601,6 @@ \subsection{Interlinear examples}\label{interlinear-examples}}
:::
\end{verbatim}

\begin{samepage}
\begin{exe} \judgewidth{:–)}
\ex Completely superfluous preamble, but it works \ldots{}
\begin{xlist}
Expand All @@ -623,7 +622,6 @@ \subsection{Interlinear examples}\label{interlinear-examples}}
\end{xlist}
\label{ex4.12}
\end{exe}
\end{samepage}

\hypertarget{cross-referencing-examples}{%
\subsection{Cross-referencing
Expand Down Expand Up @@ -723,6 +721,12 @@ \subsubsection{Global options}\label{global-options}}
this option, you can simply use capital letters for abbreviations in
the gloss, and they will be changed to small caps. The source line is
set to italics, and the translations is put into single quotes.
\item
\textbf{\texttt{samePage}} (boolean, default \texttt{true}, only for
Latex): should examples be kept together on the same page? Can also be
overriden for individual examples by adding
\texttt{\{.ex\ samePage=false\}} at the start of an example (cf.~below
on \texttt{local\ options}).
\item
\textbf{\texttt{xrefSuffixSep}} (string, defaults to no-break-space):
When cross references have a suffix, how should the separator be
Expand Down
Binary file modified docs/readme_langsci-gb4e.pdf
Binary file not shown.
10 changes: 7 additions & 3 deletions docs/readme_langsci-gb4e.tex
Original file line number Diff line number Diff line change
Expand Up @@ -557,7 +557,7 @@ \subsection{Interlinear examples}\label{interlinear-examples}}
\end{itemize}

\begin{verbatim}
::: {.ex formatGloss=true}
::: {.ex formatGloss=true samePage=false}
Completely superfluous preamble, but it works ...
a. Mixing single line examples with interlinear examples.
Expand All @@ -578,7 +578,6 @@ \subsection{Interlinear examples}\label{interlinear-examples}}
:::
\end{verbatim}

\begin{samepage}
\ea \judgewidth{:–)} \label{ex4.12} Completely superfluous preamble, but
it works \ldots{}
\ea [] { Mixing single line examples with interlinear examples. }
Expand All @@ -598,7 +597,6 @@ \subsection{Interlinear examples}\label{interlinear-examples}}
\glt `This second sentence does not have a header.' }
\z
\z
\end{samepage}

\hypertarget{cross-referencing-examples}{%
\subsection{Cross-referencing
Expand Down Expand Up @@ -697,6 +695,12 @@ \subsubsection{Global options}\label{global-options}}
this option, you can simply use capital letters for abbreviations in
the gloss, and they will be changed to small caps. The source line is
set to italics, and the translations is put into single quotes.
\item
\textbf{\texttt{samePage}} (boolean, default \texttt{true}, only for
Latex): should examples be kept together on the same page? Can also be
overriden for individual examples by adding
\texttt{\{.ex\ samePage=false\}} at the start of an example (cf.~below
on \texttt{local\ options}).
\item
\textbf{\texttt{xrefSuffixSep}} (string, defaults to no-break-space):
When cross references have a suffix, how should the separator be
Expand Down
Binary file modified docs/readme_linguex.pdf
Binary file not shown.
12 changes: 7 additions & 5 deletions docs/readme_linguex.tex
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ \subsection{Interlinear examples}\label{interlinear-examples}}
\end{itemize}

\begin{verbatim}
::: {.ex formatGloss=true}
::: {.ex formatGloss=true samePage=false}
Completely superfluous preamble, but it works ...
a. Mixing single line examples with interlinear examples.
Expand All @@ -586,8 +586,6 @@ \subsection{Interlinear examples}\label{interlinear-examples}}
:::
\end{verbatim}

\begin{samepage}

\ex. \label{ex4.12} Completely superfluous preamble, but it works
\ldots{}
\a. Mixing single line examples with interlinear examples.
Expand All @@ -605,8 +603,6 @@ \subsection{Interlinear examples}\label{interlinear-examples}}
header. \\
\glt `This second sentence does not have a header.'

\end{samepage}

\hypertarget{cross-referencing-examples}{%
\subsection{Cross-referencing
examples}\label{cross-referencing-examples}}
Expand Down Expand Up @@ -705,6 +701,12 @@ \subsubsection{Global options}\label{global-options}}
this option, you can simply use capital letters for abbreviations in
the gloss, and they will be changed to small caps. The source line is
set to italics, and the translations is put into single quotes.
\item
\textbf{\texttt{samePage}} (boolean, default \texttt{true}, only for
Latex): should examples be kept together on the same page? Can also be
overriden for individual examples by adding
\texttt{\{.ex\ samePage=false\}} at the start of an example (cf.~below
on \texttt{local\ options}).
\item
\textbf{\texttt{xrefSuffixSep}} (string, defaults to no-break-space):
When cross references have a suffix, how should the separator be
Expand Down
57 changes: 49 additions & 8 deletions pandoc-ling.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ local rev_indexRef = {} -- "reversed" indexRef, i.e. key/value: refID/exID = ord
------------------------------------

local formatGloss = false -- format interlinear examples
local samePage = true -- keep example on one page in Latex
local xrefSuffixSep = " " -- &nbsp; separator to be inserted after number in example references
local restartAtChapter = false -- restart numbering at highest header without adding local chapternumbers
local addChapterNumber = false -- add chapternumbers to counting and restart at highest header
Expand All @@ -49,6 +50,9 @@ function getUserSettings (meta)
if meta.formatGloss ~= nil then
formatGloss = meta.formatGloss
end
if meta.samePage ~= nil then
samePage = meta.samePage
end
if meta.noFormat ~= nil then
noFormat = meta.noFormat
end
Expand Down Expand Up @@ -242,6 +246,11 @@ function processDiv (div)
formatGloss = div.attributes.formatGloss
end

local saveGlobalsamePage = samePage
if div.attributes.samePage ~= nil then
samePage = div.attributes.samePage
end

local saveGlobalnoFormat = noFormat
if div.attributes.noFormat ~= nil then
noFormat = div.attributes.noFormat
Expand Down Expand Up @@ -269,6 +278,7 @@ function processDiv (div)

-- return to global setting
formatGloss = saveGlobalformatGloss
samePage = saveGlobalsamePage
noFormat = saveGlobalnoFormat

return { tmpCite, example }
Expand Down Expand Up @@ -1021,7 +1031,11 @@ function texMakeExpex (parsedDiv)
else
texFront("\\pex"..judgeOffset.."<"..ID.."> ", preamble)
end
texFront("\\begin{samepage}\n", preamble)
if samePage == true then
texFront("\\begin{samepage}\n", preamble)
else
texFront("", preamble)
end

for i=1,#kind do
if kind[i] == "single" then
Expand Down Expand Up @@ -1074,7 +1088,11 @@ function texMakeExpex (parsedDiv)

end
end
texEnd("\n\\xe\n\\end{samepage}", preamble)
if samePage == true then
texEnd("\n\\xe\n\\end{samepage}", preamble)
else
texEnd("\n\\xe", preamble)
end
return pandoc.Plain(preamble)
end

Expand Down Expand Up @@ -1109,7 +1127,11 @@ function texMakeLinguex (parsedDiv)
end

-- build Latex code starting with preamble and adding rest to it
texFront("\\begin{samepage}\n\n\\ex. \\label{"..ID.."} ", preamble)
if samePage == true then
texFront("\\begin{samepage}\n\n\\ex. \\label{"..ID.."} ", preamble)
else
texFront("\n\\ex. \\label{"..ID.."} ", preamble)
end

for i=1,#kind do
if kind[i] == "single" then
Expand Down Expand Up @@ -1162,7 +1184,11 @@ function texMakeLinguex (parsedDiv)

end
end
texEnd("\n\n\\end{samepage}", preamble)
if samePage == true then
texEnd("\n\n\\end{samepage}", preamble)
else
texEnd("\n", preamble)
end
return pandoc.Plain(preamble)
end

Expand Down Expand Up @@ -1204,7 +1230,11 @@ function texMakeGb4e (parsedDiv)
end

-- build Latex code starting with preamble and adding rest to it
if samePage == true then
texFront("\\begin{samepage}\n\\begin{exe} "..judgeOffset.."\n \\ex ", preamble)
else
texFront("\\begin{exe} "..judgeOffset.."\n \\ex ", preamble)
end

for i=1,#kind do
if kind[i] == "single" then
Expand Down Expand Up @@ -1263,7 +1293,11 @@ function texMakeGb4e (parsedDiv)
end
end
if #kind > 1 then texEnd("\n \\end{xlist}", preamble) end
texEnd("\n \\label{"..ID.."}\n\\end{exe}\n\\end{samepage}", preamble)
if samePage == true then
texEnd("\n \\label{"..ID.."}\n\\end{exe}\n\\end{samepage}", preamble)
else
texEnd("\n \\label{"..ID.."}\n\\end{exe}", preamble)
end
return pandoc.Plain(preamble)
end

Expand Down Expand Up @@ -1321,7 +1355,11 @@ function texMakeLangsci (parsedDiv)
else
texFront("\\ea "..judgeOffset.." \\label{"..ID.."} ", preamble)
end
texFront("\\begin{samepage}\n", preamble)
if samePage == true then
texFront("\\begin{samepage}\n", preamble)
else
texFront("", preamble)
end

for i=1,#kind do
if kind[i] == "single" then
Expand Down Expand Up @@ -1386,7 +1424,11 @@ function texMakeLangsci (parsedDiv)
end
end
if #kind > 1 then texEnd("\n \\z", preamble) end
texEnd("\n\\z\n\\end{samepage}", preamble)
if samePage == true then
texEnd("\n\\z\n\\end{samepage}", preamble)
else
texEnd("\n\\z", preamble)
end
return pandoc.Plain(preamble)
end

Expand Down Expand Up @@ -1530,4 +1572,3 @@ return {




3 changes: 2 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ The results of such formatting will not always work, but it seems to be quite ro
- The formatting of the interlinear is harmonised.

```
::: {.ex formatGloss=true}
::: {.ex formatGloss=true samePage=false}
Completely superfluous preamble, but it works ...
a. Mixing single line examples with interlinear examples.
Expand Down Expand Up @@ -230,6 +230,7 @@ I propose to use these ids also to refer to examples in citations when writing s
The following global options are available with `pandoc-ling`. These can be added to the [Pandoc metadata](https://pandoc.org/MANUAL.html#metadata-blocks). An example of such metadata can be found at the bottom of this `readme` in the form of a YAML-block. Pandoc allows for various methods to provide metadata (see the link above).

- **`formatGloss`** (boolean, default `false`): should all interlinear examples be consistently formatted? If you use this option, you can simply use capital letters for abbreviations in the gloss, and they will be changed to small caps. The source line is set to italics, and the translations is put into single quotes.
- **`samePage`** (boolean, default `true`, only for Latex): should examples be kept together on the same page? Can also be overriden for individual examples by adding `{.ex samePage=false}` at the start of an example (cf. below on `local options`).
- **`xrefSuffixSep`** (string, defaults to no-break-space): When cross references have a suffix, how should the separator be formatted? The defaults 'no-break-space' is a safe options. I personally like a 'narrow no-break space' better (Unicode `U+202F`), but this symbol does not work with all fonts, and might thus lead to errors. For Latex typesetting, all space-like symbols are converted to a Latex thin space `\,`.
- **`restartAtChapter`** (boolean, default `false`): should the counting restart for each chapter?
* Actually, when `true` this setting will restart the counting at the highest heading level, which for various output formats can be set by the Pandoc option `top-level-division`.
Expand Down

0 comments on commit 04ad638

Please sign in to comment.