diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2024-06-10 14:09:41 +0100 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2024-06-10 14:09:41 +0100 |
commit | d5f4b967422ed898d15aa5941f777155ddb3e3c5 (patch) | |
tree | 83c0c34e47c4e707fea6b1316bc4a3408485446f | |
parent | 0f0f4bbd9c6cba0fbf196de47e2baed7741391c3 (diff) | |
download | bookup-d5f4b967422ed898d15aa5941f777155ddb3e3c5.tar.gz bookup-d5f4b967422ed898d15aa5941f777155ddb3e3c5.tar.bz2 |
Feat: towards localization support
-rw-r--r-- | ChangeLog.md | 6 | ||||
-rw-r--r-- | TODO.md | 9 | ||||
-rw-r--r-- | _output.yml | 6 | ||||
-rwxr-xr-x | bin/compile-book | 13 | ||||
-rwxr-xr-x | bin/compile-notes | 13 | ||||
-rw-r--r-- | structure/book/en/00-header.tex (renamed from structure/book/00-header.tex) | 0 | ||||
-rw-r--r-- | structure/book/en/00-header.yml (renamed from structure/book/00-header.yml) | 0 | ||||
-rw-r--r-- | structure/book/en/00-preamble.md | 55 | ||||
-rw-r--r-- | structure/book/en/00-preamble.tex | 59 | ||||
-rw-r--r-- | structure/book/en/99-biblio.md | 9 | ||||
-rw-r--r-- | structure/book/en/99-end.tex | 35 | ||||
-rw-r--r-- | structure/book/pt-br/00-header.tex | 84 | ||||
-rw-r--r-- | structure/book/pt-br/00-header.yml | 45 | ||||
-rw-r--r-- | structure/book/pt-br/00-preamble.md (renamed from structure/book/00-preamble.md) | 0 | ||||
-rw-r--r-- | structure/book/pt-br/00-preamble.tex (renamed from structure/book/00-preamble.tex) | 0 | ||||
-rw-r--r-- | structure/book/pt-br/99-biblio.md (renamed from structure/book/99-biblio.md) | 0 | ||||
-rw-r--r-- | structure/book/pt-br/99-end.tex (renamed from structure/book/99-end.tex) | 0 | ||||
-rw-r--r-- | structure/notes/en/00-header.yml (renamed from structure/notes/00-header.yml) | 0 | ||||
-rw-r--r-- | structure/notes/en/00-preamble.md (renamed from structure/notes/00-preamble.md) | 0 | ||||
-rw-r--r-- | structure/notes/pt-br/00-header.yml | 20 | ||||
-rw-r--r-- | structure/notes/pt-br/00-preamble.md | 32 | ||||
-rw-r--r-- | templates/book/en/references.md | 8 | ||||
-rw-r--r-- | templates/book/pt-br/references.md (renamed from templates/book/references.md) | 0 | ||||
-rw-r--r-- | templates/notes/en/bibliography.md | 1 | ||||
-rw-r--r-- | templates/notes/pt-br/bibliography.md (renamed from templates/notes/bibliography.md) | 0 |
25 files changed, 384 insertions, 11 deletions
diff --git a/ChangeLog.md b/ChangeLog.md index 691474d..119cfa5 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,11 @@ # ChangeLog +## v0.0.8 - unreleased + +* [x] Towards localization support: + * [x] Detect the `lang` YAML parameters and use templates from + `{templates,structure}/{book,notes}/$lang`. + ## v0.0.7 - 2024-06-09 * [x] GitLab CI. @@ -15,10 +15,10 @@ ## Improvements -* [ ] Localization support: - * [ ] By detecting the `lang` YAML parameters and using templates from - `templates/{book,notes}/$lang`. - * [ ] Setup a PO-file workflow for translating the templates. +* [ ] Localization: + * [ ] Compile the `_output.yml` from a template, setting the `includes` + from the appropriate language-based structure files. + * [ ] Setup a PO-file workflow for translating the structure and templates? * [ ] Formats: * [ ] Fix the EPUB output: https://bookdown.org/yihui/bookdown/e-books.html @@ -35,6 +35,7 @@ Possible implementations: https://stackoverflow.com/questions/40735727/create-index-of-definitions-theorems-at-end-of-bookdown-book?rq=4 * [ ] Misc: + * [ ] Merge `structure` and `templates`? * [ ] Suport for a `BASE_URL` environment variable? It would be applied as a template variable in `%%base_url%%` placeholers, allowing the compile material to have links among themselves. diff --git a/_output.yml b/_output.yml index 62874f8..272cbc6 100644 --- a/_output.yml +++ b/_output.yml @@ -76,9 +76,9 @@ bookdown::tufte_book2: template: vendor/bookup/templates/tufte-handout.tex includes: - in_header: vendor/bookup/structure/book/00-header.tex - before_body: vendor/bookup/structure/book/00-preamble.tex - after_body: vendor/bookup/structure/book/99-end.tex + in_header: vendor/bookup/structure/book/pt-br/00-header.tex + before_body: vendor/bookup/structure/book/pt-br/00-preamble.tex + after_body: vendor/bookup/structure/book/pt-br/99-end.tex toc: true toc_depth: 3 #toc_appendix: true diff --git a/bin/compile-book b/bin/compile-book index 2907e98..5c8447a 100755 --- a/bin/compile-book +++ b/bin/compile-book @@ -7,11 +7,20 @@ BASENAME="`basename $0 | sed -e 's/\(.\)/\U\1/'`" DIRNAME="`dirname $0`" BASEDIR="$DIRNAME/.." -STRUCTURE="structure/book" CONTENT="content/sections" OUTPUT="${1:-book}" REVISION="$2" DATE="$3" +LANG="`grep lang _common.yml _book.yml _notes.yml 2> /dev/null | tail -1 | cut -d : -f 3 | sed -e 's/"//g' -e 's/ //g'`" + +# Set the language +if [ -z "$LANG" ]; then + LANG="en" +fi + +# Set structure and templates +STRUCTURE="structure/book/$LANG" +TEMPLATES="templates/book/$LANG" # Remove any dangling output files rm -f $OUTPUT.md $OUTPUT.Rmd @@ -42,7 +51,7 @@ if [ -d "$CONTENT" ]; then find $CONTENT -type f | grep '\.md$' | sort | while read file; do cat $file >> $OUTPUT.md echo "" >> $OUTPUT.md - cat $BASEDIR/templates/book/references.md >> $OUTPUT.md + cat $BASEDIR/$TEMPLATES/references.md >> $OUTPUT.md echo "" >> $OUTPUT.md done fi diff --git a/bin/compile-notes b/bin/compile-notes index 24c98ea..c56c56b 100755 --- a/bin/compile-notes +++ b/bin/compile-notes @@ -7,11 +7,20 @@ BASENAME="`basename $0 | sed -e 's/\(.\)/\U\1/'`" DIRNAME="`dirname $0`" BASEDIR="$DIRNAME/.." -STRUCTURE="structure/notes" CONTENT="content/notes" OUTPUT="${1:-notes}" REVISION="$2" DATE="$3" +LANG="`grep lang _common.yml _book.yml _notes.yml 2> /dev/null | tail -1 | cut -d : -f 3 | sed -e 's/"//g' -e 's/ //g'`" + +# Set the language +if [ -z "$LANG" ]; then + LANG="en" +fi + +# Set structure and templates +STRUCTURE="structure/notes/$LANG" +TEMPLATES="templates/notes/$LANG" # Remove any dangling output files rm -f $OUTPUT.md @@ -46,7 +55,7 @@ if [ -d "$CONTENT" ]; then fi # Bibliography section -cat $BASEDIR/templates/notes/bibliography.md >> $OUTPUT.md +cat $BASEDIR/$TEMPLATES/bibliography.md >> $OUTPUT.md # Revision information sed -i -e "s|%%revision%%|$REVISION|g" -e "s|%%date%%|$DATE|g" $OUTPUT.md diff --git a/structure/book/00-header.tex b/structure/book/en/00-header.tex index ded10bd..ded10bd 100644 --- a/structure/book/00-header.tex +++ b/structure/book/en/00-header.tex diff --git a/structure/book/00-header.yml b/structure/book/en/00-header.yml index 2ad19fe..2ad19fe 100644 --- a/structure/book/00-header.yml +++ b/structure/book/en/00-header.yml diff --git a/structure/book/en/00-preamble.md b/structure/book/en/00-preamble.md new file mode 100644 index 0000000..b11b806 --- /dev/null +++ b/structure/book/en/00-preamble.md @@ -0,0 +1,55 @@ +<!-- Bookdown HTML before-body file --> + +<!-- Hack to generate a proper cover and fix the missing index.html file --> +<!-- See https://stackoverflow.com/questions/58340924/bookdown-generates-index-file-with-a-chapter-title-instead-of-index-html-when --> +<!-- See https://bookdown.org/yihui/rmarkdown-cookbook/document-metadata.html --> +```{r echo=FALSE, results='asis'} +if (knitr::is_html_output()) { + cat('# Start {#index .unnumbered}') + cat("\n") + cat('<img src="images/cover.png">') + cat("\n") + cat("<h2>Sobre</h2>") + cat("\n") + cat('<em>') + cat(readLines('DISCLAIMER'), sep='\n') + cat('</em>') + cat('<br/><br/>') + cat('Living Book - Version <strong><em>') + cat(readLines('.metadata/revision.txt'), sep='\n') + cat('</em></strong> - compiled at <strong><em>') + cat(readLines('.metadata/date.txt'), sep='\n') + cat('</em></strong>.') + cat('<br/>') + cat('Older versions available in the <a href="/archive">archive</a>.') + cat('<br/>') + cat('Notebook available <a href="/notes">here</a>.') + cat('<br/><br/>') + cat(readLines('snippets/project.txt')) + cat(' - ') + cat(readLines('snippets/volume.txt')) + cat('<br/>') + cat('Published by ') + cat(rmarkdown::metadata$publisher) + cat('<br/>') + cat('Published at ') + cat(readLines('snippets/url.txt'), sep='\n') + cat('<br/><br/>') + cat(readLines('snippets/keywords.txt'), sep='\n') + cat("\n") + cat("<h2>Credits</h2>") + cat("\n") + cat(paste(rmarkdown::metadata$title, "<br/>", "Copyleft ©", readLines('.metadata/year.txt'), rmarkdown::metadata$author, readLines('snippets/contact.txt'), sep=' ')) + cat('<br/><br/>') + cat(readLines('LICENSE'), sep='\n') + cat('<br/><br/>') + cat(readLines('snippets/cover.txt'), sep='\n') + cat("<h2>Versão PDF</h2>") + cat("\n") + cat('Download the PDF <a href="book.pdf">here</a>, or browse it below:') + cat("\n") + cat('<br/><br/>') + cat('<embed src="book.pdf" width="100%" height="375" type="application/pdf">') + cat('<br/><br/>') +} +``` diff --git a/structure/book/en/00-preamble.tex b/structure/book/en/00-preamble.tex new file mode 100644 index 0000000..91c84bc --- /dev/null +++ b/structure/book/en/00-preamble.tex @@ -0,0 +1,59 @@ +% Bookdown LaTeX before-body file + +% Front matter +\frontmatter + +% Cover image +% See https://stackoverflow.com/questions/45963505/coverpage-and-copyright-notice-before-title-in-r-bookdown +% https://tex.stackexchange.com/questions/39147/scale-image-to-page-width +% https://stackoverflow.com/questions/1963923/adding-full-page-figures-in-latex-how +\includepdf{images/cover.png} + +% Do not print the default title set in the template +\let\maketitle\oldmaketitle +% Uncomment this to duplicate the book title +% This might also clear the \@title variable +%\maketitle + +% Metadata page +\newpage +\begin{fullwidth} +~\vfill +\thispagestyle{empty} +\setlength{\parindent}{0pt} +\setlength{\parskip}{\baselineskip} +\makeatletter\@title\makeatother + +Copyleft \copyright\ \input{.metadata/year.txt} \thanklessauthor\ \input{snippets/contact.txt} + +\input{LICENSE} + +\input{snippets/keywords.txt} + +\input{snippets/cover.txt} + +% Some \input statements need to be protected +% See https://texfaq.org/FAQ-extrabrace +% https://www.typeerror.org/docs/latex/_005cprotect +\par\smallcaps{\protect\input{snippets/project.txt} - \protect\input{snippets/volume.txt}} + +\par\smallcaps{Published by \thanklesspublisher} + +\par\smallcaps{\protect\input{snippets/url.txt}} + +%\par\textit{First impression, \input{.metadata/year.txt}} +\par Living Book - Version \textit{\textbf{\input{.metadata/revision.txt}}} compiled at \textit{\textbf{\input{.metadata/date.txt}}} +\end{fullwidth} + +% Disclaimer +\newpage +\begin{fullwidth} +~\vfill +\thispagestyle{empty} +\setlength{\parindent}{0pt} +\setlength{\parskip}{\baselineskip} +\textit{\input{DISCLAIMER}} +\end{fullwidth} + +% Start the main matter (normal chapters) +\mainmatter diff --git a/structure/book/en/99-biblio.md b/structure/book/en/99-biblio.md new file mode 100644 index 0000000..83817b6 --- /dev/null +++ b/structure/book/en/99-biblio.md @@ -0,0 +1,9 @@ +\backmatter + +<!-- Neat way to have HTML comments: https://stackoverflow.com/a/43902043 --> +<!-- This seems not to be the case anymore: https://bookdown.org/yihui/bookdown/citations.html --> +<script type="text/html"> +`r if (knitr::is_html_output()) '# Bibliografia'` +</script> + +# Bibliography diff --git a/structure/book/en/99-end.tex b/structure/book/en/99-end.tex new file mode 100644 index 0000000..0cf238b --- /dev/null +++ b/structure/book/en/99-end.tex @@ -0,0 +1,35 @@ +% Bookdown LaTeX footer file + +% Put all indexes in a final chapter +\chapter{Index} + +%Lists of tables, figures, definitions and etimologies. +%Lists of tables and figures. +Lists of tables, figures etc. + +% Print the list of tables +\listoftables + +% Print the list of figures +\listoffigures + +% Print the list of definitions +% See https://latex.org/forum/viewtopic.php?t=17679 +% https://ctan.org/pkg/thmtools +\ifx\BookupListDefinitions\undefined +\else + \renewcommand\listtheoremname{List of Definitions} + \listoftheorems[ignoreall,show={definition}] +\fi + +% Print the list of etimologies +% The "proposition" theorem type is allocated for etimologies in this book +% See the _bookdown.yml at the top-level project folder for more information +\ifx\BookupListEtimologies\undefined +\else + \renewcommand\listtheoremname{List of Etimologies} + \listoftheorems[ignoreall,show={proposition}] +\fi + +% Print the index +\printindex diff --git a/structure/book/pt-br/00-header.tex b/structure/book/pt-br/00-header.tex new file mode 100644 index 0000000..ded10bd --- /dev/null +++ b/structure/book/pt-br/00-header.tex @@ -0,0 +1,84 @@ +% Bookdown LaTeX header file + +% Inclusion of external PDF documents (such as a cover image) +% See https://www.ctan.org/pkg/pdfpages +\usepackage{pdfpages} + +% To properly handle URLs in bibliographies +% See https://tex.stackexchange.com/questions/484176/biblatex-overflowing-url +\usepackage{xurl} + +% PDF bookmarks +% See https://ctan.org/pkg/bookmark +% https://texdoc.org/serve/bookmark.pdf/0 +\usepackage[depth=2]{bookmark} + +% Indexing +% See https://en.wikibooks.org/wiki/LaTeX/Indexing +% https://www.ctan.org/pkg/makeidx +% https://bookdown.org/yihui/bookdown/latex-index.html +%\usepackage{imakeidx} +\usepackage{makeidx} +\makeindex + +% No matter what is said in the docs, this was required +% But maybe because tufte::tufte_book was being used instead of bookdown::tufte_book2 +% So perhaps this is not needed anymore +% See https://bookdown.org/yihui/bookdown/markdown-extensions-by-bookdown.html#theorems +% https://ctan.math.illinois.edu/macros/latex/contrib/thmtools/doc/thmtools-manual.pdf +\usepackage{amsthm,thmtools} + +% Bookdown docs recommends to not mess with this +% See https://bookdown.org/yihui/bookdown/markdown-extensions-by-bookdown.html#theorems +%\newtheorem{definition}{Definição}[chapter] +%\newtheorem{hiphotesis}{Hipótese}[chapter] +%\newtheorem{conjecture}{Conjectura}[chapter] +%\newtheorem{demonstration}{Demonstração}[chapter] +%\newtheorem{etimology}{Etimologia}[chapter] + +% Fix positions of margin notes +% See https://ctan.org/pkg/marginfix +% https://tex.stackexchange.com/questions/119726/horizontal-margins-for-margin-notes-in-the-tufte-classes +% https://tex.stackexchange.com/questions/624033/long-sidenotes-break-marginfix-or-how-to-make-breakable-sidenotes +\usepackage{marginfix} + +% Workaround to theorems work correctly +% Maybe this is not needed anymore +% See https://stackoverflow.com/questions/46942352/r-bookdown-document-with-theorem-does-not-render-when-output-file-is-specified +\let\BeginKnitrBlock\begin \let\EndKnitrBlock\end + +% Set page size +% +% This command conflicts with something and gives an error +%\usepackage[paperwidth=6in, paperheight=9in]{geometry} +% +% This command needs tuning for the margins +%\newgeometry{paperwidth=6in, paperheight=9in} +% +% This also needs tuning +% See https://tex.stackexchange.com/questions/201893/change-paper-size-in-tufte-book-class#380699 +%\newgeometry{ +% % showframe, +% paperwidth=6in, +% paperheight=9in, +% left=0.55in, +% right=0.45in, +% top=.5in, +% bottom=.5in, +% marginparsep=0.25in, +% marginparwidth=0.65in, +% includemp, +% includehead, +% % The text width and height are calculated automatically. +%} +% +% This should work, but we're setting this at 00-header.md +%\newgeometry{b5paper} + +% Coverpage and copyright notice before title in R bookdown +% See https://stackoverflow.com/questions/45963505/coverpage-and-copyright-notice-before-title-in-r-bookdown +\let\oldmaketitle\maketitle +\AtBeginDocument{\let\maketitle\relax} + +% Custom header +\IfFileExists{snippets/header.tex}{\input{snippets/header.tex}}{} diff --git a/structure/book/pt-br/00-header.yml b/structure/book/pt-br/00-header.yml new file mode 100644 index 0000000..2ad19fe --- /dev/null +++ b/structure/book/pt-br/00-header.yml @@ -0,0 +1,45 @@ +# Bookdown YAML header +# See https://bookdown.org/yihui/bookdown/usage.html#usage +# https://bookdown.org/yihui/bookdown/yaml-options.html + +# Site +site: "bookdown::bookdown_site" + +# Automatically generate the list of tables and figures +# These can also be explicitly generated using LaTeX commands +lot: false +lof: false + +# Cover image +#cover-image: "images/cover.png" + +# Fonts +mainfont: "Linux Libertine O" +monofont: "Liberation Mono" + +# Paper size +#papersize: a4paper +#papersize: letterpaper +papersize: b5paper + +# Geometry +#geometry: paperwidth=6in,paperheight=9in + +# Class option +# Use "symmetric" in the classoption if you want margin notes in alternating sides +#classoption: "symmetric,justified" +#classoption: "twoside,symmetric,justified" +classoption: "justified" + +# Header includes +header-includes: + # Support for deeply nested lists + # See https://stackoverflow.com/questions/57945414/too-deeply-nested-at-just-fourth-nesting-level-using-pandoc-with-markdown + - \usepackage{enumitem} + - \setlistdepth{20} + - \renewlist{itemize}{itemize}{20} + - \renewlist{enumerate}{enumerate}{20} + - \setlist[itemize]{label=$\cdot$} + - \setlist[itemize,1]{label=\textbullet} + - \setlist[itemize,2]{label=--} + - \setlist[itemize,3]{label=*} diff --git a/structure/book/00-preamble.md b/structure/book/pt-br/00-preamble.md index f3738c6..f3738c6 100644 --- a/structure/book/00-preamble.md +++ b/structure/book/pt-br/00-preamble.md diff --git a/structure/book/00-preamble.tex b/structure/book/pt-br/00-preamble.tex index d558cc1..d558cc1 100644 --- a/structure/book/00-preamble.tex +++ b/structure/book/pt-br/00-preamble.tex diff --git a/structure/book/99-biblio.md b/structure/book/pt-br/99-biblio.md index c5385cb..c5385cb 100644 --- a/structure/book/99-biblio.md +++ b/structure/book/pt-br/99-biblio.md diff --git a/structure/book/99-end.tex b/structure/book/pt-br/99-end.tex index 1959646..1959646 100644 --- a/structure/book/99-end.tex +++ b/structure/book/pt-br/99-end.tex diff --git a/structure/notes/00-header.yml b/structure/notes/en/00-header.yml index 1404cad..1404cad 100644 --- a/structure/notes/00-header.yml +++ b/structure/notes/en/00-header.yml diff --git a/structure/notes/00-preamble.md b/structure/notes/en/00-preamble.md index 37d097e..37d097e 100644 --- a/structure/notes/00-preamble.md +++ b/structure/notes/en/00-preamble.md diff --git a/structure/notes/pt-br/00-header.yml b/structure/notes/pt-br/00-header.yml new file mode 100644 index 0000000..1404cad --- /dev/null +++ b/structure/notes/pt-br/00-header.yml @@ -0,0 +1,20 @@ +site : "bookdown::bookdown_site" +output: + bookdown::gitbook: + config: + toc: + collapse: section + toolbar: + # Default search indexing is very slow: there's lots of notes to be indexed at each page load + # Because of that, it may be better to disable search by default + #search: no + # Fuse search engine is faster + search: + engine: fuse + sharing: no + fontsettings: + theme: night + family: sans + size: 2 + #split_by: chapter+number + #split_by: section diff --git a/structure/notes/pt-br/00-preamble.md b/structure/notes/pt-br/00-preamble.md new file mode 100644 index 0000000..37d097e --- /dev/null +++ b/structure/notes/pt-br/00-preamble.md @@ -0,0 +1,32 @@ +<!-- Bookdown HTML before-body file --> + +<!-- Hack to generate a proper cover and fix the missing index.html file --> +<!-- See https://stackoverflow.com/questions/58340924/bookdown-generates-index-file-with-a-chapter-title-instead-of-index-html-when --> +<!-- See https://bookdown.org/yihui/rmarkdown-cookbook/document-metadata.html --> +```{r echo=FALSE, results='asis'} +if (knitr::is_html_output()) { + cat('# Início {#index .unnumbered}') + cat("\n") + cat('<img src="images/cover.png">') + cat("\n") + cat("<h2>Sobre</h2>") + cat("\n") + cat('<em>') + cat(readLines('DISCLAIMER'), sep='\n') + cat('</em>') + cat('<br/><br/>') + cat('Cardeno Vivo - Versão <strong><em>') + cat(readLines('.metadata/revision.txt'), sep='\n') + cat('</em></strong> - compilada em <strong><em>') + cat(readLines('.metadata/date.txt'), sep='\n') + cat('</em></strong>.') + cat('<br/><br/>') + cat("\n") + cat("<h2>Créditos</h2>") + cat("\n") + cat(paste(rmarkdown::metadata$title, "<br/>", "Copyleft ©", readLines('.metadata/year.txt'), rmarkdown::metadata$author, readLines('snippets/contact.txt'), sep=' ')) + cat('<br/><br/>') + cat(readLines('LICENSE'), sep='\n') + cat('<br/><br/>') +} +``` diff --git a/templates/book/en/references.md b/templates/book/en/references.md new file mode 100644 index 0000000..ebac3cb --- /dev/null +++ b/templates/book/en/references.md @@ -0,0 +1,8 @@ +<!-- Include the references subsection only in the HTML version --> +```{r echo=FALSE, results='asis'} +if (knitr::is_html_output()) { + cat("## References") + cat("\n") + cat("\n") +} +``` diff --git a/templates/book/references.md b/templates/book/pt-br/references.md index cf028c9..cf028c9 100644 --- a/templates/book/references.md +++ b/templates/book/pt-br/references.md diff --git a/templates/notes/en/bibliography.md b/templates/notes/en/bibliography.md new file mode 100644 index 0000000..b87ff79 --- /dev/null +++ b/templates/notes/en/bibliography.md @@ -0,0 +1 @@ +# Bibliography diff --git a/templates/notes/bibliography.md b/templates/notes/pt-br/bibliography.md index 1c6d0e6..1c6d0e6 100644 --- a/templates/notes/bibliography.md +++ b/templates/notes/pt-br/bibliography.md |