Skip to content

Commit 5dffbdc

Browse files
committed
latex, template - pandoc now uses partials for LaTeX and split beamer in its own template
This is a breaking change for users who have custom templates. The new templates are more modular and easier to customize, but they now mix Pandoc's partial and Quarto's partials. Changes: - Add an new template logic dedicated to beamer as Pandoc has split beamer in its own template. Aim is to make it easy to update the beamer template in the future. - Add a new LaTeX template that is based on the default template, but it is split into several partials that are provided by Pandoc and by Quarto. - Adapt the update script to use the new partials and to update the beamer template separately. - Add two Quarto partials that are used in the new LaTeX template: `babel-lang.tex` and `biblio-config.tex`. The new organization possibly could break custom format that tweak the `pandoc.tex` partials as it now contains part of the default `common.latex` partial from Pandoc. This means that if you have a custom template that uses `pandoc.tex` you will need to update it to use the new partials.
1 parent 56071dc commit 5dffbdc

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1586
-465
lines changed

package/src/common/update-pandoc.ts

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ async function writePandocTemplates(
198198
);
199199
const latexOutdir = join(formatSrcDir, "pdf", "pandoc");
200200
const revealOutdir = join(formatSrcDir, "revealjs", "pandoc");
201+
const beamerOutdir = join(formatSrcDir, "beamer", "pandoc");
201202
const asciidocOutdir = join(formatSrcDir, "asciidoc", "pandoc");
202203
const typstOutdir = join(formatSrcDir, "typst", "pandoc");
203204

