drupol / latex-letter

5 stars 0 forks source link

LaTeX Letter

This is a repository of Nix package expressions for creating beautiful letters using Pandoc/LaTeX. Pandoc templates in use are:

  1. Latex letter from Aaron Wolen, using LaTeX letter class.
  2. Custom template adapted from the one of Jens Erat, using LaTeX scrlttr2 class. This template is a mix between the one from Aaron and Jens.

Find an example of letter in the latest release section.

Quick start

You have two options:

  1. Do not start a full project and use nix run to compile a PDF from a Markdown file:
    1. nix run github:drupol/latex-letter#letter -- --output=letter.pdf --from=markdown /path/to/letter.md
    2. nix run github:drupol/latex-letter#letter-scrlttr2 -- --output=letter.pdf --from=markdown /path/to/letter.md
  2. Watch a markdown letter for changes and build on-the-go:
    1. nix run github:drupol/latex-letter#watch-letter -- --output=letter.pdf --from=markdown /path/to/letter.md
    2. nix run github:drupol/latex-letter#watch-letter-scrlttr2 -- --output=letter.pdf --from=markdown /path/to/letter.md
  3. Scaffold a full project from a default template: nix flake new --template github:drupol/latex-letter#default ./my-new-document

Usage

Create a new letter by creating a new project:

nix flake new --template github:drupol/latex-letter#default ./my-new-document

Then go into the new directory:

cd ./my-new-document

Then build the letter:

nix build .#letter

or

nix build .#letter-scrlttr2

Then open the resulting letter in PDF:

open result/letter.pdf

API

This package is contains a flake.nix which exposes its derivations in an overlay.

Exposed derivations:

To use it in your own package, here's a minimum working example:

{
  description = "Simple flake with Pandoc latex letter";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
    flake-utils.url = "github:numtide/flake-utils";
    latex-letter.url = "github:drupol/latex-letter";
  };

  outputs = inputs:
    inputs.flake-utils.lib.eachDefaultSystem (system: let
      pkgs = import inputs.nixpkgs {
        overlays = [inputs.latex-letter.overlays.default];

        inherit system;
      };

      tex = pkgs.texlive.combine {
        inherit (pkgs.texlive) scheme-full latex-bin latexmk;
      };

      pandoc-templates = pkgs.symlinkJoin {
        name = "pandoc-templates";

        paths = [
          pkgs.pandoc-letter-scrlttr2-template
          pkgs.pandoc-letter-template
        ];
      };

      pandoc = pkgs.writeShellApplication {
        name = "pandoc";
        text = ''
          pandoc --data-dir=${pandoc-templates}/share/pandoc/ "$@"
        '';
        runtimeInputs = [tex pkgs.pandoc];
      };
    in {
      formatter = pkgs.alejandra;

      devShells.default = pkgs.mkShellNoCC {
        name = "latex-letter-devshell";

        buildInputs = [pandoc];
      };
    });
}