GithubHelp home page GithubHelp logo

slowphil / svg_and_texmacs_for_libreoffice Goto Github PK

View Code? Open in Web Editor NEW
9.0 1.0 2.0 10.78 MB

This extension enables using TeXmacs as a GUI equation editor for LO (and copy-pasting SVG drawings in LO)

Python 100.00%
svg libreoffice-extension inkscape texmacs equation

svg_and_texmacs_for_libreoffice's Introduction

Equation Editor for LibreOffice (direct download)

You need to prepare documents with equations but are struggling with LO Math, and do not want to learn how to code in LaTeX just for that? You are at the right place!

The purposes of this extension are:

  • Provide an easy, fully GUI, equation editor for LO
    With this extension, one uses the Free and Open Source software GNU TeXmacs to directly enter equations in their final visual form, using an extremely flexible and well though-out combination of toolbars, menus, and keyboard shortcuts... And this can even be customized!
    With this extension there is no need to know anything of TeX/LaTeX for obtaining beautiful equations in LO such as

    (Also check the samples).
    In spite of its very misleading name, TeXmacs is actually not at all based on TeX/LaTeX ⇒ Unlike with LibreOffice Math or the TextMath extension, with TeXmacs you simply cannot make a syntax error while entering your equations!

  • Convert existing equations to TeXmacs equations on-the-fly
    Whenever you select an existing equation in a LO document and call this extension, the equation is converted to a TeXmacs equation. Conversion works for

    • LibreOffice Math equations
      (Microsoft Equations imported in LibreOffice become LO Math equations)

    • MathType equations (wmf drawings or OLE objects).

    • plain LaTeX markup in Writer.
      Hence, if you have Latex material at hand or are proficient typing Latex, this is not wasted! Latex can also be pasted in TeXmacs while editing equations.

    • Other equations such as TextMath could olso be converted (contributions welcome)

  • Enable copy-pasting SVG drawings between LO and Inkscape (or any other app that handles SVG).
    Although LO has a pretty good support for SVG, when you copy a drawing in Inkscape it is disappointingly pasted as a bitmap in LO and it is not even possible to use "paste special" to get the vector format.
    With this extension, there is no need to go through a file for LO to exchange SVG with other apps.
    Equations appear as SVG images in LO (yet, they are fully re-editable).

How it works:

After installation, Writer, Draw and Impress have an additional toolbar with 3 buttons that implement the functionalities of the extension:

  • Paste SVG This button pastes an SVG image from the clipboard
  • Copy SVG This copies a selected SVG image to the clipboard
  • TeXmacs Revise the selected equation with TeXmacs (converting it, if needed).
    Creates a new equation if nothing is selected. This opens a TeXmacs window in which one can edit the equation visually, as shown below:

In order to get a feeling of how easy it is to enter equations in TeXmacs and to kickstart you using it, I recommend watching a couple of short tutorial videos on TeXmacs. They should convince you that TeXmacs is really user-friendly. I have tried many systems over the years, and when it comes to laying out maths, TeXmacs simply has no competitor! Gone the hassle of aligning equations in LO Math, or debugging a long LaTeX markup!

The two buttons for Copying and Pasting of SVG act on the system clipboard (overcoming the shortcomings of LO's clipboard handling of SVG). This allows rapid 2-way exchange with Inkscape and pasting TeXmacs fragments (using "copy to image" in TeXmacs' Edit menu). These clipboard actions are not (not yet?) transparently integrated with LibreOffice's standard edit menu, and keyboard shortcuts. However, once the extension installed you can define your own menu (or contextual menu) entries, and/or keyboard shortcuts, if desired. The macros you woud target are respectively paste_svg, copy_svg and edit_texmacs inside the TexmacsInkscape Basic library.

Miscellanous details

In Writer, equations are "anchored as characters" and automatically aligned to the baseline (for single line equations). If you want a displayed equation, define you own formating style for that.

In Writer, new equations are created with the current font size at the insertion point (except when converting LO math equations). Revised equations get their font size adjusted to their surrounding. If the size is off, change the output scale to 1 in TeXmacs preferences for conversion to images (one may want another default scale when working with Impress...)

Numbering equations is not handled. Use LibreOffice tools for that.

In Draw and Impress, it is not possible to insert a TeXmacs equation inside a text frame, to obtain an inline equation (It does not work for LO Math either). The workarounds are :

  • Write the entire text with inline equation(s) in TeXmacs
  • In place of a text box, use an LO Writer OLE object
    There you can place Texmacs equations inline. Ironically this does not work with LO Math, because of this bug.

