="http://www.w3.org/2000/svg" viewBox="0 0 512 512">

20 LaTeX File Import

How to use tex2wp

Go to eskript/tex2ast on github, download the latest version. In your terminal, you will use the convert.php file in the src folder with the command php convert.php.


The original repository is the repository tex2ast on github. The original ‘how to’ is on gitlab. One version of the tex2wp file is also on gitlab.

Advanced: If you use the binary tex2wp, make it executable (chmod +x) and move it to /usr/local/bin/. Use the command tex2wp in your terminal. If you use the phar file tex2wp.phar, use php tex2wp.phar. The README.md is full of info.

20.1 – Basic conversion (.tex to html code)

You can convert and copy-paste your .tex easily into eSkript with tex2wp

Use the command line:

php convert.php <path to tex file>

Example command

php convert.php FILE.tex

You will get html code that you can copy-paste into the editor in eSkript in text mode (not into the visual editor).[1]

There is a new plugin in eSkript that allows you to write your LaTeX directly in eSkript, WP QuickLaTeX. No conversion needed! Contact Sarah for access.

20.2 – Conversion and Import using the JSON-format

If you have lots of content, i.e. many chapters, you can convert your .tex and import everything with the plugin ‘Pressbooks Import’ in eSkript.

20.2.1 – Converting to JSON

To convert your TeX-file, use the following command:

php convert.php <path to tex file> --mode pb > <path to new json file>

Example command

php convert.php FILE.tex --mode pb > File.json

20.2.2 – Importing into eSkript

The output file FILE.json may be imported into an eSkript as follows:

  1. Activate the Pressbooks import plugin under Plugins.
  2. This enables the JSON-Import option under Import.

Note that importing a JSON file will overwrite the entire eSkript. [2]

20.2.3 – Importing Pictures

The command

php convert.php FILE.tex --mode quiet --figarch FILE.zip

executed in the folder containing the main file (FILE.tex) generates a ZIP-file containing all pictures used in TeX-File (using their links in the TeX-file). The ZIP-file can be uploaded via the JSON-import tool (even if not explicitly mentioned there). This will place all pictures correctly inside the eSkript (according to the TeX-file). A second upload of a ZIP-file will simply overwrite the old ZIP-file.

Note that the above command will look only for SVG-files and put these into the generated ZIP-output. For instance, if a picture is included in the TeX-file using

[latex]\backslash[/latex]includegraphics[scale=1] [latex]\lbrace[/latex] Pictures/blasquared.pdf [latex]\rbrace[/latex]

the ZIP-generator will search for a file named blasquared.svg in the folder Pictures and add it to the ZIP-file (if it exists). The file blasquared.pdf will however be completely ignored.

For the conversion pdf to svg the writers can for instance recommend the software Inkscape which can be downloaded here for free.

(Note that at the time of writing all pictures included via the ZIP-file are by default scaled to the full pagewidth. An option to include a desired width in the TeX-file is however planned.)

20.3 – The .tex File for JSON conversion

20.3.1 – Division into chapters and subchapters

The JSON-Import is able to automatically recognize the structure of the TeX-File used as input and to then subdivide it into eSkript chapters so that no manual changes and shifts to the eSkript have to be made after the import.

In order for this subdivision to work properly, the tex2wp converter requires the following structure of TeX-file.



\chapter{Kapitel 1}
\chapter{Kapitel 2}

\chapter{Appendix 1}
\chapter{Appendix 2}


All sections before the first chapter will be converted into front-matter chapters numbered by I, II, III, and all chapters in the appendix will be converted into back-matter chapters numbered by A, B, C,

If the reader desires to create a title page for the pdf-file, we recommend that title page to be ignored by the converter (see Section 20.3.2, \texonly).

The converter ignores the command \tableofcontents by default. If a table of contents on an own eSkript-page is nevertheless desired, one can insert the following lines right before the command \tableofcontents :

\webonly{[toc levels="3" /]}

see also Section 20.3.2 for the commands \webonly,\texforweb.

20.3.2 – TeX only

In this section we would like to explain how (and in particular using which commands) the TeX-file can be used as the only source. For this purpose the converter tex2wp is programmed not to ignore the content after the comment


