diff --git a/.latexmkrc b/.latexmkrc index 4d30c929..396949d0 100644 --- a/.latexmkrc +++ b/.latexmkrc @@ -1,10 +1,11 @@ -$pdf_mode = 1; -$pdflatex = 'lualatex -shell-escape %O %S'; - +$pdf_mode = 4; +$bibtex_use = 1; $log_file_mode = 1; - $failure_cmd = 'echo "Error during the compilation of file: %S"'; +set_tex_cmds( '--shell-escape -file-line-error %O %S' ); + + add_cus_dep('glo', 'gls', 0, 'run_makeglossaries'); add_cus_dep('acn', 'acr', 0, 'run_makeglossaries'); @@ -23,4 +24,4 @@ sub run_makeglossaries { push @generated_exts, 'glo', 'gls', 'glg'; push @generated_exts, 'acn', 'acr', 'alg'; -$clean_ext .= ' %R.ist %R.xdy'; \ No newline at end of file +$clean_ext .= ' %R.ist %R.xdy %R.maf %R.mtc*'; \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 5acc10f8..0d2f7fb0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,11 +2,11 @@ FROM kjarosh/latex:2024.2-basic RUN tlmgr update --self --all RUN tlmgr install latexmk fontspec minted babel-french adjustbox capt-of \ - csquotes datatool emptypage enumitem environ epigraph fontawesome5 gensymb \ - glossaries imakeidx listofitems minitoc stackengine tcolorbox titlesec \ - tocloft wasysym booktabs caption euenc filehook lm makecmds microtype \ - parskip ulem unicode-math lualatex-math tikzfill units pdfcol nextpage \ - hyphen-french noto notomath luatexbase + csquotes datatool emptypage enumitem environ epigraph fontawesome5 gensymb \ + glossaries imakeidx listofitems minitoc stackengine tcolorbox titlesec \ + tocloft wasysym booktabs caption euenc filehook lm makecmds microtype \ + parskip ulem unicode-math lualatex-math tikzfill units pdfcol nextpage \ + hyphen-french noto notomath luatexbase RUN apk --no-cache add font-noto font-noto-music font-noto-emoji font-noto-cjk \ font-noto-naskh-arabic font-noto-devanagari font-noto-hebrew font-noto-tamil \ @@ -17,8 +17,16 @@ RUN mkdir -p /usr/share/fonts/truetype/creativecommons && \ -P /usr/share/fonts/truetype/creativecommons RUN apk add --no-cache \ - make ghostscript fontconfig ttf-freefont py3-pygments + make ghostscript fontconfig ttf-freefont py3-pygments ncurses + +RUN mkdir -p /tmp/texmf-cache +ENV TEXMFCACHE=/tmp/texmf-cache +ENV TERM=xterm RUN fc-cache -fv RUN updmap-sys RUN luaotfload-tool -u -v + +RUN chmod -R 777 /tmp/texmf-cache + +#USER $(id -u):$(id -g) diff --git a/Makefile b/Makefile index 7c31c9d2..b9e4ca28 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,12 @@ -BUILD_DIR=build/l-informatique-pour-l-ingenieur +BUILD_DIR=build/book all: poetry run mkdocs build serve: + poetry run mkdocs serve + +servefast: poetry run mkdocs serve --dirty poetry.lock: pyproject.toml @@ -12,9 +15,13 @@ poetry.lock: pyproject.toml build: poetry run mkdocs build -latex: $(BUILD_DIR)/index.tex +latex-clean: + $(RM) -rf $(BUILD_DIR)/_minted-index latexmk -cd $(BUILD_DIR)/index.tex -C - latexmk --shell-escape -pdf -file-line-error -lualatex -cd $(BUILD_DIR)/index.tex + +latex: $(BUILD_DIR)/index.tex | latex-clean + latexmk -cd $(BUILD_DIR)/index.tex -gg -silent \ + -time -logfilewarninglist --interaction=nonstopmode --halt-on-error $(BUILD_DIR)/output-print.pdf: $(BUILD_DIR)/index.pdf gs -sDEVICE=pdfwrite -dPDFSETTINGS=/printer \ @@ -23,19 +30,26 @@ $(BUILD_DIR)/output-print.pdf: $(BUILD_DIR)/index.pdf -dDownsampleMonoImages=true -dColorImageResolution=200 \ -dGrayImageResolution=200 -dMonoImageResolution=200 $< -$(BUILD_DIR)/output-screen.pdf: $(BUILD_DIR)/index.pdf - gs -sDEVICE=pdfwrite -dPDFSETTINGS=/screen \ - -dNOPAUSE -dQUIET -dBATCH -sOutputFile=$@ \ - -dDownsampleColorImages=true -dDownsampleGrayImages=true \ - -dDownsampleMonoImages=true -dColorImageResolution=72 \ - -dGrayImageResolution=72 -dMonoImageResolution=72 $< +docker-image: Dockerfile + docker build -t latex-ycr . + +ci: + docker run -v $(shell pwd):/workspace \ + -w /workspace \ + -u $(shell id -u):$(shell id -g) \ + -v /etc/passwd:/etc/passwd:ro \ + latex-ycr \ + make latex optimize + +update: docs/js/viewer.min.js + poetry update -update-viewer: +docs/js/viewer.min.js: wget https://raw.githubusercontent.com/jgraph/drawio/dev/src/main/webapp/js/viewer.min.js -O docs/js/viewer.min.js optimize: $(BUILD_DIR)/output-print.pdf clean: - rm -rf build site + $(RM) -rf build site __pycache__ _minted-* -.PHONY: all serve build clean optimize \ No newline at end of file +.PHONY: all serve build clean optimize latex latex-clean docker-image ci update-viewer \ No newline at end of file diff --git a/hooks/latex/renderer.py b/hooks/latex/renderer.py index 2e5902ef..761bc531 100644 --- a/hooks/latex/renderer.py +++ b/hooks/latex/renderer.py @@ -162,18 +162,19 @@ def __init__(self, output_path=Path("build"), config={}): def discard_unwanted(self, soup: Tag, **kwargs): unwanted = [ - ("a", ["headerlink", "footnote-backref"], False), - ("a", ["glightbox"], True), - ("div", ["latex-ignore"], False), - ("span", ["exercise-title"], True), - ("div", ["exercise-checkbox"], False), + ("a", ["headerlink", "footnote-backref"], "extract"), + ("a", ["glightbox"], "unwrap"), + ("div", ["latex-ignore"], "extract"), + ("span", ["exercise-title"], "unwrap"), + ("div", ["exercise-checkbox"], "extract"), + ("figure", ["mermaid-figure"], "extract"), ] - for tag, classes, unwrap in unwanted: + for tag, classes, mode in unwanted: for el in soup.find_all(tag, class_=classes): - if unwrap: + if mode == "unwrap": el.unwrap() - else: + elif mode == "extract": el.extract() return soup @@ -385,6 +386,7 @@ def render_mermaid(self, soup: Tag, **kwargs): width = f"{width}mm" self.apply(el, template, path=filename.name, caption=caption, width=width) + return soup def render_epigraph(self, soup: Tag, **kwargs): @@ -728,6 +730,8 @@ def render_tabbed(self, soup: Tag, **kwargs): def render_figure(self, soup: Tag, **kwargs): for figure in soup.find_all(["figure"]): + if get_class(figure, "mermaid-figure"): + continue image = figure.find("img") if not image: raise ValueError(f"Missing image in figure {figure}") diff --git a/hooks/latex/templates/template.cls b/hooks/latex/templates/template.cls index fd18c25f..4537c38b 100644 --- a/hooks/latex/templates/template.cls +++ b/hooks/latex/templates/template.cls @@ -1,4 +1,4 @@ -\documentclass[9pt,twoside]{book} +\documentclass[10pt,twoside]{book} \usepackage{fontspec} \usepackage{xcolor} \usepackage{tikz} @@ -376,14 +376,14 @@ top=1mm, bottom=1mm, minted options={% - tabsize=4, - breaklines, - xleftmargin=-0.75em, - fontsize=\footnotesize, - highlightcolor=gray!30, - ignorelexererrors, - #4 - }, + tabsize=4, + breaklines, + xleftmargin=-0.75em, + fontsize=\footnotesize, + highlightcolor=gray!30, + ignorelexererrors, + #4 + }, coltitle=black, colbacktitle=gray!20!white, title={#3}, @@ -401,8 +401,8 @@ colframe=gray!20, colback=gray!20, minted options={% - ignorelexererrors - }, + ignorelexererrors + }, rounded corners, boxrule=0pt, }{\mintinline{#1}{#2}} @@ -541,8 +541,8 @@ \foreach \i in {2.5,3.3,...,15}{ - \node[rounded corners,\covercolor!60,draw,regular polygon,regular polygon sides=6, minimum size=\i cm,line width=1.4pt,rotate=30] at ($(current page.west)+(4,-5)$) {} ; - }; + \node[rounded corners,\covercolor!60,draw,regular polygon,regular polygon sides=6, minimum size=\i cm,line width=1.4pt,rotate=30] at ($(current page.west)+(4,-5)$) {} ; + }; \node[fill=\covercolor, rounded corners,text =\covercolor!5,regular polygon,regular polygon sides=6, minimum size=5 cm,inner sep=0,line width=1.4pt,rotate=30] at ($(current page.west)+(4,-5)$) { diff --git a/hooks/latex/transformers.py b/hooks/latex/transformers.py index 0d370042..000da3c0 100644 --- a/hooks/latex/transformers.py +++ b/hooks/latex/transformers.py @@ -13,6 +13,7 @@ from typing import Union import cairosvg +import pillow_avif # noqa import pypdf import requests import unidecode diff --git a/hooks/mermaid.py b/hooks/mermaid.py index 9e83fd2e..2a292f99 100644 --- a/hooks/mermaid.py +++ b/hooks/mermaid.py @@ -26,19 +26,11 @@ def on_page_content(html, page, config, files): if not title: continue - figure = Tag(name="figure") + figure = Tag(name="figure", attrs={"class": "mermaid-figure"}) figcaption = Tag(name="figcaption") figcaption.string = title - # Create a copy of the original element - el_copy = Tag(name="pre", attrs={"class": "mermaid"}) - el_copy.string = el.string # Copy the content - - # Append the copied element and the caption to the figure - figure.append(el_copy) + el.wrap(figure) figure.append(figcaption) - # Replace the original element with the new figure - el.replace_with(figure) - return str(soup) diff --git a/mkdocs.yml b/mkdocs.yml index d3435f2c..7d2b9220 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -202,7 +202,6 @@ extra: - colophon copy_files: docs/assets/c-logo.pdf: assets/ - tex/.latexmkrc: . tex/*.sty: . admonition_translations: diff --git a/poetry.lock b/poetry.lock index b7ff7ead..587f37ed 100644 --- a/poetry.lock +++ b/poetry.lock @@ -719,18 +719,18 @@ test = ["flufl.flake8", "importlib-resources (>=1.3)", "jaraco.test (>=5.4)", "p [[package]] name = "importlib-resources" -version = "6.4.0" +version = "6.4.2" description = "Read resources from Python packages" optional = false python-versions = ">=3.8" files = [ - {file = "importlib_resources-6.4.0-py3-none-any.whl", hash = "sha256:50d10f043df931902d4194ea07ec57960f66a80449ff867bfe782b4c486ba78c"}, - {file = "importlib_resources-6.4.0.tar.gz", hash = "sha256:cdb2b453b8046ca4e3798eb1d84f3cce1446a0e8e7b5ef4efb600f19fc398145"}, + {file = "importlib_resources-6.4.2-py3-none-any.whl", hash = "sha256:8bba8c54a8a3afaa1419910845fa26ebd706dc716dd208d9b158b4b6966f5c5c"}, + {file = "importlib_resources-6.4.2.tar.gz", hash = "sha256:6cbfbefc449cc6e2095dd184691b7a12a04f40bc75dd4c55d31c34f174cdf57a"}, ] [package.extras] -docs = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx (<7.2.5)", "sphinx (>=3.5)", "sphinx-lint"] -testing = ["jaraco.test (>=5.4)", "pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-mypy", "pytest-ruff (>=0.2.1)", "zipp (>=3.17)"] +doc = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-lint"] +test = ["jaraco.test (>=5.4)", "pytest (>=6,!=8.1.*)", "pytest-checkdocs (>=2.4)", "pytest-cov", "pytest-enabler (>=2.2)", "pytest-mypy", "pytest-ruff (>=0.2.1)", "zipp (>=3.17)"] [[package]] name = "inflection" diff --git a/pyproject.toml b/pyproject.toml index e73bcc94..a4920d37 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,6 +58,7 @@ mkdocs-plugin-exercises = { git = "https://github.com/yves-chevallier/mkdocs-exe mkdocs-snippets = "^1.3.0" mkdocs-toggle-sidebar-plugin = "^0.0.3" pillow = "^10.4.0" +# until official support has been added (Pillow/pull/5201) pillow-avif-plugin = "^1.4.6" pngquant = "^1.0.8" pydantic = "^2.8.2" diff --git a/tex/.latexmkrc b/tex/.latexmkrc deleted file mode 100644 index 779342c7..00000000 --- a/tex/.latexmkrc +++ /dev/null @@ -1,18 +0,0 @@ -add_cus_dep('glo', 'gls', 0, 'run_makeglossaries'); -add_cus_dep('acn', 'acr', 0, 'run_makeglossaries'); - -sub run_makeglossaries { - my ($base_name, $path) = fileparse( $_[0] ); #handle -outdir param by splitting path and file, ... - pushd $path; # ... cd-ing into folder first, then running makeglossaries ... - - if ( $silent ) { - system "makeglossaries -q '$base_name'"; #unix - # system "makeglossaries", "-q", "$base_name"; #windows - } - else { - system "makeglossaries '$base_name'"; #unix - # system "makeglossaries", "$base_name"; #windows - }; - - popd; # ... and cd-ing back again -} \ No newline at end of file