## A simplified way to insert TikZ graphics into actual documents.

One of the observations I seem to be making is, that the technology-intensive part of the world is still using such tools as LaTeX, to typeset documents and vector-based graphics, such as Mathematical equations which I’ve included in previous parts of this blog, even though we know that GUI-based applications have existed for some time, that also typeset and do graphics…

I like ‘LaTeX’, even though I never learned the full syntax. LaTeX defines the document in a type of textual syntax. And there is even a system of TeX macros, which defines a sub-language called “TikZ”, that defines entire figures, sketches and plots, using a textual syntax.

Edit: Alternatively, there is a sub-language called “PSTricks”, which offers yet another way to do the same thing

And so a question which strikes me as important is, how to use these languages, even though I don’t know the syntax. And the answer is, ‘I use a GUI.’ That GUI mainly consists of the application ‘LyX’.

(Updated 3/07/2019, 17h55 … )

## How the EPUB2 and MOBI formats can be used for typeset Math.

According to This preceding posting, I was experiencing some frustration over trying to typeset Math, for publication in EPUB2 format. EPUB3 format with MathML support was a viable alternative, though potentially hard on any readers I might have.

Well a situation exists in which either EPUB2 or MOBI can be used to publish typeset Math: Each lossless image can claim the entire width of a column of text, and each image can represent an entire equation. That way, the content of the document can alternate vertically between Text and Typeset Math.

In fact, if an author was to choose to do this, he or she could also use the Linux-based solutions ‘LyX’ , ‘ImageMagick’ , and ‘tex4ebook’ .

(Edited 1/9/2019, 15h35 … )

## Trying to bridge the gap to mobile-friendly reading of typeset equations, using EPUB3?

One of the sad facts about this blog is, that it’s not very mobile-friendly. The actual WordPress Theme that I use is very mobile-friendly, but I have the habit of inserting links into postings, that open typeset Math, in the form of PDF Files. And the real problem with those PDF Files is, the fact that when people try to view them on, say, smart-phones, the Letter-Sized page format forces them to pinch-zoom the document, and then to drag it around on their phone, not getting a good view of the overall document.

And so eventually I’m going to have to look for a better solution. One solution that works, is just to output a garbled PDF-File. But something better is in order.

A solution that works in principle, is to export my LaTeX -typeset Math to EPUB3-format, with MathML. But, the other EPUB and/or MOBI formats just don’t work. But the main downside after all that work for me is, the fact that although there are many ebook-readers for Android, there are only very few that can do everything which EPUB3 is supposed to be able to do, including MathML. Instead, the format is better-suited for distributing prose.

One ebook-reader that does support EPUB3 fully, is called “Infinity Reader“. But if I did publish my Math using EPUB3 format, then I’d be doing the uncomfortable deed, of practically requiring that my readers install this ebook-reader on their smart-phones, for which they’d next need to pay a small in-app purchase, just to get rid of the ads. I’d be betraying all those people who, like me, prefer open-source software. For many years, some version of ‘FBReader’ has remained sufficient for most users.

Thus, if readers get to read This Typeset Math, just because they installed that one ebook-reader, then the experience could end up becoming very disappointing for them. And, I don’t get any kick-back from ImeonSoft, for having encouraged this.

I suppose that this cloud has a silver lining. There does exist a Desktop-based / Laptop-based ebook-reader, which is capable of displaying all these EPUB3 ebooks, and which is as free as one could wish for: The Calibre Ebook Manager. When users install this either under Linux or under Windows, they will also be able to view the sample document I created and linked to above.

(Updated 1/6/2019, 6h00 … )

## Integrating Sage with LyX

I have been interested in the LaTeX typesetting system, but not in actually learning the extra syntax. And so I’ve been using a WYSIWYM GUI named ‘LyX‘. The .TEX-Files LyX exports are suitable to creating HTML Files, which in turn can contain typeset Math, by way of scripts, that provide MathJax code.

But then one compromise this has meant for me was, that I could either typeset Math which I had written myself, or that I could do Computer Algebra, the latter through the use of ‘wxMaxima’, which has its own system of exporting to HTML. But so far, I could not do both in one document.

Well, now that I have ‘SageMath’ and ‘SageTeX’ installed, I can do both within the same document. It’s possible to integrate SageTeX into LyX. The following is an article which explains how to do that, under the assumption that the user has both SageTeX and LyX installed:

https://wiki.lyx.org/Layouts/Modules#toc7

There is an important way in which I needed to modify the instructions however, to get the two working. First of all, there is a list of files to download – LyX does not support SageTeX out of the box – that the article above links to. Out of those files, ‘setup.sh’ is absolutely useless on a modern Linux computer. The following files from the repository above are essential:

1. sage.module
2. preferences
3. compile-pdf-sage.sh
4. example.lyx

The file ‘preferences’ needs to be edited, in that its last line needs to be uncommented.

