Skip to content

Commit

Permalink
Fixes. Issue unicode+regex
Browse files Browse the repository at this point in the history
  • Loading branch information
yves-chevallier committed Aug 15, 2024
1 parent 518e849 commit 47d56bf
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 78 deletions.
11 changes: 6 additions & 5 deletions .latexmkrc
Original file line number Diff line number Diff line change
@@ -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');

Expand All @@ -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';
$clean_ext .= ' %R.ist %R.xdy %R.maf %R.mtc*';
20 changes: 14 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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)
38 changes: 26 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 \
Expand All @@ -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
.PHONY: all serve build clean optimize latex latex-clean docker-image ci update-viewer
20 changes: 12 additions & 8 deletions hooks/latex/renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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}")
Expand Down
26 changes: 13 additions & 13 deletions hooks/latex/templates/template.cls
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
\documentclass[9pt,twoside]{book}
\documentclass[10pt,twoside]{book}
\usepackage{fontspec}
\usepackage{xcolor}
\usepackage{tikz}
Expand Down Expand Up @@ -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},
Expand All @@ -401,8 +401,8 @@
colframe=gray!20,
colback=gray!20,
minted options={%
ignorelexererrors
},
ignorelexererrors
},
rounded corners,
boxrule=0pt,
}{\mintinline{#1}{#2}}
Expand Down Expand Up @@ -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)$) {

Expand Down
1 change: 1 addition & 0 deletions hooks/latex/transformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
from typing import Union

import cairosvg
import pillow_avif # noqa
import pypdf
import requests
import unidecode
Expand Down
12 changes: 2 additions & 10 deletions hooks/mermaid.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
1 change: 0 additions & 1 deletion mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ extra:
- colophon
copy_files:
docs/assets/c-logo.pdf: assets/
tex/.latexmkrc: .
tex/*.sty: .

admonition_translations:
Expand Down
10 changes: 5 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
18 changes: 0 additions & 18 deletions tex/.latexmkrc

This file was deleted.

0 comments on commit 47d56bf

Please sign in to comment.