nvim: add things to make Inkscape figures in Typst
This commit is contained in:
parent
e49433d53c
commit
01f328be31
@ -116,6 +116,13 @@ nnoremap <silent> ZF :qa<cr>
|
||||
" copy URL under cursor to clipboard bind
|
||||
:nnoremap <silent><leader>uu :let @+ = expand('<cfile>')<CR>
|
||||
|
||||
" edit figure in Inkscape
|
||||
function EditFig()
|
||||
let figure_fname = expand('<cfile>')
|
||||
exec "silent !typst-figure " .. figure_fname
|
||||
endfunc
|
||||
|
||||
:nnoremap <silent><leader>ff :call EditFig()<cr>
|
||||
" Plugins
|
||||
|
||||
" Run PlugInstall if there are missing plugins
|
||||
|
31
src/.config/nvim/ultisnips/typst.snippets
Normal file
31
src/.config/nvim/ultisnips/typst.snippets
Normal file
@ -0,0 +1,31 @@
|
||||
snippet problem "template for problem notes" bi
|
||||
#import "../templates/problems.typ": template, source_code, status
|
||||
#show: template.with(
|
||||
title: "$1",
|
||||
problem_url: "$2",
|
||||
stat: "${3:incomplete}",
|
||||
)
|
||||
|
||||
endsnippet
|
||||
|
||||
snippet math_prob "template for math problems" bi
|
||||
#import "../../../templates/math_prob.typ": template
|
||||
#show: template.with(
|
||||
title: "$1",
|
||||
)
|
||||
|
||||
endsnippet
|
||||
|
||||
snippet ss "superscript" i
|
||||
^$1
|
||||
endsnippet
|
||||
snippet im "inline math" w
|
||||
\$${1:${VISUAL}}\$
|
||||
endsnippet
|
||||
|
||||
snippet fig "create new figure" bi
|
||||
#figure(
|
||||
image("fig/${0:name}.svg"),
|
||||
caption: [$2],
|
||||
) <${3:identifier}>
|
||||
endsnippet
|
51
src/.local/bin/svg-typst
Executable file
51
src/.local/bin/svg-typst
Executable file
@ -0,0 +1,51 @@
|
||||
#!/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"
|
58
src/.local/bin/typst-figure
Executable file
58
src/.local/bin/typst-figure
Executable file
@ -0,0 +1,58 @@
|
||||
#!/bin/sh
|
||||
# Figure manager for typst.
|
||||
# Run this from Vim and it will edit a figure with the given filename in Inkscape.
|
||||
|
||||
SVG_PATH="$1"
|
||||
mkdir -p fig/
|
||||
|
||||
if [ -e fig/"$1" ]; then
|
||||
# just edit it
|
||||
inkscape "$SVG_PATH" &
|
||||
else
|
||||
# otherwise, copy this template file and edit it
|
||||
cat <<'EOF' > "$SVG_PATH"
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
width="300mm"
|
||||
height="300mm"
|
||||
viewBox="0 0 300 300"
|
||||
version="1.1"
|
||||
id="svg5"
|
||||
inkscape:version="1.2.2 (b0a8486541, 2022-12-01)"
|
||||
sodipodi:docname="drawing.svg"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg">
|
||||
<sodipodi:namedview
|
||||
id="namedview7"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#000000"
|
||||
borderopacity="0.25"
|
||||
inkscape:showpageshadow="2"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pagecheckerboard="0"
|
||||
inkscape:deskcolor="#252525"
|
||||
inkscape:document-units="mm"
|
||||
showgrid="false"
|
||||
inkscape:zoom="0.62272556"
|
||||
inkscape:cx="353.28564"
|
||||
inkscape:cy="546.78983"
|
||||
inkscape:window-width="1836"
|
||||
inkscape:window-height="986"
|
||||
inkscape:window-x="40"
|
||||
inkscape:window-y="30"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="layer1" />
|
||||
<defs
|
||||
id="defs2" />
|
||||
<g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1" />
|
||||
</svg>
|
||||
EOF
|
||||
inkscape "$SVG_PATH" &
|
||||
fi
|
Loading…
Reference in New Issue
Block a user