The file ‘compile-pdf-sage.sh’ needs to be edited, in that the first two lines need to be commented out, and the next three lines which are commented by default, need to be uncommented. Then:


(As user:)

$mkdir -p ~/.lyx/layouts$ cp sage.module ~/.lyx/layouts
\$ cat preferences >> ~/.lyx/preferences

(As root:)

# cp compile-pdf-sage.sh /usr/local/bin
# chmod a+x /usr/local/bin/compile-pdf-sage.sh




Then, within the GUI of LyX, one gives the command ‘Tools -> Reconfigure’. One shuts down and restarts LyX. Next, one opens ‘example.lyx’ to test the setup. The following is the document which I finally obtained (successfully), which was provided by the Web-site above (not written by me):

http://dirkmittler.homeip.net/sg_lyx_1.pdf

(Update 2/22/2019, 2h05 : )

I suppose that I should warn other users, that, even when one has ‘installed’ this extension to LyX properly, it will not cause SageMath figures to appear in the editing view. Instead, the editing view will contain the actual SageTex code. But, when one clicks on ‘File -> Export -> PDF (pdflatex+sagetex)’, then, a PDF-File will be output that contains the figures, such as the PDF File above.

(Update 2/24/2019, 15h15 : )

I can also elaborate that, the editing of the two text files which I recommended above, merely has as purpose, to enable the use of the module in a single-step process, which is by default written to work in a two-stage process.

The way in which the author of the module intended for it to be used was, that users should click on ‘File -> Export -> SageTex’, and obtain a LaTeX File, which they’d need to compile from the command-line, to arrive at an actual document. The supposed advantage of that would have been, that users could also edit the SageTex File output, before compiling it.

But the way the module was originally written – by the same author – allows for a PDF File to be output, with a single click from within LyX, when those two text files are edited as he recommended, and as I wrote above. I felt that it would be more satisfying both for me, and perhaps for readers of this blog, to be able to obtain a document in one click. And when the two files have been edited like that, the option still exists within the GUI, to export to SageTex format, which can still be compiled from the command-line…

I should add that, if the goal was to compile this sort of file from the command-line, then, it becomes necessary to obtain a Sage-File, if need be from the .TEX-File, and then actually to run ‘sage’ on the Sage-File, at which point Sage is performing its Math. Only after that, can the corresponding .TEX-File be compiled for a second time, into a document that displays correctly. If the step was omitted, to run Sage on the Sage-File, then at no point will the final document actually contain solved Math.

I suppose that a further question could be asked which would be:

‘In the one-step process, “pdflatex” is used twice, as it should be. But if we wanted output in some other format, would it be possible to Export the document from LyX as a SageTex document, and then merely to run “latex” on it, where appropriate?’

And the short answer is, ‘Only if the .TEX-File is edited accordingly.’ The slightly longer answer would be:

As it stands, the .TEX-File will export images into a separate folder, as .PDF-Files, that contain the plots. The simpler ‘latex’ command cannot use anything other than .EPS-Files as images. So the .TEX-File would need to be modified, to generate the .EPS-File (by deleting any occurrences of ‘[pdf]’), and then in principle, EPS Images should be generated, alongside PDF Images, and the .EPS-Files used.

Just to make the above exercise more confusing, a .DVI-File will be output, which ‘xdvi’ might not preview correctly, in that it will seem to contain a blank rectangle where the plot should be. The error message is then output by ‘xdvi’, that ‘gs’ doesn’t recognize the output device ‘x11′. Yet, when ‘dvips’ is next run on the .DVI-File, a correct .PS-File results, that contains the plot.

This modern problem with ‘xdvi’ can be solved, by installing the package ‘ghostscript-x’, which enhances the way ‘gs’ works, and also allows ‘xdvi’ to preview the .DVI-File properly.

Further, a plausible question could be:

‘What will happen if I simply click on “File -> Export -> Sage” ?’

And AFAIK the answer would be, that the file output only contains the Math for Sage to solve. The rest of the LyX Document, with text etc., will not be contained in that file.

(Update 2/24/2019, 16h20 : )

I suppose that yet another plausible question to ask might be, ‘What advantage did the author see, in a two-step process, that requires manual compilation?’

The best answer I can think of would be:

The actual step of running ‘sage’ on the Sage-File, is also the slowest. A situation is conceivable in which the actual Math to solve is very complex, but in which minor editing of the document is needed, after which to recompile would not require that the Math be redone.

For the purposes of this posting, the computer is fast, the Math is still straightforward, and the reader needs an easy-to-follow guide on how to get the integration of ‘SageTex’ into ‘LyX’ working.

(Update 2/25/2019, 8h45 : )

Since some of my readers may want to obtain a preview of their document, before actually exporting the final PDF, if the configuration files have been edited as I wrote, the way to do that is ‘Document -> View (Other Formats) -> PDF (pdflatex+sagetex)’.

Enjoy,

Dirk