nvim: typst figure stuff
This commit is contained in:
parent
0959d9b6d1
commit
5808279548
@ -25,7 +25,7 @@ endsnippet
|
|||||||
|
|
||||||
snippet fig "create new figure" bi
|
snippet fig "create new figure" bi
|
||||||
#figure(
|
#figure(
|
||||||
image("fig/${0:name}.svg"),
|
image("fig/`!v expand("%:r")`/$1.svg"),
|
||||||
caption: [$2],
|
caption: [$2],
|
||||||
) <${3:identifier}>
|
) <$1>
|
||||||
endsnippet
|
endsnippet
|
||||||
|
@ -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"
|
|
@ -3,9 +3,9 @@
|
|||||||
# Run this from Vim and it will edit a figure with the given filename in Inkscape.
|
# Run this from Vim and it will edit a figure with the given filename in Inkscape.
|
||||||
|
|
||||||
SVG_PATH="$1"
|
SVG_PATH="$1"
|
||||||
mkdir -p fig/
|
mkdir -p "$(dirname "$SVG_PATH")"
|
||||||
|
|
||||||
if [ -e fig/"$1" ]; then
|
if [ -e "$SVG_PATH" ]; then
|
||||||
# just edit it
|
# just edit it
|
||||||
inkscape "$SVG_PATH" &
|
inkscape "$SVG_PATH" &
|
||||||
else
|
else
|
||||||
@ -15,9 +15,9 @@ else
|
|||||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||||
|
|
||||||
<svg
|
<svg
|
||||||
width="300mm"
|
width="100mm"
|
||||||
height="300mm"
|
height="100mm"
|
||||||
viewBox="0 0 300 300"
|
viewBox="0 0 100 100"
|
||||||
version="1.1"
|
version="1.1"
|
||||||
id="svg5"
|
id="svg5"
|
||||||
inkscape:version="1.2.2 (b0a8486541, 2022-12-01)"
|
inkscape:version="1.2.2 (b0a8486541, 2022-12-01)"
|
||||||
|
Loading…
Reference in New Issue
Block a user