Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds default configuration for PDF generation #264

Merged
merged 9 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .sphinx/_static/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -376,3 +376,17 @@ p code.literal {
.highlight .o {
color: #BB5400;
}

.rubric > .hclass2 {
SecondSkoll marked this conversation as resolved.
Show resolved Hide resolved
display: block;
font-size: 2em;
border-radius: .5rem;
font-weight: 300;
line-height: 1.25;
margin-top: 1.75rem;
margin-right: -0.5rem;
margin-bottom: 0.5rem;
margin-left: -0.5rem;
padding-left: .5rem;
padding-right: .5rem;
}
Binary file added .sphinx/fonts/Ubuntu-B.ttf
SecondSkoll marked this conversation as resolved.
Show resolved Hide resolved
Binary file not shown.
Binary file added .sphinx/fonts/Ubuntu-R.ttf
Binary file not shown.
Binary file added .sphinx/fonts/Ubuntu-RI.ttf
Binary file not shown.
Binary file added .sphinx/fonts/UbuntuMono-B.ttf
Binary file not shown.
Binary file added .sphinx/fonts/UbuntuMono-R.ttf
Binary file not shown.
Binary file added .sphinx/fonts/UbuntuMono-RI.ttf
Binary file not shown.
Binary file added .sphinx/images/Canonical-logo-4x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .sphinx/images/front-page-light.pdf
Binary file not shown.
Binary file added .sphinx/images/front-page.png
SecondSkoll marked this conversation as resolved.
Show resolved Hide resolved
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added .sphinx/images/normal-page-footer.pdf
Binary file not shown.
29 changes: 27 additions & 2 deletions Makefile.sp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ ADDPREREQS ?=

.PHONY: sp-full-help sp-woke-install sp-pa11y-install sp-install sp-run sp-html \
sp-epub sp-serve sp-clean sp-clean-doc sp-spelling sp-spellcheck sp-linkcheck sp-woke \
sp-pa11y Makefile.sp sp-vale
sp-pa11y sp-pdf-prep-force sp-pdf-prep sp-pdf Makefile.sp sp-vale

sp-full-help: $(VENVDIR)
@. $(VENV); $(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
Expand Down Expand Up @@ -114,7 +114,32 @@ sp-vale: sp-install
@echo ""
@. $(VENV); vale --config "$(SPHINXDIR)/vale.ini" --glob='*.{md,txt,rst}' $(TARGET)


sp-pdf-prep: sp-install
@. $(VENV); (dpkg-query -W -f='$${Status}' latexmk 2>/dev/null | grep -c "ok installed" >/dev/null && echo "Package latexmk is installed") || (echo "PDF generation requires the installation of the following packages: latexmk fonts-freefont-otf fonts-ibm-plex texlive-latex-recommended texlive-latex-extra texlive-fonts-recommended texlive-font-utils texlive-lang-cjk texlive-xetex plantuml xindy tex-gyre dvipng" && echo "" && echo "make pdf-prep-force will install these packages" && echo "" && echo "Please be aware these packages will be installed to your system" && false)
ru-fu marked this conversation as resolved.
Show resolved Hide resolved
@. $(VENV); (dpkg-query -W -f='$${Status}' fonts-freefont-otf 2>/dev/null | grep -c "ok installed" >/dev/null && echo "Package fonts-freefont-otf is installed") || (echo "PDF generation requires the installation of the following packages: latexmk fonts-freefont-otf fonts-ibm-plex texlive-latex-recommended texlive-latex-extra texlive-fonts-recommended texlive-font-utils texlive-lang-cjk texlive-xetex plantuml xindy tex-gyre dvipng" && echo "" && echo "make pdf-prep-force will install these packages" && echo "" && echo "Please be aware these packages will be installed to your system" && false)
@. $(VENV); (dpkg-query -W -f='$${Status}' fonts-ibm-plex 2>/dev/null | grep -c "ok installed" >/dev/null && echo "Package fonts-ibm-plex is installed") || (echo "PDF generation requires the installation of the following packages: latexmk fonts-freefont-otf fonts-ibm-plex texlive-latex-recommended texlive-latex-extra texlive-fonts-recommended texlive-font-utils texlive-lang-cjk texlive-xetex plantuml xindy tex-gyre dvipng" && echo "" && echo "make pdf-prep-force will install these packages" && echo "" && echo "Please be aware these packages will be installed to your system" && false)
@. $(VENV); (dpkg-query -W -f='$${Status}' texlive-latex-recommended 2>/dev/null | grep -c "ok installed" >/dev/null && echo "Package texlive-latex-recommended is installed") || (echo "PDF generation requires the installation of the following packages: latexmk fonts-freefont-otf fonts-ibm-plex texlive-latex-recommended texlive-latex-extra texlive-fonts-recommended texlive-font-utils texlive-lang-cjk texlive-xetex plantuml xindy tex-gyre dvipng" && echo "" && echo "make pdf-prep-force will install these packages" && echo "" && echo "Please be aware these packages will be installed to your system" && false)
@. $(VENV); (dpkg-query -W -f='$${Status}' texlive-latex-extra 2>/dev/null | grep -c "ok installed" >/dev/null && echo "Package texlive-latex-extra is installed") || (echo "PDF generation requires the installation of the following packages: latexmk fonts-freefont-otf fonts-ibm-plex texlive-latex-recommended texlive-latex-extra texlive-fonts-recommended texlive-font-utils texlive-lang-cjk texlive-xetex plantuml xindy tex-gyre dvipng" && echo "" && echo "make pdf-prep-force will install these packages" && echo "" && echo "Please be aware these packages will be installed to your system" && false)
@. $(VENV); (dpkg-query -W -f='$${Status}' texlive-fonts-recommended 2>/dev/null | grep -c "ok installed" >/dev/null && echo "Package texlive-fonts-recommended is installed") || (echo "PDF generation requires the installation of the following packages: latexmk fonts-freefont-otf fonts-ibm-plex texlive-latex-recommended texlive-latex-extra texlive-fonts-recommended texlive-font-utils texlive-lang-cjk texlive-xetex plantuml xindy tex-gyre dvipng" && echo "" && echo "make pdf-prep-force will install these packages" && echo "" && echo "Please be aware these packages will be installed to your system" && false)
@. $(VENV); (dpkg-query -W -f='$${Status}' texlive-font-utils 2>/dev/null | grep -c "ok installed" >/dev/null && echo "Package texlive-font-utils is installed") || (echo "PDF generation requires the installation of the following packages: latexmk fonts-freefont-otf fonts-ibm-plex texlive-latex-recommended texlive-latex-extra texlive-fonts-recommended texlive-font-utils texlive-lang-cjk texlive-xetex plantuml xindy tex-gyre dvipng" && echo "" && echo "make pdf-prep-force will install these packages" && echo "" && echo "Please be aware these packages will be installed to your system" && false)
@. $(VENV); (dpkg-query -W -f='$${Status}' texlive-lang-cjk 2>/dev/null | grep -c "ok installed" >/dev/null && echo "Package texlive-lang-cjk is installed") || (echo "PDF generation requires the installation of the following packages: latexmk fonts-freefont-otf fonts-ibm-plex texlive-latex-recommended texlive-latex-extra texlive-fonts-recommended texlive-font-utils texlive-lang-cjk texlive-xetex plantuml xindy tex-gyre dvipng" && echo "" && echo "make pdf-prep-force will install these packages" && echo "" && echo "Please be aware these packages will be installed to your system" && false)
@. $(VENV); (dpkg-query -W -f='$${Status}' texlive-xetex 2>/dev/null | grep -c "ok installed" >/dev/null && echo "Package texlive-xetex is installed") || (echo "PDF generation requires the installation of the following packages: latexmk fonts-freefont-otf fonts-ibm-plex texlive-latex-recommended texlive-latex-extra texlive-fonts-recommended texlive-font-utils texlive-lang-cjk texlive-xetex plantuml xindy tex-gyre dvipng" && echo "" && echo "make pdf-prep-force will install these packages" && echo "" && echo "Please be aware these packages will be installed to your system" && false)
@. $(VENV); (dpkg-query -W -f='$${Status}' plantuml 2>/dev/null | grep -c "ok installed" >/dev/null && echo "Package plantuml is installed") || (echo "PDF generation requires the installation of the following packages: latexmk fonts-freefont-otf fonts-ibm-plex texlive-latex-recommended texlive-latex-extra texlive-fonts-recommended texlive-font-utils texlive-lang-cjk texlive-xetex plantuml xindy tex-gyre dvipng" && echo "" && echo "make pdf-prep-force will install these packages" && echo "" && echo "Please be aware these packages will be installed to your system" && false)
@. $(VENV); (dpkg-query -W -f='$${Status}' xindy 2>/dev/null | grep -c "ok installed" >/dev/null && echo "Package xindy is installed") || (echo "PDF generation requires the installation of the following packages: latexmk fonts-freefont-otf fonts-ibm-plex texlive-latex-recommended texlive-latex-extra texlive-fonts-recommended texlive-font-utils texlive-lang-cjk texlive-xetex plantuml xindy tex-gyre dvipng" && echo "" && echo "make pdf-prep-force will install these packages" && echo "" && echo "Please be aware these packages will be installed to your system" && false)
@. $(VENV); (dpkg-query -W -f='$${Status}' tex-gyre 2>/dev/null | grep -c "ok installed" >/dev/null && echo "Package tex-gyre is installed") || (echo "PDF generation requires the installation of the following packages: latexmk fonts-freefont-otf fonts-ibm-plex texlive-latex-recommended texlive-latex-extra texlive-fonts-recommended texlive-font-utils texlive-lang-cjk texlive-xetex plantuml xindy tex-gyre dvipng" && echo "" && echo "make pdf-prep-force will install these packages" && echo "" && echo "Please be aware these packages will be installed to your system" && false)
@. $(VENV); (dpkg-query -W -f='$${Status}' dvipng 2>/dev/null | grep -c "ok installed" >/dev/null && echo "Package dvipng is installed") || (echo "PDF generation requires the installation of the following packages: latexmk fonts-freefont-otf fonts-ibm-plex texlive-latex-recommended texlive-latex-extra texlive-fonts-recommended texlive-font-utils texlive-lang-cjk texlive-xetex plantuml xindy tex-gyre dvipng" && echo "" && echo "make pdf-prep-force will install these packages" && echo "" && echo "Please be aware these packages will be installed to your system" && false)

sp-pdf-prep-force:
@. $(VENV); apt-get update
ru-fu marked this conversation as resolved.
Show resolved Hide resolved
@. $(VENV); apt-get upgrade -y
@. $(VENV); apt-get install --no-install-recommends -y latexmk fonts-freefont-otf fonts-ibm-plex texlive-latex-recommended texlive-latex-extra texlive-fonts-recommended texlive-font-utils texlive-lang-cjk texlive-xetex plantuml xindy tex-gyre dvipng \
SecondSkoll marked this conversation as resolved.
Show resolved Hide resolved

sp-pdf: sp-pdf-prep
@. $(VENV); sphinx-build -M latexpdf "$(SOURCEDIR)" "_build" $(SPHINXOPTS)
SecondSkoll marked this conversation as resolved.
Show resolved Hide resolved
@. $(VENV); rm ./_build/latex/front-page-light.pdf || true
@. $(VENV); rm ./_build/latex/normal-page-footer.pdf || true
@. $(VENV); find ./_build/latex -name "*.pdf" -exec mv -t ./ {} +
@. $(VENV); rm -r _build
SecondSkoll marked this conversation as resolved.
Show resolved Hide resolved

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
Expand Down
142 changes: 142 additions & 0 deletions custom_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,146 @@
# that you want to link to:
# manpages_url = "https://manpages.ubuntu.com/manpages/noble/en/man{section}/{page}.{section}.html"

############################################################
SecondSkoll marked this conversation as resolved.
Show resolved Hide resolved
### -- Options for PDF output ------------------------------
############################################################
SecondSkoll marked this conversation as resolved.
Show resolved Hide resolved

latex_additional_files = [
"./.sphinx/fonts/Ubuntu-B.ttf",
"./.sphinx/fonts/Ubuntu-R.ttf",
"./.sphinx/fonts/Ubuntu-RI.ttf",
"./.sphinx/fonts/UbuntuMono-R.ttf",
"./.sphinx/fonts/UbuntuMono-RI.ttf",
"./.sphinx/fonts/UbuntuMono-B.ttf",
"./.sphinx/images/Canonical-logo-4x.png",
"./.sphinx/images/front-page-light.pdf",
"./.sphinx/images/normal-page-footer.pdf",
]

latex_engine = 'xelatex'
latex_show_pagerefs = True
latex_show_urls = 'footnote'
latex_elements = {
'papersize': 'a4paper',
'pointsize': '11pt',
'fncychap': '',
'preamble': r'''
%\usepackage{charter}
%\usepackage[defaultsans]{lato}
%\usepackage{inconsolata}
\setmainfont[UprightFont = *-R, BoldFont = *-B, ItalicFont=*-RI, Extension = .ttf]{Ubuntu}
\setmonofont[UprightFont = *-R, BoldFont = *-B, ItalicFont=*-RI, Extension = .ttf]{UbuntuMono}
\usepackage[most]{tcolorbox}
\tcbuselibrary{breakable}
\usepackage{lastpage}
\usepackage{tabto}
\usepackage{ifthen}
\usepackage{etoolbox}
\usepackage{fancyhdr}
\usepackage{graphicx}
\usepackage{titlesec}
\usepackage{fontspec}
\usepackage{tikz}
\usepackage{changepage}
\usepackage{array}
\usepackage{tabularx}
\definecolor{yellowgreen}{RGB}{154, 205, 50}
\definecolor{title}{RGB}{76, 17, 48}
\definecolor{subtitle}{RGB}{116, 27, 71}
\definecolor{label}{RGB}{119, 41, 100}
\definecolor{copyright}{RGB}{174, 167, 159}
\makeatletter
\def\tcb@finalize@environment{%
\color{.}% hack for xelatex
\tcb@layer@dec%
}
\makeatother
\newenvironment{sphinxclassprompt}{\color{yellowgreen}\setmonofont[Color = 9ACD32, UprightFont = *-R, Extension = .ttf]{UbuntuMono}}{}
\tcbset{enhanced jigsaw, colback=black, fontupper=\color{white}}
\newtcolorbox{termbox}{use color stack, breakable, colupper=white, halign=flush left}
\newenvironment{sphinxclassterminal}{\setmonofont[Color = white, UprightFont = *-R, Extension = .ttf]{UbuntuMono}\sphinxsetup{VerbatimColor={black}}\begin{termbox}}{\end{termbox}}
\newcommand{\dimtorightedge}{%
\dimexpr\paperwidth-1in-\hoffset-\oddsidemargin\relax}
\newcommand{\dimtotop}{%
\dimexpr\height-1in-\voffset-\topmargin-\headheight-\headsep\relax}
\newtoggle{tpage}
\AtBeginEnvironment{titlepage}{\global\toggletrue{tpage}}
\fancypagestyle{plain}{
\fancyhf{}
\fancyfoot[R]{\thepage\ of \pageref*{LastPage}}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
}
\fancypagestyle{normal}{
\fancyhf{}
\fancyfoot[R]{\thepage\ of \pageref*{LastPage}}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
}
\fancypagestyle{titlepage}{%
\fancyhf{}
\fancyfoot[L]{\footnotesize \textcolor{copyright}{© 2024 Canonical Ltd. All rights reserved.}}
}
\newcommand\sphinxbackoftitlepage{\thispagestyle{titlepage}}
\titleformat{\chapter}[block]{\Huge \color{title} \bfseries\filright}{\thechapter .}{1.5ex}{}
\titlespacing{\chapter}{0pt}{0pt}{0pt}
\titleformat{\section}[block]{\huge \bfseries\filright}{\thesection .}{1.5ex}{}
\titlespacing{\section}{0pt}{0pt}{0pt}
\titleformat{\subsection}[block]{\Large \bfseries\filright}{\thesubsection .}{1.5ex}{}
\titlespacing{\subsection}{0pt}{0pt}{0pt}
\setcounter{tocdepth}{1}
\renewcommand\pagenumbering[1]{}
''',
'sphinxsetup': 'verbatimwithframe=false, pre_border-radius=0pt, verbatimvisiblespace=\\phantom{}, verbatimcontinued=\\phantom{}',
'extraclassoptions': 'openany,oneside',
'maketitle': r'''
\begin{titlepage}
\begin{flushleft}
\begin{tikzpicture}[remember picture,overlay]
\node[anchor=south east, inner sep=0] at (current page.south east) {
\includegraphics[width=\paperwidth, height=\paperheight]{front-page-light}
};
\end{tikzpicture}
\end{flushleft}

\vspace*{3cm}

\begin{adjustwidth}{8cm}{0pt}
\begin{flushleft}
\huge \textcolor{black}{\textbf{}{\raggedright{''' + project + r'''}}}
\end{flushleft}
\end{adjustwidth}

\vfill

\begin{adjustwidth}{8cm}{0pt}
\begin{tabularx}{0.5\textwidth}{ l l }
\textcolor{lightgray}{© 2024 Canonical Ltd.} & \hspace{3cm} \\
\textcolor{lightgray}{All rights reserved.} & \hspace{3cm} \\
& \hspace{3cm} \\
& \hspace{3cm} \\

\end{tabularx}
\end{adjustwidth}

\end{titlepage}
\RemoveFromHook{shipout/background}
\AddToHook{shipout/background}{
\begin{tikzpicture}[remember picture,overlay]
\node[anchor=south west, align=left, inner sep=0] at (current page.south west) {
\includegraphics[width=\paperwidth]{normal-page-footer}
};
\end{tikzpicture}
\begin{tikzpicture}[remember picture,overlay]
\node[anchor=north east, opacity=0.5, inner sep=35] at (current page.north east) {
\includegraphics[width=4cm]{Canonical-logo-4x}
};
\end{tikzpicture}
}
''',
}


############################################################
### Additional configuration
############################################################
Expand All @@ -222,4 +362,6 @@
rst_prolog = '''
.. role:: center
:class: align-center
.. role:: h2
:class: hclass2
'''
2 changes: 2 additions & 0 deletions doc-cheat-sheet.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Also see the `Sphinx reStructuredText Primer <https://www.sphinx-doc.org/en/mast
H2 heading
----------

.. rubric:: :h2:`H2 heading without TOC entry`

H3 heading
~~~~~~~~~~

Expand Down
2 changes: 2 additions & 0 deletions index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ For quick help on reST or MyST syntax, see the :file:`doc-cheat-sheet.rst.txt` o

More information is available in the `reStructuredText style guide`_.

.. rubric:: :h2:`In this documentation`

.. toctree::
:hidden:
:maxdepth: 2
Expand Down
26 changes: 26 additions & 0 deletions readme.rst
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,32 @@ your doc files were placed (repository root or the ``docs`` directory):
make install
make html

Build a PDF
^^^^^^^^^^^

The documentation can build a PDF locally with the following command:
SecondSkoll marked this conversation as resolved.
Show resolved Hide resolved

.. code-block:: none

make pdf

PDF generation requires some system files. If these files are not found, a prompt will be presented and the generation will stop.

Required packages can be installed with:
SecondSkoll marked this conversation as resolved.
Show resolved Hide resolved

.. code-block:: none

make pdf-prep-force

.. note::

When generating a PDF, the index page is considered a 'foreword' and will not be labelled with a chapter.

.. important::

When generating a PDF, it is important to not use additional headings before the ``toctree`` on the index page. Documents referenced by the
SecondSkoll marked this conversation as resolved.
Show resolved Hide resolved
``toctree`` will be nested under any provided headings.
SecondSkoll marked this conversation as resolved.
Show resolved Hide resolved

Configure the documentation
~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down