1

I am searching for a good tool for graphs and charts and found Graphics Layout Engine. Am I able to include a code written in GLE within a latex document? The aim is not including it as a file in the document but as a script within the latex script, is it possible?

Thank you

  • 3
    Of course you are if you're willing to write an interpreter in TeX that reads that format (I never heard of one as of now). Note however that there are packages like pgfplots and TikZ around, which also enable you to produce high quality plots and images. – Skillmon Apr 1 '18 at 17:37
  • 1
    that page says that it will generate pdf, which you can then include into latex – David Carlisle Apr 1 '18 at 17:45
  • 1
    It really depends on what tool you can use and how far you want to go. If you use MATLAB, you can create your figures and print them as eps or other vector or raster graphics formats. If you use python, you can do the same with the matplotlib library. If you want to go deep in the code to fully control the output, you may use pgfplots of TikZ as proposed by @Skillmon ... – BambOo Apr 1 '18 at 17:59
  • 2
    In addition to @BambOo: Python's matplotlib can export to pgf-code which can be included directly into your LaTeX document with the pgf (or TikZ) package. This way every font aspect should match the rest of your document (but it might really slow down your compilation process). – Skillmon Apr 1 '18 at 18:11
  • 1
    Right, so the suggested duplicate doesn't fit. (I've voted to reopen.) I don't know whether such a thing exists, in the meantime you can of course use David's suggestion. – Torbjørn T. Apr 2 '18 at 6:24
1

You can insert the GLE code in your document, write it to a temporary file, call GLE on this file, and include the output as an image. Writing the contents of an environment to a file can be done with \VerbatimOut from the fancyvrb package, see Write environment body verbatim to a file. Calling an external program can be done with \immediate\write18 (see for example https://stackoverflow.com/questions/3252957/how-to-execute-shell-script-from-latex), which requires the --shell-escape flag when compiling the document.

A counter called glenum is used to prevent caching by creating different filenames in case you want to compile more than one figure.

MWE:

\documentclass{article}
\usepackage{graphicx}
\usepackage{fancyvrb}
\newcounter{glenum}
\setcounter{glenum}{0}
\newenvironment{GLEinclude}[1]
  {\xdef\mywd{#1}\VerbatimOut{\jobname.\theglenum.gle}}
  {\endVerbatimOut%
  \immediate\write18{gle -output \jobname.\theglenum.gle.pdf \jobname.\theglenum.gle}%
  \includegraphics[width=\mywd]{{\jobname.\theglenum.gle}.pdf}%
  \stepcounter{glenum}%
  }

\begin{document}
Here is a tree fractal compiled with GLE:

\begin{GLEinclude}{5cm}
size 32 22

a = 3; b = 4; c = sqrt(a^2+b^2)

sub pythagorean n
   local red   = (34+n*92)/(n+1)
   local green = (139+n*64)/(n+1)
   local blue  = (34+n*51)/(n+1)
   box c c fill rgb255(red,green,blue)
   if n = 0 then return
   begin translate c c
      begin rotate todeg(-acos(a/c))
         begin scale a/c a/c
            begin translate -c 0
               pythagorean n-1
            end translate
         end scale
      end rotate
   end translate
   begin translate 0 c
      begin rotate todeg(acos(b/c))
         begin scale b/c b/c
            pythagorean n-1
         end scale
      end rotate
   end translate
end sub

begin translate 16 0
   pythagorean 10
end translate
\end{GLEinclude}

Also known as a \textbf{Pythagorean tree}.
\end{document}

Result:

enter image description here

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.