Dmitrii Posted June 9, 2020 Posted June 9, 2020 There are several forum threads (example) about using LaTeX formulas in Designer. I have written a small Python script that implements something like Inkscape's "Export to PDF + LaTeX" option. This is not a WYSIWYG solution in that you never see any formula previews in Affinity Designer! You only see the TeX code. The formulas appear only in the exported file. This is as intended. Note that using the script assumes some familiarity with the command line. Additionally, as written, the script works only on Mac OS. Is this useful? The script is useful if you design an illustration to put into a LaTeX document. It is even more useful if you want to include the picture in several LaTeX documents with different font styles, e.g., in a paper and in a beamer presentation. This is what I use Affinity Designer for. The script is probably not helpful if your main goal is to produce the picture itself. In this case, as described in the previously mentioned threads, a more convenient way would be to copy the formulas from LaTeXit or its alternatives to Affinity Designer. Setup The script itself is a python file available at this link. Save this text into an executable file called 'svg2pdftex' somewhere in your $PATH. The script does not work by itself: you must have at least one of the following two tools installed in your system: Either Inkscape for Mac, or cairosvg (execute pip3 install cairosvg to install; if pip3 doesn't work, execute brew install python to install it first with Homebrew) The script will try to automatically detect those tools. It will use Inkscape when it is available. The conversion using Inkscape is more accurate, but slower. If Inkscape is not available, the script does not support text colors and text rotations. Note that both options ignore text size and font types. This is as intended, since the text should be consistent with your LaTeX document and thus it should be controlled on the TeX level, not on the graphic design level. Usage Draw a picture in Affinity Designer. Put LaTeX code in text labels (example: $\mathbb{P}^n \setminus Z$). Export to SVG making sure that Export text as curves option is disabled and Flatten transforms (in the "More" options menu) option is enabled. Run the script on the produced SVG file: svg2pdftex PICTURENAME.svg It produces files PICTURENAME.pdf, which is your picture with all text omitted, as well as an auxiliary PICTURENAME.pdf_tex file. To include the picture in your LaTeX file, add the following packages to the preamble of your document: \usepackage{graphicx} \usepackage{import} \usepackage{xifthen} \usepackage{pdfpages} \usepackage{transparent} And now you can include the picture as follows: \begin{figure}[ht] \def\svgwidth{0.7\columnwidth} \import{./}{PICTURENAME.pdf_tex} \end{figure} Changing the \svgwidth parameter will scale the picture preserving the text size. 7. Compile the document and enjoy the results! Advanced usage notes Additional options The script supports some command-line options: -c forces cairosvg conversion even if Inkscape is available. -g will create and compile PICTURENAME-preview.tex file containing the picture. This is very useful for tweaking the positions of the text nodes, difficult to get right in this non-WYSIWYG approach. -p PREAMBLE.tex: if you use -g, this will add the contents of PREAMBLE.tex to the preview tex file. Convenient if you want to use custom LaTeX macros in the text labels. Notes on the conversion mechanisms Inkscape is more robust, it supports text rotations, uses the specified text color, and can handle text partially obscured by other objects. The first invocation of Inkscape would be very slow since it needs to initialize XQuartz; however, if you leave XQuartz running, the consequent invocations of Inkscape would be quite fast. The conversion using cairosvg is very basic, and it relies heavily on the Flatten transforms option in Affinity Designer. It does not look on the text colors specified in the Designer, so change the color in your LaTeX code if necessary, e.g., with \color{blue}\mathbb{P}^n. There are no clear workarounds for rotated text. Using this script on Windows To use this script on Windows, you'll need to change the INKSCAPE variable near the top of the script to the correct location of Inkscape executable. The installation steps for cairosvg could also be different. Finally, you'll probably need to do something like python svg2pdftex PICTURENAME.svg instead of executing svg2pdftex itself. Other than that, things should work fine. Tips and tricks Roughly speaking, the left bottom corner of the text is preserved under the TeX transformation. A convenient way to locate a good position for a text label is the following: Use Continuous export to SVG (with flattened transforms etc) in Affinity Designer. Use entr or similar tools to do "continuous svg2pdftex conversion". Example: echo "PICTURENAME.svg" | entr svg2pdftex -cg -p PREAMBLE.tex PICTURENAME.svg will recompile PICTURENAME-preview.pdf file every time the picture in Affinity Designer changes. Use some PDF viewer which automatically refreshes the contents of the PDF file. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.