LyXInstant Preview of Tikz/Pgfplots figures from external files

Information and discussion about LyX, a WYSIWYM editor, available for Linux, Windows and Mac OS X systems.
Post Reply
Deve
Posts: 8
Joined: Mon May 18, 2015 10:12 am

Instant Preview of Tikz/Pgfplots figures from external files

Post by Deve »

Hi all, I think I best start with what I'm trying to achieve before describing my actual problem(s):

I would like to insert Tikz/Pgfplots figures stored in external files into my LyX document. The figures should be inside a figure float and an instant preview of the Pgfplots figure should be displayed in LyX. Ideally, I'm able to open the Pgfplots file in an external editor, edit and save it, and see the updated preview in Lyx. I have partly achieved the above, but never fully. Here is what I've tried:
  • Insert the Pgfplots file via "Insert/File/Child Document...", choose Include Type "Input" and check the "Show preview" box. This works outside the float environment but inside a float, no preview is created.
  • Insert the Pgfplots file via "Insert/File/Child Document..." into a preview box which in turn is inside a figure float. This renders the preview but the preview is never updated unless I close the document and open it again.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Deve
Posts: 8
Joined: Mon May 18, 2015 10:12 am

Instant Preview of Tikz/Pgfplots figures from external files

Post by Deve »

During writing the above post I came across the solution and thought I would just share it here in case anyone else has the same problem in the future. The trick is to close and reopen the LyX document after inserting the external file for the first time. In detail:
  1. Create a figure float
  2. Choose "Insert/File/Child Document.."
  3. In the following dialog choose the file, the Include Type "Input" and check the "Show preview" box. Press OK.
  4. Close the document and reopen it
After some time (depends on the complexity of the inserted figure, I guess), the preview of the figure should appear. You can now click on the figure preview, press "Edit", edit the file and close the dialog, and the updated preview appears (without reopening the document). Perfect! :D
Post Reply