# How to replace all images in Libreoffice with their description

I have a very long document containing lots of svg images created using the extension TexMaths. This extension uses the latex installation to create svg image of the inputted equation (or set of equations). The latex code for each equation (or set of equations) is embedded in the image as part of its Description. Such a Description can be accessed by right clicking the svg image and choosing the option Description.

I want to replace all the svg images using a suitable macro, by the embedded descriptions.

e.g. from

The Einstein's famous equation, [svg embedded equation : E = mc 2], tells us that mass can be converted to energy and vice-versa.

To

The Einstein's famous equation, E = mc^2, tells us that mass can be converted to energy and vice-versa.

This will allow me to convert by hand the odt file containing numerous TexMaths equations to LaTeX.

-
Take a look at the answer in How to remove all the images in a document in LibreOffice Writer? . It will give you the basics of want you want to do, but you will need to adjust it a little. If you are not able to make the changes needed, I might be able to do it; but I wouldn't be able to get to it for a few days. –  chaskes Apr 17 at 4:25
Well, tnx a lot. In fact I looked at the given post above before asking the question. The general plan is make a loop to go through each svg image. For each image, read the description and remove unnecessary characters so that what is left is a pure equation or something like \begin{} .. \end{}. Then remove the svg image. What I am puzzled now, is the matter of putting the text at the location of the deleted image. Most of it are anchored as characters by the way. –  user30131 Apr 17 at 14:20
Just an idea, try to combine graphmonkey with source-code part of libre-office concerning icons/images ?! –  dschinn1001 Jun 5 at 3:41
@dschinn1001 Thank you, BTW TexMaths is plugin for formulas. Could you please explain more. I couldn't make a glue how graphmonky will convert TexMaths draw objects to its description. In other words I didn't hear about graphmonkey before; Does it has an option, you thought it may lead to solve the problem? –  Sneetsher Jun 5 at 4:36

This is a different way without using Macros. As .odt file is basically just zipped files and the main file is an XML.

1. Create a XML style sheet texmath_raw_equation.xslt

2. Extract .odt file to tmp folder, example texmath_test.odt:

7z x -otmp texmath_test.odt

3. Replace TexMath image (hold by <draw:g></draw:g> tag) with its description (hold by <svg:desc></svg:desc> tag)

xsltproc -o content.xml texmath_raw_equation.xslt tmp/content.xml
mv content.xml tmp/content.xml

4. Compress back to new .odt file

cd tmp
7z a -tzip ../texmath_test_new.odt *
cd ..
rm -r tmp


References:

-