From 666261a7319de874a960e9e39d189a7b64f69c3c Mon Sep 17 00:00:00 2001 From: Yan Lin Date: Fri, 3 Oct 2025 20:40:37 +0200 Subject: [PATCH] Add tex module --- hosts/darwin/home-default.nix | 10 +++--- hosts/nixos/hs/home.nix | 2 +- hosts/nixos/thinkpad/home.nix | 6 ++-- modules/tex.nix | 68 +++++++++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+), 9 deletions(-) create mode 100644 modules/tex.nix diff --git a/hosts/darwin/home-default.nix b/hosts/darwin/home-default.nix index bb5d33d..f4ed5e9 100644 --- a/hosts/darwin/home-default.nix +++ b/hosts/darwin/home-default.nix @@ -1,11 +1,11 @@ { config, pkgs, nixvim, claude-code, firefox-addons, ... }: { - imports = [ + imports = [ nixvim.homeModules.nixvim - ../../modules/nvim.nix - ../../modules/tmux.nix - ../../modules/zsh.nix + ../../modules/nvim.nix + ../../modules/tmux.nix + ../../modules/zsh.nix ../../modules/ssh.nix ../../modules/git.nix ../../modules/lazygit.nix @@ -19,6 +19,7 @@ ../../modules/dictionary.nix ../../modules/yt-dlp.nix ../../modules/claude-code.nix + ../../modules/tex.nix ../../config/fonts.nix ]; @@ -184,7 +185,6 @@ hidden-bar # Menu bar organizer (macOS-only) # Development and build tools - texlive.combined.scheme-full python312 uv lazysql diff --git a/hosts/nixos/hs/home.nix b/hosts/nixos/hs/home.nix index f72602f..fbcc0f4 100644 --- a/hosts/nixos/hs/home.nix +++ b/hosts/nixos/hs/home.nix @@ -4,6 +4,7 @@ imports = [ ../home-default.nix ../../../modules/syncthing.nix + ../../../modules/tex.nix ]; # hs-specific home configuration @@ -30,7 +31,6 @@ }; home.packages = with pkgs; [ - texlive.combined.scheme-full ]; } diff --git a/hosts/nixos/thinkpad/home.nix b/hosts/nixos/thinkpad/home.nix index 8603081..8195907 100644 --- a/hosts/nixos/thinkpad/home.nix +++ b/hosts/nixos/thinkpad/home.nix @@ -5,12 +5,13 @@ nixpkgs.config.allowUnfree = true; # Import the common NixOS home configuration - imports = [ - ../home-default.nix + imports = [ + ../home-default.nix ../../../modules/firefox.nix ../../../modules/plasma.nix ../../../modules/syncthing.nix ../../../modules/ghostty.nix + ../../../modules/tex.nix plasma-manager.homeModules.plasma-manager ]; @@ -32,7 +33,6 @@ # For example, laptop-specific aliases or scripts home.packages = with pkgs; [ - texlive.combined.scheme-full keepassxc obsidian ]; diff --git a/modules/tex.nix b/modules/tex.nix new file mode 100644 index 0000000..00f9a9e --- /dev/null +++ b/modules/tex.nix @@ -0,0 +1,68 @@ +{ config, pkgs, lib, ... }: + +{ + # Install TeXLive + home.packages = with pkgs; [ + texlive.combined.scheme-full + ]; + + # Shell aliases for LaTeX compilation + programs.zsh.shellAliases = { + # Clean auxiliary LaTeX files + mkpdf-clean = "latexmk -C"; + }; + + # Shell functions for LaTeX compilation + programs.zsh.initContent = '' + # Build PDF with latexmk + # Usage: mkpdf [file.tex] + # If no argument provided, builds all .tex files in current directory + function mkpdf() { + local tex_file="''${1}" + local output_dir="./out" + + if [[ -z "$tex_file" ]]; then + # Build all .tex files in current directory + local tex_files=(*.tex) + if [[ ''${#tex_files[@]} -eq 0 ]] || [[ ! -f "''${tex_files[0]}" ]]; then + echo "No .tex files found in current directory" + return 1 + fi + + for file in "''${tex_files[@]}"; do + echo "Building $file..." + latexmk -pdf -bibtex -shell-escape -interaction=nonstopmode \ + -output-directory="$output_dir" -f "$file" + done + else + if [[ ! -f "$tex_file" ]]; then + echo "File not found: $tex_file" + return 1 + fi + + latexmk -pdf -bibtex -shell-escape -interaction=nonstopmode \ + -output-directory="$output_dir" -f "$tex_file" + fi + } + + # Continuous compilation mode - watch and auto-rebuild + # Usage: mkpdf-watch + function mkpdf-watch() { + local tex_file="''${1}" + local output_dir="./out" + + if [[ -z "$tex_file" ]]; then + echo "Usage: mkpdf-watch " + return 1 + fi + + if [[ ! -f "$tex_file" ]]; then + echo "File not found: $tex_file" + return 1 + fi + + latexmk -pdf -pvc -view=none -shell-escape -interaction=nonstopmode \ + -output-directory="$output_dir" -f "$tex_file" + } + ''; +}