Using this functionality we will now list a few useful commands which we recommend to be added to the preamble of the TeX-file.

  • The command
    [latex]\backslash[/latex]newcommand[latex]\lbrace \backslash[/latex]raw[latex]\rbrace[/latex][1][latex]\lbrace[/latex]#1[latex]\rbrace[/latex]

    is used by the converter to copy paste the content to WordPress-Output. It should however only be used to define the commands below.

  • The command
    [latex]\backslash[/latex]newcommand[latex]\lbrace \backslash[/latex]wpswitch[latex]\rbrace[/latex][2][latex]\lbrace[/latex]#1[latex]\rbrace[/latex]
    %tex2ast [latex]\backslash[/latex]renewcommand[latex]\lbrace \backslash[/latex]wpswitch [latex]\rbrace [2][/latex]{#2}

    yields the functionality to distinguish directly between TeX- and WordPress-Output. For instance, [latex]\backslash[/latex]wpswitch{Hallo}{Bye} yields Hallo in TeX and Bye in the eSkript.

  • Correspondingly, the following commands are also useful:
    %tex2ast \renewcommand{\texonly}[1]{}
    %tex2ast \renewcommand{\texforweb}[1]{#1}
    %tex2ast \renewcommand{\webonly}[1]{\raw{#1}}

20.3.3 – Defining colors and boxes


20.3.4 – Using H5P

The content of other websites and in particular applets can be embedded in the eSkript using the Iframe-Embedder and H5P. For this the administrator of the eSkript has to go to the menu item H5P on the admin-page of the eSkript, install the Iframe-embedder (only once) and register every website (applet) that should be available in the eSkript. With registration the website gets assigned a number within the eSkript and one can embedd the webpage within the eSkript by the command

[h5p id="1"]

Using tex2ast and the above commands one can add the webpage also within latex by

\raw{[h5p id="1"]}

Of course one can also define environments and shorthands for the above, we are using the definitions (and the package environ)[3]

%tex2ast \renewcommand{\applet}[1]
  {\raw{\n [h5p id="}#1\raw{"]\n}}

%tex2ast \renewenvironment{h5pbox}[1][random]

{\raw{<div class="textbox tbbeispiel" style="border-color: black; background-color: #ec9969;">\n

<details open>
<summary style="color: white;">
<a id="h5p}#1\raw{" class="not-in-list"></a>}
Hier ist ein Applet

%tex2ast \renewcommand{\appletref}[2]
  {\raw{<a href="#h5p}#2\raw{</a>}}

 %tex2ast \renewenvironment{wpthanks}{\raw{<hr />}}{}

With this one would then write within the latex file

Here we are including the H5P-content within its own box,
so that e.g.\ an applet would have the same style as a
picture within an example.
After the applet we can explain a bit more of what is
going on.

Some quick comments/hints regarding applets/geogebra:

  • The page width of the eSkript is 720px, hence it works best if the geogebra-applet is using the same number. This is achieved by ????
  • The desired width of the applet is different if the applet is within a box, in that case the correct width is ????
  • The geogebra 5 “classic” programm for the Windows/Mac is more powerful and has less bugs than the mobile or online counterparts.
  • The color choice background-color:#EC9969 can of course be adapted to any other color. A wide selection of colors can be found here.
  • As for instance in the environmenth5boxa label (with the more or less the same functionality as the TeX-command \label in eSkript may always defined through a command like <a id="foo" class="not-in-list"></a> in combination with e.g. \webonly.

20.3.5 – Known Bugs

Note that the converter/eSkript-server comes with a given list of compatible packages and ignores all other packages and its commands.

  • psmallmatrix
  • [latex]\backslash[/latex]tag*[latex]\backslash[/latex]qedhere

  1. With the binary file, use the following:
    tex2wp <path to tex file>

    tex2wp takes a tex file as its first argument and will output markup which can be put into the WordPress editor in textmode.

  2. If you use hypothes.is Web annotation: the import respects existing annotations given that no major changes occurred at place where an annotation was made and the same URL is used.
  3. I copied the current relevant header content to here even though it is not working yet as intended with geogebra and the details-tag. With verbatim-environment it is easy to copy-paste the final version of these to here.


PolyBooks: How To eskript.ethz.ch - old Copyright © 2014 by Sarah Frédérickx. All Rights Reserved.