diff --git a/src/.config/nvim/ultisnips/typst.snippets b/src/.config/nvim/ultisnips/typst.snippets index f57bc28..c8f1449 100644 --- a/src/.config/nvim/ultisnips/typst.snippets +++ b/src/.config/nvim/ultisnips/typst.snippets @@ -25,7 +25,7 @@ endsnippet snippet fig "create new figure" bi #figure( - image("fig/${0:name}.svg"), + image("fig/`!v expand("%:r")`/$1.svg"), caption: [$2], -) <${3:identifier}> +) <$1> endsnippet diff --git a/src/.local/bin/svg-typst b/src/.local/bin/svg-typst deleted file mode 100755 index a9b1879..0000000 --- a/src/.local/bin/svg-typst +++ /dev/null @@ -1,51 +0,0 @@ -#!/bin/sh -# Write Typst markup, then copy it as an SVG. -# This can be used to paste math labels in Inkscape. - -# Requires -# -------- -# pdf2svg -# typst -# xclip -# $EDITOR set to an editor (prefer nvim) - -# create temp files -TMP_SRC="$(mktemp --suffix=.typ)" -TMP_PDF="$(mktemp --suffix=.pdf)" -TMP_SVG="$(mktemp --suffix=.svg)" - -# Typst template -cat <<'EOF' > "$TMP_SRC" -#set page( - width: 10cm, - height: auto, - margin: (x: 1cm, y: 1cm) -) - -#show math.equation: eq => scale(x: 150%, y: 150%, text(font: "Fira Math", size: 17pt, eq)) -#show text: set text(font: "Fira Math", size: 25pt) - -$ $ -EOF - -# edit Typst source -if [ "$EDITOR" = "nvim" ] || [ "$EDITOR" = "vim" ]; then - # if we're using vim we can jump to the end of the template - $EDITOR -c "normal Gll" -c "startinsert" "$TMP_SRC" -else - $EDITOR "$TMP_SRC" -fi - -# compile to pdf -typst c "$TMP_SRC" "$TMP_PDF" - -# convert to svg -pdf2svg "$TMP_PDF" "$TMP_SVG" - -# copy (x-inkscape-svg necessary otherwise it rasterizes the image when pasting) -xclip -selection clipboard -t image/x-inkscape-svg -i "$TMP_SVG" - -# clean up -rm "$TMP_SRC" -rm "$TMP_PDF" -rm "$TMP_SVG" diff --git a/src/.local/bin/typst-figure b/src/.local/bin/typst-figure index d741a3e..577641f 100755 --- a/src/.local/bin/typst-figure +++ b/src/.local/bin/typst-figure @@ -3,9 +3,9 @@ # Run this from Vim and it will edit a figure with the given filename in Inkscape. SVG_PATH="$1" -mkdir -p fig/ +mkdir -p "$(dirname "$SVG_PATH")" -if [ -e fig/"$1" ]; then +if [ -e "$SVG_PATH" ]; then # just edit it inkscape "$SVG_PATH" & else @@ -15,9 +15,9 @@ else