|
| 1 | +.. |TexText| replace:: **TexText** |
| 2 | +.. |Inkscape| replace:: **Inkscape 1.x** |
| 3 | + |
| 4 | +.. role:: bash(code) |
| 5 | + :language: bash |
| 6 | + :class: highlight |
| 7 | + |
| 8 | +.. role:: dos(code) |
| 9 | + :language: dos |
| 10 | + :class: highlight |
| 11 | + |
| 12 | + |
| 13 | +.. _commandlineusage: |
| 14 | + |
| 15 | +========================== |
| 16 | +TexText Command Line Usage |
| 17 | +========================== |
| 18 | + |
| 19 | +Next to the usage from within Inkscape |TexText| can also be invoked from the |
| 20 | +command line. This maybe used in third party apps or for debugging |
| 21 | +purposes. |
| 22 | + |
| 23 | +.. contents:: :local: |
| 24 | + :depth: 2 |
| 25 | + |
| 26 | +Prerequisites |
| 27 | +============= |
| 28 | + |
| 29 | +In order to use |TexText| from the command line some prerequisites must be met. |
| 30 | +At first, since |TexText| uses the Inkscape executable itself for the required |
| 31 | +pdf -> svg conversion, Inkscape must be installed on your system. Additionally, |
| 32 | +the path to the Inkscape extension system must be known. |
| 33 | + |
| 34 | +Linux |
| 35 | +~~~~~ |
| 36 | + |
| 37 | +Since Inkscape is on your system all required Python libraries are already |
| 38 | +available for the system Python interpreter. You only have to ensure that the |
| 39 | +``PYTHONPATH`` variable contains the path to the Inkscape extension framework: |
| 40 | + |
| 41 | +.. code-block:: bash |
| 42 | +
|
| 43 | + export PYTHONPATH=${PYTHONPATH}:/usr/share/inkscape/extensions |
| 44 | +
|
| 45 | +Windows |
| 46 | +~~~~~~~ |
| 47 | + |
| 48 | +On Windows Python is bundled within the Inkscape installation. You need to |
| 49 | +ensure that the Inkscape binary directory is in the system path so that |
| 50 | +``inkscape.exe`` and ``python.exe`` is found. Additionally, the ``PYTHONPATH`` |
| 51 | +variable must contain the path to the Inkscape extension framework: |
| 52 | + |
| 53 | +.. code-block:: doscon |
| 54 | +
|
| 55 | + set PATH=C:\Program Files\Inkscape\bin;%PATH% |
| 56 | + set PYTHONPATH=%PYTHONPATH%;C:\Program Files\Inkscape\share\inkscape\extensions |
| 57 | +
|
| 58 | +.. note:: |
| 59 | + |
| 60 | + If you are unsure where the Inkscape extension subsystem resides in your |
| 61 | + system execute the command |
| 62 | + |
| 63 | + .. code-block:: bash |
| 64 | +
|
| 65 | + inkscape --system-data-directory |
| 66 | +
|
| 67 | + and add ``/extensions`` (or ``\extensions`` on Windows) to the output. |
| 68 | + |
| 69 | + |
| 70 | +Usage |
| 71 | +===== |
| 72 | + |
| 73 | +On the command line, in principle, |TexText| operates as follows: It takes the |
| 74 | +content of an Inkscape SVG-document, does something with it (e.g. inserts a |
| 75 | +|TexText| object, modifies an existing |TexText| object, or re-compiles all |
| 76 | +existing |TexText| obejcts) and writes the resulting SVG-content into a new file |
| 77 | +or to ``stdout``. |
| 78 | + |
| 79 | +The calling syntax is |
| 80 | + |
| 81 | +.. code-block:: bash |
| 82 | +
|
| 83 | + python __main.py__ [-h] [--output OUTPUT] [--id IDS] [--selected-nodes SELECTED_NODES] |
| 84 | + [--text TEXT] [--preamble-file PREAMBLE_FILE] |
| 85 | + [--scale-factor SCALE_FACTOR] [--alignment ALIGNMENT] |
| 86 | + [--recompile-all-entries] [--tex_command TEX_COMMAND] [INPUT_FILE] |
| 87 | +
|
| 88 | +The function returns ``0`` in case compilation succeeded. It returns ``1`` |
| 89 | +(bad setup) or ``60`` (program or compile errors) if execution failed. |
| 90 | + |
| 91 | +Command Line Arguments |
| 92 | +====================== |
| 93 | + |
| 94 | +-h, --help |
| 95 | + Show help message and exit. |
| 96 | + |
| 97 | +INPUT_FILE: |
| 98 | + The Inkscape SVG-file the content of with is taken and processed by |
| 99 | + |TexText|. This file is not modified. See the ``--output`` argument for |
| 100 | + more details. |
| 101 | + |
| 102 | +--output OUTPUT |
| 103 | + Path of the file into which the output of |TexText| is written. If this |
| 104 | + argument is omitted the output is written to ``stdout``. |
| 105 | + |
| 106 | +--id IDS |
| 107 | + The XML id attribute of the selected |TexText| object (or a list of ids |
| 108 | + if multiple are selected) in the SVG-Document one would like to modify. |
| 109 | + If this argument is omitted it is assumed that a new |TexText| object |
| 110 | + is going to be created and inserted into the SVG document. If the object |
| 111 | + is no |TexText| object nothing happens. |
| 112 | + |
| 113 | + .. note:: |
| 114 | + |
| 115 | + Currently, |TexText| does only support a single id. |
| 116 | + |
| 117 | +--selected-nodes SELECTED_NODES |
| 118 | + Not used by |TexText| (it is the XML id:subpath:position attribute |
| 119 | + of selected nodes of a path) |
| 120 | + |
| 121 | +--text TEXT |
| 122 | + The LaTeX or typst code to compile. If this argument is omitted the GUI |
| 123 | + opens if ``--recompile-all-entries`` is not set. The GUI will show the |
| 124 | + content of the |TexText| object specified by ``--id`` or nothing if no id |
| 125 | + has been specified. |
| 126 | + |
| 127 | +--preamble-file PREAMBLE_FILE |
| 128 | + Full path to the preamble file one would like to use for |
| 129 | + compilation. |
| 130 | + |
| 131 | +--scale-factor SCALE_FACTOR |
| 132 | + The scale factor one would like to use for compilation. A scale factor |
| 133 | + ``1.0`` means that the compiled LaTeX or typst output is inserted |
| 134 | + "as is" into the document. |
| 135 | + |
| 136 | +--alignment ALIGNMENT |
| 137 | + Only evaluated when a |TexText| object is re-compiled. It controls how a |
| 138 | + modified |TexText| object is aligned with respect to the old object. |
| 139 | + Possible values are: ``top left``, ``top center``, ``top right``, |
| 140 | + ``middle left``, ``middle center``, ``middle-right``, ``bottom left``, |
| 141 | + ``bottom center``, and ``bottom right``. |
| 142 | + |
| 143 | +--recompile-all-entries |
| 144 | + Re-compile all |TexText| objects found in the SVG-document. The |
| 145 | + ``--id`` and ``--text`` arguments are ignored in that case. |
| 146 | + |
| 147 | +--tex_command TEX_COMMAND |
| 148 | + The command used for compilation of the code passed via the ``--text`` |
| 149 | + argument. Possible values are ``pdflatex``, ``xelatex``, ``lualatex``, |
| 150 | + and ``typst``. If this argument is omitted the default (``pdflatex``) |
| 151 | + is used. |
| 152 | + |
| 153 | +Examples |
| 154 | +======== |
| 155 | + |
| 156 | +With showing the GUI |
| 157 | +~~~~~~~~~~~~~~~~~~~~ |
| 158 | + |
| 159 | +- Take ``empty.svg``, open the GUI, compile the code typed in there and insert |
| 160 | + the generated object into the document. Write the result to ``stdout``: |
| 161 | + |
| 162 | + .. code-block:: bash |
| 163 | +
|
| 164 | + python __main__.py empty.svg |
| 165 | +
|
| 166 | +- From ``nonempty.svg`` take the object the ``id`` attribute of which has the |
| 167 | + value ``7`` and in case this is a |TexText| object pass its LaTeX code to the |
| 168 | + GUI. After modification of the code, compile it and replace the original |
| 169 | + object by the modified one and write the output to ``result.svg``: |
| 170 | + |
| 171 | + .. code-block:: bash |
| 172 | +
|
| 173 | + python __main__.py --id 7 --output result.svg nonempty.svg |
| 174 | +
|
| 175 | +Without showing the GUI |
| 176 | +~~~~~~~~~~~~~~~~~~~~~~~ |
| 177 | + |
| 178 | +- Take ``empty.svg``, compile the code ``$x \in \mathbb{R}$`` using the preamble |
| 179 | + ``my_preamble.tex`` and insert the result as a |TexText| object scaled by |
| 180 | + ``2.0`` into the document. Write the result into the file ``result.svg``: |
| 181 | + |
| 182 | + .. code-block:: bash |
| 183 | +
|
| 184 | + python __main__.py --text "$x \in \mathbb{R}$" --preamble-file "my_preamble.tex" --scale-factor 2.0 --output result.svg empty.svg |
| 185 | +
|
| 186 | +- Take ``nonempty.svg``, compile the code ``$x \in \mathbb{R}$`` using the preamble |
| 187 | + ``my_preamble.tex``. Then, replace the |TexText| object the XML id attribute |
| 188 | + of which has the value ``7`` by the compiled result in such a way that the |
| 189 | + center of the new object matches the center of the old object. Write the |
| 190 | + result into the file ``result.svg``: |
| 191 | + |
| 192 | + .. code-block:: bash |
| 193 | +
|
| 194 | + python __main__.py --id 7 --text "$x \in \mathbb{R}$" --preamble-file "my_preamble.tex" --alignment "middle center" --output result.svg empty.svg |
| 195 | +
|
| 196 | +- Recompile all |TexText| objects in ``nonempty.svg`` and write the result into |
| 197 | + ``result.svg``: |
| 198 | + |
| 199 | + .. code-block:: bash |
| 200 | +
|
| 201 | + python __main__.py --recompile-all-entries --output result.svg nonempty.svg |
0 commit comments