diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..bc49353 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake .# diff --git a/.github/workflows/build_and_release.yml b/.github/workflows/build_and_release.yml index a1fdab5..fd5ee1c 100644 --- a/.github/workflows/build_and_release.yml +++ b/.github/workflows/build_and_release.yml @@ -8,12 +8,14 @@ on: - "**.tex" - "**.yml" - "**.sty" + - "**.nix" branches: [ master ] pull_request: paths: - "**.tex" - "**.yml" - "**.sty" + - "**.nix" branches: [ master ] # A workflow run is made up of one or more jobs that can run sequentially or in parallel @@ -67,6 +69,7 @@ jobs: with: args: fish ./.github/workflows/convert_pdf_to_png.fish if: github.event_name == 'push' + # HERE: Use simple cli logic, maybe script, to push documentation artifacts to external repo with access token - name: Sync docs uses: kai-tub/external-repo-sync-action@v1 with: diff --git a/.github/workflows/convert_pdf_to_png.fish b/.github/workflows/convert_pdf_to_png.fish deleted file mode 100644 index 17f130c..0000000 --- a/.github/workflows/convert_pdf_to_png.fish +++ /dev/null @@ -1,52 +0,0 @@ -#!/bin/fish - -function convert_minimal_examples - set files (find ./minimal_examples -type d -path '*/.git' -prune -o -name '*.pdf' -print) - for file_ in $files - echo "$file_" - set target (string replace '.pdf' '.png' "$file_") - convert -density 500 "$file_"[0] "$target" - end -end - -function convert_compare_examples - set files (find ./compare_examples -type d -path '*/.git' -prune -o -name '*example*.pdf' -print) - - for file_ in $files - echo "$file_" - set convert_target (string replace -r '(.*)\.pdf' '$1-%02d.tmp.png' "$file_") - set montage_source (string replace -r '(.*)\.pdf' '$1-*.png' "$file_") - set montage_target (string replace -r '(.*)\.pdf' '$1.tmp.png' "$file_") - convert -density 300 "$file_" "$convert_target" - montage "$montage_source" -geometry +10+10 -tile 1x -background gray -colorspace RGB "$montage_target" - # maybe next to each other - end - montage ./compare_examples/pureminimalistic_example_dark.tmp.png ./compare_examples/defaultbeamer_example.tmp.png -geometry +2+2 -tile 2x -background gray ./compare_examples/comparison_dark.png - montage ./compare_examples/pureminimalistic_example_light.tmp.png ./compare_examples/defaultbeamer_example.tmp.png -geometry +2+2 -tile 2x -background gray ./compare_examples/comparison_light.png -end - -function convert_multi_lang_examples - set files (find ./multi_lang_examples -type d -path '*/.git' -prune -o -name '*.lua.pdf' -print) - - for file_ in $files - echo "$file_" - set convert_target (string replace -r '(.*)\.pdf' '$1-%02d.tmp.png' "$file_") - set montage_source (string replace -r '(.*)\.pdf' '$1-*.png' "$file_") - set montage_target (string replace -r '(.*)\.pdf' '$1.tmp.png' "$file_") - convert -density 300 "$file_" "$convert_target" - montage "$montage_source" -geometry +10+10 -tile 1x -background gray -colorspace RGB "$montage_target" - end - montage ./multi_lang_examples/*.pdf -geometry +2+2 -tile 2x -background gray ./multi_lang_examples/lang_comparison.png -end - -function convert_demo - convert -density 300 beamertheme-pure-minimalistic-demo.pdf beamertheme-pure-minimalistic-demo-%02d.tmp.png - montage beamertheme-pure-minimalistic-demo-*.png -geometry +10+10 -tile 4x -background gray beamertheme-pure-minimalistic-demo.png -end - -apk add --no-cache imagemagick - -convert_demo -convert_minimal_examples -convert_compare_examples -convert_multi_lang_examples \ No newline at end of file diff --git a/.gitignore b/.gitignore index aaf2a2f..975dc6f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # cannot link to sty for windows support result +.direnv minimal_examples/*.sty minimal_examples/*.pdf minimal_examples/logos diff --git a/compare_examples/defaultbeamer_example.tex b/compare_examples/defaultbeamer_example.tex index 31db499..93fee28 100644 --- a/compare_examples/defaultbeamer_example.tex +++ b/compare_examples/defaultbeamer_example.tex @@ -1,5 +1,5 @@ -\input{common_header_input.tex} +\input{inputs/common_header_input.tex} \begin{document} - \input{common_slides_input.tex} + \input{inputs/common_slides_input.tex} \end{document} diff --git a/compare_examples/common_header_input.tex b/compare_examples/inputs/common_header_input.tex similarity index 100% rename from compare_examples/common_header_input.tex rename to compare_examples/inputs/common_header_input.tex diff --git a/compare_examples/common_slides_input.tex b/compare_examples/inputs/common_slides_input.tex similarity index 100% rename from compare_examples/common_slides_input.tex rename to compare_examples/inputs/common_slides_input.tex diff --git a/compare_examples/pureminimalistic_example_dark.tex b/compare_examples/pureminimalistic_example_dark.tex index e81723a..1a5982a 100644 --- a/compare_examples/pureminimalistic_example_dark.tex +++ b/compare_examples/pureminimalistic_example_dark.tex @@ -1,6 +1,6 @@ -\input{common_header_input.tex} +\input{inputs/common_header_input.tex} \usetheme[darkmode]{pureminimalistic} \begin{document} - \input{common_slides_input.tex} + \input{inputs/common_slides_input.tex} \end{document} diff --git a/compare_examples/pureminimalistic_example_light.tex b/compare_examples/pureminimalistic_example_light.tex index da0bd4f..7d9de91 100644 --- a/compare_examples/pureminimalistic_example_light.tex +++ b/compare_examples/pureminimalistic_example_light.tex @@ -1,6 +1,6 @@ -\input{common_header_input.tex} +\input{inputs/common_header_input.tex} \usetheme{pureminimalistic} \begin{document} - \input{common_slides_input.tex} + \input{inputs/common_slides_input.tex} \end{document} diff --git a/flake.nix b/flake.nix index 66be2f0..a650000 100644 --- a/flake.nix +++ b/flake.nix @@ -15,7 +15,7 @@ } @ inputs: let eachSystem = nixpkgs.lib.genAttrs (import systems); pkgsFor = eachSystem (system: (nixpkgs.legacyPackages.${system}.extend inputs.devshell.overlays.default)); - tex-minimal-deps-builder = texlive-pkg: (texlive-pkg.combine { + tex-deps-builder = texlive-pkg: (texlive-pkg.combine { inherit (texlive-pkg) scheme-small @@ -32,6 +32,16 @@ fontspec infwarerr kvoptions + # only for demo + + biblatex + biber + # only for language examples + + haranoaji + haranoaji-extra + babel + luatexja # without \RequirePackage{lmodern} and without cm-super # Otherwise I was getting errors: 3/bin/pdflatex (file ecss0800): Font ecss0800 at 600 not found @@ -47,10 +57,92 @@ # should probably be call package packages = eachSystem (system: let pkgs = pkgsFor.${system}; - in { - default = pkgs.callPackage nix/minimal_examples.nix { + in rec { + demo-pdflatex = pkgs.callPackage nix/default.nix { + inherit self; + nix-filter = inputs.nix-filter; + tex-deps = tex-deps-builder pkgs.texlive; + tex-directory = "."; + }; + demo-pdflatex-montage = + pkgs.runCommand "demo-pdflatex-pdf" { + src = ./scripts; + buildInputs = [demo-pdflatex pkgs.nushell pkgs.imagemagickBig]; + } '' + mkdir $out + nu --no-history --no-config-file \ + $src/create_pngs.nu create-montage demo \ + --src-dir ${demo-pdflatex} --target-dir $out + ''; + minimal-examples-pdflatex = pkgs.callPackage nix/default.nix { + inherit self; + nix-filter = inputs.nix-filter; + tex-deps = tex-deps-builder pkgs.texlive; + tex-directory = "minimal_examples"; + }; + minimal-examples-lualatex = pkgs.callPackage nix/default.nix { + inherit self; nix-filter = inputs.nix-filter; - tex-deps = tex-minimal-deps-builder pkgs.texlive; + tex-deps = tex-deps-builder pkgs.texlive; + use-lualatex = true; + tex-directory = "minimal_examples"; + }; + minimal-examples-pngs = + pkgs.runCommand "minimal-examples-pngs" { + src = ./scripts; + buildInputs = [minimal-examples-lualatex pkgs.nushell pkgs.imagemagickBig]; + } '' + mkdir $out + nu --no-history --no-config-file \ + $src/create_pngs.nu convert-pdfs-to-pngs \ + --src-dir ${minimal-examples-lualatex} --target-dir $out --density 600 + + ''; + compare-examples = pkgs.callPackage nix/default.nix { + inherit self; + nix-filter = inputs.nix-filter; + tex-deps = tex-deps-builder pkgs.texlive; + use-lualatex = true; + tex-directory = "compare_examples"; + }; + # what is runCommand ? + # just need to call command and provide the given input and output dir! + compare-examples-montage = + pkgs.runCommand "compare-examples-pdf" { + src = ./scripts; + buildInputs = [compare-examples pkgs.nushell pkgs.imagemagickBig]; + } '' + mkdir $out + nu --no-history --no-config-file \ + $src/create_pngs.nu create-montage compare_examples \ + --src-dir ${compare-examples} --target-dir $out + ''; + multi-lang-examples = pkgs.callPackage nix/default.nix { + inherit self; + nix-filter = inputs.nix-filter; + tex-deps = tex-deps-builder pkgs.texlive; + use-lualatex = true; + tex-directory = "multi_lang_examples"; + }; + multi-lang-examples-montage = + pkgs.runCommand "multi-lang-examples-pdf" { + src = ./scripts; + buildInputs = [multi-lang-examples pkgs.nushell pkgs.imagemagickBig]; + } '' + mkdir $out + nu --no-history --no-config-file \ + $src/create_pngs.nu create-montage multi_lang_examples \ + --src-dir ${multi-lang-examples} --target-dir $out + ''; + documentation-artifacts = pkgs.symlinkJoin { + name = "documentation-artifacts"; + paths = [ + multi-lang-examples-montage + compare-examples-montage + demo-pdflatex-montage + minimal-examples-pngs + minimal-examples-lualatex + ]; }; }); devShells = eachSystem ( @@ -59,7 +151,9 @@ in { default = pkgs.devshell.mkShell { packages = [ - (tex-minimal-deps-builder pkgs.texlive) + (tex-deps-builder pkgs.texlive) + pkgs.imagemagickBig + pkgs.fd ]; }; } diff --git a/nix/default.nix b/nix/default.nix new file mode 100644 index 0000000..522c5df --- /dev/null +++ b/nix/default.nix @@ -0,0 +1,76 @@ +{ + self, + lib, + stdenvNoCC, + nix-filter, + coreutils, + findutils, + version ? "git", + tex-deps, + use-lualatex ? false, + use-pdflatex ? true, + tex-directory ? "minimal_examples", +}: +# https://nixos.wiki/wiki/TexLive +# https://flyx.org/nix-flakes-latex/ +stdenvNoCC.mkDerivation rec { + pname = "pure-minimalistic-${tex-directory}"; + inherit version; + + src = nix-filter { + root = ./..; + include = [ + # Include the "src" path relative to the root + (nix-filter.lib.matchExt "sty") + (nix-filter.lib.matchExt "bib") + "logos/" + "${tex-directory}/" + ]; + }; + + # phases = ["unpackPhase" "buildPhase" "installPhase"]; + + buildInputs = [ + tex-deps + coreutils + findutils + # cntr is kinda broken. Requires these utils to be available + # in buildinputs + # cntr + # breakpointHook + # bash + ]; + + # TODO: Figure out how to wrap this in a shellchecker and with correct flags + # -pretex="\pdfvariable suppressoptionalinfo 512\relax" \ # lualatex + buildPhase = + '' + export PATH="${lib.makeBinPath buildInputs}"; + mkdir -p .cache/texmf-var + '' + + lib.optionalString (tex-directory != ".") '' + mv ${tex-directory}/* . + '' + + '' + env TEXMFHOME=.cache TEXMFVAR=.cache/texmf-var \ + SOURCE_DATE_EPOCH=${builtins.toString self.lastModified or 0} \ + latexmk \ + -file-line-error -interaction=nonstopmode \ + -pdf \ + '' + + lib.optionalString use-pdflatex '' + -usepretex='\pdftrailerid{}' \ + '' + + lib.optionalString use-lualatex '' + -lualatex \ + -usepretex='\pdfvariable suppressoptionalinfo 512\relax' \ + '' + + '' + *.tex + ''; + + installPhase = '' + mkdir -p $out + cp *.pdf $out/ + ''; +} diff --git a/nix/minimal_examples.nix b/nix/minimal_examples.nix deleted file mode 100644 index 8587e52..0000000 --- a/nix/minimal_examples.nix +++ /dev/null @@ -1,59 +0,0 @@ -{ - lib, - stdenvNoCC, - nix-filter, - coreutils, - cntr, - bash, - findutils, - version ? "git", - tex-deps, - breakpointHook, -}: -# https://nixos.wiki/wiki/TexLive -# https://flyx.org/nix-flakes-latex/ -stdenvNoCC.mkDerivation rec { - pname = "pure-minimalistic-minimal-examples"; - inherit version; - - src = nix-filter { - root = ./..; - include = [ - # Include the "src" path relative to the root - (nix-filter.lib.matchExt "sty") - (nix-filter.lib.matchExt "bib") - "logos/" - "minimal_examples/" - ]; - }; - - # phases = ["unpackPhase" "buildPhase" "installPhase"]; - - buildInputs = [ - tex-deps - coreutils - findutils - # cntr is kinda broken. Requires these utils to be available - # in buildinputs - # cntr - # breakpointHook - # bash - ]; - - # TODO: Figure out how to wrap this in a shellchecker and with correct flags - buildPhase = '' - export PATH="${lib.makeBinPath buildInputs}"; - mkdir -p .cache/texmf-var - - mv minimal_examples/* . - - env TEXMFHOME=.cache TEXMFVAR=.cache/texmf-var \ - latexmk -pdf -file-line-error -interaction=nonstopmode \ - *.tex - ''; - - installPhase = '' - mkdir -p $out - cp *.pdf $out/ - ''; -} diff --git a/scripts/create_pngs.nu b/scripts/create_pngs.nu new file mode 100644 index 0000000..622cf09 --- /dev/null +++ b/scripts/create_pngs.nu @@ -0,0 +1,72 @@ +#!/usr/bin/env nu + +use std assert + +# how is this called? +# in a wrapping bash script (presumably) +# that provides the paths as arguments that use the environment variables +# from $src and $out ? + +# Convert all PDF files in the `src-dir` to png files, +# where each page of the PDF is converted into a file called +# `-.png` +# Can be used for `minimal_examples` +export def "main convert-pdfs-to-pngs" [ + --src-dir: path + --target-dir: path + --density: int = 300 +]: nothing -> nothing { + cd $src_dir + ls *.pdf | get name | each { + |f| + let stem = $f | path parse | $in.stem + let result_path = $"($target_dir)/($stem)-%02d.png" + ^convert -density $density $f $result_path + } + null +} + +export def "main create-montage compare_examples" [ + --src-dir: path + --target-dir: path +] { + let tmp_dir = mktemp -d + + main convert-pdfs-to-pngs --src-dir $src_dir --target-dir $tmp_dir + print (ls $tmp_dir | table) + let dark_ordered_pngs = (glob $"($tmp_dir)/pureminimalistic_example_dark*.png") | zip (glob $"($tmp_dir)/defaultbeamer_example*.png") | flatten + assert (($dark_ordered_pngs | length) > 0) + let light_ordered_pngs = (glob $"($tmp_dir)/pureminimalistic_example_light*.png") | zip (glob $"($tmp_dir)/defaultbeamer_example*.png") | flatten + assert (($light_ordered_pngs | length) > 0) + ^montage ...$dark_ordered_pngs -geometry +4+4 -tile 2x -background gray -colorspace RGB $"($target_dir)/comparison_dark.png" + ^montage ...$light_ordered_pngs -geometry +4+4 -tile 2x -background gray -colorspace RGB $"($target_dir)/comparison_light.png" + + rm -r $tmp_dir +} + +export def "main create-montage multi_lang_examples" [ + --src-dir: path + --target-dir: path +] { + let tmp_dir = mktemp -d + + main convert-pdfs-to-pngs --src-dir $src_dir --target-dir $tmp_dir + let multi_lang_pngs = (glob $"($tmp_dir)/*.png") + assert (($multi_lang_pngs | length) > 0) + ^montage ...$multi_lang_pngs -geometry +4+4 -tile 2x -background gray -colorspace RGB $"($target_dir)/lang_comparison.png" + + rm -r $tmp_dir +} + +export def "main create-montage demo" [ + --src-dir: path + --target-dir: path +] { + let tmp_dir = mktemp -d + main convert-pdfs-to-pngs --src-dir $src_dir --target-dir $tmp_dir + ^montage ...(glob $"($tmp_dir)/*.png") -geometry +10+10 -tile 4x -background gray $"($target_dir)/beamertheme-pure-minimalistic-demo.png" + + rm -r $tmp_dir +} + +export def main [] {}