JMM’s notes on

Inkscape

Just some personal notes, or a cheatsheet, on using Inkscape.

Note for other people: I usually use Inkscape and Emacs in conjunction, and I’ve made my own (as-of-yet undocumented) library called jmm-inkscape.el for using them together. It basically relies on D-Bus communication, though Inkscape’s D-Bus interface recently was updated. Some of the org.gtk.Actions for Inkscape are located in src/actions/. Like here’s an example of actions defined in actions-selection.cpp.

Keyboard tips

Keyboard Description.
Shift+Tab Can be used to quickly select the last-created object (assuming it’s on top). More generally it cycles backward an object (compared to Tab).
drag object+Control+C Creates clones while dragging (in Inkscape 1.3)
Control+Alt+D Duplicate and transform (in Inkscape 1.3)

You can see some of my saved keyboard shortcuts at /inkscape-keys.

Command line

See https://wiki.inkscape.org/wiki/Using_the_Command_Line.

Exporting a PNG

Here’s how you’d export a PNG with a white background and a width of 500px.

inkscape yourfile.svg --export-type=png --export-width=500 --export-background=white

It’ll make a file named yourfile.png by default.

SVG to PDF

Here’s how you’d export an SVG to a PDF:

inkscape --export-type=pdf --export-filename=output.pdf input.svg

Note the --export-type=pdf isn’t actually necessary, but I think it ensures that the export-filename has the right extension.

Tips

Editing defs or markers

Editing markers or symbols (which are in the <defs> section) can be slightly annoying. One tip is to replace a def’d ID with a <use> element pointing to some group (e.g. <g>), which you can then edit. You may also be able to have the <use> point to an external SVG.

(TODO: Show an example of this.)

Maintaining text style

I kind of don’t like Inkscape resets to some default style for entering text. Though I think you can set it to remember a previous style (which is sometimes worse for me).

Edit from 2024-05-13: Actually, just set it to remember the previous style. This is easier. If you want to maintain a style, you might edit your ~/.config/inkscape/preferences.xml (only edit when Inkscape is closed, otherwise it’ll overwrite it) and look for

    <eventcontext
       id="text"
and edit the style attribute.

Here’s the old workarounds:

If you want to start a new block of text, but have that block use another’s style, here’s what you can do:

  1. Select (F1 mouse-1) the text block whose style you want to use then copy (Ctrl+C) it.
  2. Start a new block of text (T)
  3. Paste the style (Ctrl+Shift+V)

However, this doesn’t seem to maintain the text alignment (e.g. if you wanted to make text centered) (tested on 2024-02-01 with Inkscape 1.3.2 (091e20ef0f, 2023-11-25)).

A second workaround which I use pretty often is to:

  1. duplicate text (Ctrl+D)
  2. cut the new object (Ctrl+X)
  3. paste it under my mouse (Ctrl+V)
  4. edit as text (T)
  5. highlight all text (Ctrl+A)
  6. and delete the highlighted selection (Backspace)

This does maintain text alignment, but it’s a hassle as well.

Another possibility would be to save your style into a class and then just set classes on objects. Converting styles to classes is possible with the “Merge styles into CSS” builtin extension, but setting classes on objects is still a bit rough for me. You can set classes with the “Selectors and CSS” toolbar (Shift+Ctrl+Q), but occasionally this has crashed. Ideally I’d have several different hotkeys to toggle different classes. To work around this, my jmm-inkscape-svg-mode has a command to send some DBus commands to erase a style and set a class.

Hotkeys for setting classes and clearing styles

Okay, I’ve kind of figured out a way of clearing styles and setting a class using hotkeys. You can use the gaction app.object-set-attribute('attribute,value') to set (but not seemingly completely remove) XML attributes. So you can set style to an empty string and class to some class you want. You can then bind these to hotkeys like:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<keys name="User Shortcuts">
  <bind
     gaction="app.object-set-attribute('class,test')"
     keys="&lt;Hyper&gt;t" />
  <bind
     gaction="app.object-set-attribute('style,')"
     keys="&lt;Hyper&gt;s" />
</keys>

In this example, Hyper+t sets the class to “test” and Hyper+s sets the style attribute to be an empty string. You’d import this file in your keyboard preferences. Take note that this doesn’t seem to survive being re-exported.

Command palette

You can pop up the command palette by pressing ?. Say you selected two objects and then hit ? then searched for align. Select the “Align Objects” option. You’ll see the search icon at the left of the text input turns to a keyboard icon. This is where you can enter in arguments. Like you can put “vcenter last” to vertically align the center to the last selected object.

Also, I’m not sure where the documentation for the command palette is, so here’s what I’ve discovered from command-palette.cpp:

  • Press the up key to use history (not sure how to use parameter history, though it seems saved).
  • Hitting Escape or ? (not configurable) will exit the command palette.

Using multi-page SVGs in browsers

Inkscape has support for “multiple-page” SVGs. This isn’t some part of the SVG spec, instead Inkscape has its own <inkscape:page/> element. Browsers will only show the first page. To actually view multiple pages, you can use the SVG <view/> element. If you have a back page like:

<inkscape:page
       x="1066"
       y="0"
       width="1056"
       height="816"
       id="page6"
       margin="0"
       bleed="0" />

Make a view like:

<view id="back" viewBox="1066 0 1056 816" />

Then to use it in an XHTML file, include:

<img src="/some.svg#back"/>

Resizing text in figures

For my dissertation, I made a lot of figures where I didn’t consider their physical, printed dimensions. They were usually too big and would end up getting scaled down to fit on a piece of letter paper. Although now I set figure dimensions to be more realistic (say, 5 inches wide where 1 inch = 96 pixels or “user units”), I had to resize a lot of other figures and their text.

One trick for resizing old figures is to use embedded <svg> tags. Encase your old SVG in a new one with better dimensions, and then pull text from the inner SVG to the outer using “Move to Layer”. You may also need to move text down and back (like, pressing Up Down) to get rid of any matrix transformations. Once text is in the outer SVG where 1 inch = 96 pixels, you can use “pt” font sizes meaningfully.

Issues

Some issues I’ve run into with Inkscape:

Questions/Wishlist

Questions I have or features I’d like or might want to implement

Cool or fun features of Inkscape

Extensions

I haven’t really messed around too much with extensions, but here are some links for future reference:

Inkex is in Python, but extension can be written in any language (even shell script).