@@ -219,12 +220,25 @@ async function writePandocTemplates(
219220
],
220221
[latexOutdir]: [
221222
{ from: "default.latex", to: "latex.template" },
223+
// Template we need to tweak
222224
{ from: "common.latex", to: "latex.common" },
223-
{ from: "after-header-includes.latex", to: "latex.after-header-includes" },
224-
{ from: "font-settings.latex", to: "latex.font-settings" },
225-
{ from: "fonts.latex", to: "latex.fonts" },
226-
{ from: "hypersetup.latex", to: "latex.hypersetup" },
227-
{ from: "passoptions.latex", to: "latex.passoptions" },
225+
// Template kept unchanged
226+
{ from: "after-header-includes.latex" },
227+
{ from: "hypersetup.latex" },
228+
{ from: "font-settings.latex" },
229+
{ from: "fonts.latex" },
230+
{ from: "passoptions.latex" },
231+
],
232+
[beamerOutdir]: [
233+
{ from: "default.beamer", to: "beamer.template" },
234+
// Template we need to tweak
235+
{ from: "common.latex", to: "latex.common" },
236+
// Template kept unchanged
237+
{ from: "after-header-includes.latex" },
238+
{ from: "hypersetup.latex" },
239+
{ from: "font-settings.latex" },
240+
{ from: "fonts.latex" },
241+
{ from: "passoptions.latex" },
228242
],
229243
[asciidocOutdir]: [
230244
{ from: "default.asciidoc", to: "asciidoc.template" },

src/format/pdf/format-pdf.ts

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,12 @@ function createPdfFormat(
232232
}
233233

234234
// Provide a custom template for this format
235-
const partialNames = [
235+
// Partials can be the one from Quarto division
236+
const partialNamesQuarto: string[] = [
237+
"babel-lang",
236238
"before-bib",
237239
"biblio",
240+
"biblio-config",
238241
"citations",
239242
"doc-class",
240243
"graphics",
@@ -247,12 +250,38 @@ function createPdfFormat(
247250
"title",
248251
"toc",
249252
];
250-
extras.templateContext = {
251-
template: formatResourcePath("pdf", "pandoc/template.tex"),
252-
partials: partialNames.map((name) => {
253-
return formatResourcePath("pdf", `pandoc/${name}.tex`);
254-
}),
253+
// or the one from Pandoc division (since Pandoc 3.6.3)
254+
const partialNamesPandoc: string[] = [
255+
"after-header-includes",
256+
"common",
257+
"font-settings",
258+
"fonts",
259+
"hypersetup",
260+
"passoptions",
261+
];
262+
263+
const createTemplateContext = function (
264+
to: string,
265+
partialNamesQuarto: string[],
266+
partialNamesPandoc: string[],
267+
) {
268+
return {
269+
template: formatResourcePath(to, "pandoc/template.tex"),
270+
partials: [
271+
...partialNamesQuarto.map((name) => {
272+
return formatResourcePath(to, `pandoc/${name}.tex`);
273+
}),
274+
...partialNamesPandoc.map((name) => {
275+
return formatResourcePath(to, `pandoc/${name}.latex`);
276+
}),
277+
],
278+
};
255279
};
280+
extras.templateContext = createTemplateContext(
281+
displayName === "Beamer" ? "beamer" : "pdf",
282+
partialNamesQuarto,
283+
partialNamesPandoc,
284+
);
256285

257286
// Don't shift the headings if we see any H1s (we can't shift up any longer)
258287
const hasLevelOneHeadings = await hasL1Headings(markdown);

src/resources/formats/beamer/pandoc/after-body.tex

Whitespace-only changes.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
\usepackage{bookmark}
2+
\IfFileExists{xurl.sty}{\usepackage{xurl}}{} % add URL line breaks if available
3+
\urlstyle{$if(urlstyle)$$urlstyle$$else$same$endif$}
4+
$if(links-as-notes)$
5+
% Make links footnotes instead of hotlinks:
6+
\DeclareRobustCommand{\href}[2]{#2\footnote{\url{#1}}}
7+
$endif$
8+
$if(verbatim-in-note)$
9+
\VerbatimFootnotes % allow verbatim text in footnotes
10+
$endif$
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
$--
2+
$-- Babel language support
3+
$--
4+
$if(lang)$
5+
\ifLuaTeX
6+
\usepackage[bidi=basic$for(babeloptions)$,$babeloptions$$endfor$]{babel}
7+
\else
8+
\usepackage[bidi=default$for(babeloptions)$,$babeloptions$$endfor$]{babel}
9+
\fi
10+
$if(babel-lang)$
11+
$if(mainfont)$
12+
\ifPDFTeX
13+
\else
14+
\babelfont{rm}[$for(mainfontoptions)$$mainfontoptions$$sep$,$endfor$$if(mainfontfallback)$,RawFeature={fallback=mainfontfallback}$endif$]{$mainfont$}
15+
\fi
16+
$endif$
17+
$endif$
18+
$for(babelfonts/pairs)$
19+
\babelfont[$babelfonts.key$]{rm}{$babelfonts.value$}
20+
$endfor$
21+
% get rid of language-specific shorthands (see #6817):
22+
\let\LanguageShortHands\languageshorthands
23+
\def\languageshorthands#1{}
24+
$if(selnolig-langs)$
25+
\ifLuaTeX
26+
\usepackage[$for(selnolig-langs)$$it$$sep$,$endfor$]{selnolig} % disable illegal ligatures
27+
\fi
28+
$endif$
29+
$endif$
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
$passoptions.latex()$
2+
\documentclass[
3+
$if(fontsize)$
4+
$fontsize$,
5+
$endif$
6+
ignorenonframetext,
7+
$if(handout)$
8+
handout,
9+
$endif$
10+
$if(aspectratio)$
11+
aspectratio=$aspectratio$,
12+
$endif$
13+
$if(babel-lang)$
14+
$babel-lang$,
15+
$endif$
16+
$for(classoption)$
17+
$classoption$$sep$,
18+
$endfor$
19+
]{$documentclass$}
20+
$if(geometry)$
21+
\geometry{$for(geometry)$$geometry$$sep$,$endfor$}
22+
$endif$
23+
\newif\ifbibliography
24+
$if(background-image)$
25+
\usebackgroundtemplate{%
26+
\includegraphics[width=\paperwidth]{$background-image$}%
27+
}
28+
% In beamer background-image does not work well when other images are used, so this is the workaround
29+
\pgfdeclareimage[width=\paperwidth,height=\paperheight]{background}{$background-image$}
30+
\usebackgroundtemplate{\pgfuseimage{background}}
31+
$endif$
32+
\usepackage{pgfpages}
33+
\setbeamertemplate{caption}[numbered]
34+
\setbeamertemplate{caption label separator}{: }
35+
\setbeamercolor{caption name}{fg=normal text.fg}
36+
\beamertemplatenavigationsymbols$if(navigation)$$navigation$$else$empty$endif$
37+
$--
38+
$-- section numbering
39+
$--
40+
$if(numbersections)$
41+
$else$
42+
% remove section numbering
43+
\setbeamertemplate{part page}{
44+
\centering
45+
\begin{beamercolorbox}[sep=16pt,center]{part title}
46+
\usebeamerfont{part title}\insertpart\par
47+
\end{beamercolorbox}
48+
}
49+
\setbeamertemplate{section page}{
50+
\centering
51+
\begin{beamercolorbox}[sep=12pt,center]{section title}
52+
\usebeamerfont{section title}\insertsection\par
53+
\end{beamercolorbox}
54+
}
55+
\setbeamertemplate{subsection page}{
56+
\centering
57+
\begin{beamercolorbox}[sep=8pt,center]{subsection title}
58+
\usebeamerfont{subsection title}\insertsubsection\par
59+
\end{beamercolorbox}
60+
}
61+
$endif$
62+
$for(beameroption)$
63+
\setbeameroption{$beameroption$}
64+
$endfor$
65+
% Prevent slide breaks in the middle of a paragraph
66+
\widowpenalties 1 10000
67+
\raggedbottom
68+
$if(section-titles)$
69+
\AtBeginPart{
70+
\frame{\partpage}
71+
}
72+
\AtBeginSection{
73+
\ifbibliography
74+
\else
75+
\frame{\sectionpage}
76+
\fi
77+
}
78+
\AtBeginSubsection{
79+
\frame{\subsectionpage}
80+
}
81+
$endif$
82+
$fonts.latex()$
83+
$-- Set Beamer theme before user font settings so they can override theme
84+
$if(theme)$
85+
\usetheme[$for(themeoptions)$$themeoptions$$sep$,$endfor$]{$theme$}
86+
$endif$
87+
$if(colortheme)$
88+
\usecolortheme[$for(colorthemeoptions)$$colorthemeoptions$$sep$,$endfor$]{$colortheme$}
89+
$endif$
90+
$if(fonttheme)$
91+
\usefonttheme[$for(fontthemeoptions)$$fontthemeoptions$$sep$,$endfor$]{$fonttheme$}
92+
$endif$
93+
$if(mainfont)$
94+
\usefonttheme{serif} % use mainfont rather than sansfont for slide text
95+
$endif$
96+
$if(innertheme)$
97+
\useinnertheme[$for(innerthemeoptions)$$innerthemeoptions$$sep$,$endfor$]{$innertheme$}
98+
$endif$
99+
$if(outertheme)$
100+
\useoutertheme[$for(outerthemeoptions)$$outerthemeoptions$$sep$,$endfor$]{$outertheme$}
101+
$endif$
102+
$font-settings.latex()$
103+
$common.latex()$
104+
$for(header-includes)$
105+
$header-includes$
106+
$endfor$
107+
$after-header-includes.latex()$
108+
$hypersetup.latex()$
109+
110+
$if(title)$
111+
\title$if(shorttitle)$[$shorttitle$]$endif${$title$$if(thanks)$\thanks{$thanks$}$endif$}
112+
$endif$
113+
$if(subtitle)$
114+
\subtitle$if(shortsubtitle)$[$shortsubtitle$]$endif${$subtitle$}
115+
$endif$
116+
\author$if(shortauthor)$[$shortauthor$]$endif${$for(author)$$author$$sep$ \and $endfor$}
117+
\date$if(shortdate)$[$shortdate$]$endif${$date$}
118+
$if(institute)$
119+
\institute$if(shortinstitute)$[$shortinstitute$]$endif${$for(institute)$$institute$$sep$ \and $endfor$}
120+
$endif$
121+
$if(titlegraphic)$
122+
\titlegraphic{
123+
$for(titlegraphic)$
124+
\includegraphics$if(titlegraphicoptions)$[$for(titlegraphicoptions)$$titlegraphicoptions$$sep$, $endfor$]$endif${$titlegraphic$}$sep$\enspace
125+
$endfor$}
126+
$endif$
127+
$if(logo)$
128+
\logo{\includegraphics{$logo$}}
129+
$endif$
130+
131+
\begin{document}
132+
$if(title)$
133+
\frame{\titlepage}
134+
$if(abstract)$
135+
\begin{abstract}
136+
$abstract$
137+
\end{abstract}
138+
$endif$
139+
$endif$
140+
141+
$for(include-before)$
142+
$include-before$
143+
144+
$endfor$
145+
$if(toc)$
146+
$if(toc-title)$
147+
\renewcommand*\contentsname{$toc-title$}
148+
$endif$
149+
\begin{frame}[allowframebreaks]
150+
$if(toc-title)$
151+
\frametitle{$toc-title$}
152+
$endif$
153+
\setcounter{tocdepth}{$toc-depth$}
154+
\tableofcontents
155+
\end{frame}
156+
\setcounter{tocdepth}{$toc-depth$}
157+
\tableofcontents
158+
}
159+
$endif$
160+
$if(lof)$
161+
\listoffigures
162+
$endif$
163+
$if(lot)$
164+
\listoftables
165+
$endif$
166+
$if(linestretch)$
167+
\setstretch{$linestretch$}
168+
$endif$
169+
$body$
170+
171+
$if(natbib)$
172+
$if(bibliography)$
173+
$if(biblio-title)$
174+
$if(has-chapters)$
175+
\renewcommand\bibname{$biblio-title$}
176+
$else$
177+
\renewcommand\refname{$biblio-title$}
178+
$endif$
179+
$endif$
180+
\begin{frame}[allowframebreaks]{$biblio-title$}
181+
$if(nocite-ids)$
182+
\nocite{$for(nocite-ids)$$it$$sep$, $endfor$}
183+
$endif$
184+
\bibliographytrue
185+
\bibliography{$for(bibliography)$$bibliography$$sep$,$endfor$}
186+
\end{frame}
187+
188+
$endif$
189+
$endif$
190+
$if(biblatex)$
191+
\begin{frame}[allowframebreaks]{$biblio-title$}
192+
$if(nocite-ids)$
193+
\nocite{$for(nocite-ids)$$it$$sep$, $endfor$}
194+
$endif$
195+
\bibliographytrue
196+
\printbibliography[heading=none]
197+
\end{frame}
198+
199+
$endif$
200+
$for(include-after)$
201+
$include-after$
202+
203+
$endfor$
204+
\end{document}

src/resources/formats/beamer/pandoc/before-bib.tex

Whitespace-only changes.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
$if(title)$
2+
\frame{\titlepage}
3+
$if(abstract)$
4+
\begin{abstract}
5+
$abstract$
6+
\end{abstract}
7+
$endif$
8+
$endif$

src/resources/formats/beamer/pandoc/before-title.tex

Whitespace-only changes.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
$--
2+
$-- bibliography support support for natbib and biblatex
3+
$--
4+
5+
$-- biblio-config: false will not emit the bibliography configuration.
6+
$-- This is useful if the bibliography configuration is already handled by a class file, for example.
7+
$if(biblio-config)$ $-- <-- QUARTO ONLY VARIABLE
8+
$if(natbib)$
9+
\usepackage[$natbiboptions$]{natbib}
10+
\bibliographystyle{$if(biblio-style)$$biblio-style$$else$plainnat$endif$}
11+
$endif$
12+
$if(biblatex)$
13+
\usepackage[$if(biblio-style)$style=$biblio-style$,$endif$$for(biblatexoptions)$$biblatexoptions$$sep$,$endfor$]{biblatex}
14+
$for(bibliography)$
15+
\addbibresource{$bibliography$}
16+
$endfor$
17+
$endif$
18+
$endif$

0 commit comments

Comments
 (0)