If you ever change the font size of a document, you'll need to manually update each equation in the document. This implies this extension is suitable only for documents containing a limited number of equations. If you want to write a document with hundreds of equations (say, a PhD thesis), consider using a real scientific word processor like TeXmacs...

Requirements

This extension is known to work in recent LibreOffice in both Linux and Windows (⩾7.0 ? ymmv for earlier versions). It was not tested in OpenOffice and probably won't work without modifications. If the extension fails to install properly, make sure you have libreoffice-script-provider-python installed.

Of course, you need to have TeXmacs installed on your system.

For the TeXmacs equation editor feature to work with this LibreOffice extension, TeXmacs further needs the equation-editor plugin which will be distributed with the next official version available at texmacs.org. Meanwhile, the plugin can be installed manually, or one can get one of my texmacs builds incorporating it (see below).

You'll also need pdftocairo (from Poppler tools) that TeXmacs needs to produce the SVG images.

Both the plugin and pdf to cairo are bundled in my windows builds. For Linux, the AppImage already contains the equation-editor plugin.

Technical details

This is my first LO extension and it uses a mix of Basic and Python scripts: It is easier to hack with Basic as you find much more examples and help, on the other hand Python was more convenient for implementing a couple of things (like for instance working around a bug in the interfacing to windows clipboard in LO).

Modifying and repacking the LO extension (.oxt file)

If you tweak the Basic code in LO and want to repack the extension, clone the repo and export your modified Basic library to the TeXmacs_and_SVG folder. Then open the SVG_and_Texmacs.odt (which is a just Bernard Marcelly's Extension Compiler with proper settings for this extension set in the content of the Basic macro Standard:Module1 in that file) and recompile the oxt in section 2.3.3 (full instructions in the file).

Known issues

  • Inserting SVG in rescued documents leads to an error: save them first.
  • SVG images are well handled in native LO document formats (.odt, .odg, .odp). However, when saved as MS Office documents, LO converts SVG images to lousy bitmaps. When exporting to these formats it is possible to preserve the vector character by converting SVG to metafile images, but any equation then becomes non-editable…
  • While an equation is opened for revision in TeXmacs, all LO windows are unresponsive. Although it can be frustrating for the user, this is the expected behavior for this simple extension. To regain control of LO, terminate the edition in TeXmacs, by pressing either the "done" or "cancel" button on the lower toolbar in TeXmacs.

Credits

The extension is packaged using Bernard Marcelly's excellent Extension Compiler The conversion of MathType equations is based on the converter originaly included in the Jex equation editor, which was ported from Java to Python and adapted. The icon of the TeXmacs toolbar button is based on an original design by Massimiliano Gubinelli.

svg_and_texmacs_for_libreoffice's People

Contributors

slowphil avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

svg_and_texmacs_for_libreoffice's Issues

equation images have (almost) zero height when a writer document is saved from LO v7.4

This bug affects LO writer documents containing equations created with this extension, when they have been saved once from LO 7.4. Note that before the document is saved from LO 7.4, everything looks perfectly fine in LO 7.4, and it does not matter if it's a freshly created document with new equations or editing an existing document from and earlier LO version (even without modifying the equations it contains). Once the document saved from LO 7.4, upon re-opening it in any LO version, all embedded equations in the document are broken.

The issue can be fixed one image at a time, by clicking the restore "original image size" button in the image properties dialog.

It seems somehow related to https://bugs.documentfoundation.org/show_bug.cgi?id=45884, which perhaps is getting worse... It's a matter of how to specify the image should "keep its aspect ratio" in the saved xml document, and how to get that from the basic code. I think I've found a way to fix that, and should be able to commit a fix ASAP.

copying/pasting svg is broken in LO ⩾6.1

The GrahicsURL property we are using has been deprecated .
Hints are provided in this link to fix this. I just need some time to look at it...

Edit: The new way of doing is not super well documented.
relevant links
https://forum.openoffice.org/fr/forum/viewtopic.php?f=8&t=41236&p=318925&hilit=GraphicURL#p318925
https://api.libreoffice.org/docs/idl/ref/interfacecom_1_1sun_1_1star_1_1document_1_1XGraphicObjectResolver.html#details
https://wiki.documentfoundation.org/Macros

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.