You can define text objects in Geogebra containing complex math in LaTeX math mode, but the editor Geogebra offers for this is not very convenient.
For example, you must use your mouse to open a drop-down list and select an item everytime you want to insert the value of a Geogebra object (i.e., a number, a formula etc.) in the text.
ggtex
is a tiny Python script to translate from modified LaTeX math
mode to Geogebra code to define text objects.
With ggtex
, you can use your favorite text editor to define your
Geogebra text object. In your definition, you can include Geogebra
objects delimited by the symbol @
.
If you want to preview the contents of your text, you can use the preview feature of your LaTeX editor, or copy your text to a full LaTeX document and compile it to your favorite format.
When you are done defining your text, you use ggtex
to translate it to
Geogebra code, which you must then copy and paste into the Geogebra
input bar.
For example, if you pass ggtex
a file example.tex
containing
\[
@a@ x^2 + @FractionText(b)@ x = 0
\]
then ggtex
will output a file example.tex.ggtex
with contents
FormulaText(Simplify(
a + " x^2 + " + FractionText(b) + " x = 0"
))
If a
is a number defined in your Geogebra session with value, say, 10,
and b
is a number with value, say, 2.5, then this code, when entered
in the Geogebra input bar, will produce a text object containing
ggtex
is a command-line script. It must be run in a terminal.
-
You need to have some version of Python 3 installed.
-
Download the file
ggtex.py
and save it somewhere, preferably in~/bin
. -
Make it executable (if necessary, replace
~/bin
with the directory where you saved the file):chmod a+x ~/bin/ggtex.py
-
You need to have the docopt module, which can be installed with
pip3 install docopt
-
You need to have some version of Python 3 installed.
-
Download the file
ggtex.py
and save it somewhere. -
You need to have the docopt module, which can be installed with
pip3 install docopt
entered at the terminal.
-
Make sure the file
ggtex.py
is in a directory in your Python Module Search Path (PMSP). Check the contents of your PMSP by executing the following at the Python prompt:import sys sys.path
-
At the Python prompt, enter
from ggtex import ggtex
-
To convert a file named
path/to/file.tex
, enterggtex('path/to/file.tex')
-
The translated code will be saved in file
path/to/file.tex.ggtex
. Open it in any text editor, copy its entire contents and paste them into the Geogebra input bar.
-
Suppose you saved the
ggtex.py
file aspath/to/ggtex.py
and made it executable. -
Open a terminal running bash.
-
To convert a file named
path/to/file.tex
, enterpath/to/ggtex.py path/to/file.tex
or, if
ggtex.py
was saved in a directory in your PATH, enterggtex.py path/to/file.tex
-
The translated code will be saved in file
path/to/file.tex.ggtex
. Open it in any text editor, copy its entire contents and paste them into the Geogebra input bar.
-
Suppose you saved the
ggtex.py
file aspath/to/ggtex.py
. -
Open a terminal running bash.
-
To convert a file named
path/to/file.tex
, enterpython3 path/to/ggtex.py path/to/file.tex
-
The translated code will be saved in file
path/to/file.tex.ggtex
. Open it in any text editor, copy its entire contents and paste them into the Geogebra input bar.
-
This will work if your Windows system is configured to execute
.py
files by sending them to the Python 3 interpreter. If it doesn’t work, try method 2 below. -
Suppose you saved the
ggtex.py
file asC:\path\to\ggtex.py
. -
Open a terminal.
-
To convert a file named
C:\path\to\file.tex
, enterC:\path\to\ggtex.py C:\path\to\file.tex
-
The translated code will be saved in file
C:\path\to\file.tex.ggtex
. Open it in any text editor, copy its entire contents and paste them into the Geogebra input bar.
-
Suppose you saved the
ggtex.py
file asC:\path\to\ggtex.py
. -
Open a terminal.
-
To convert a file named
C:\path\to\file.tex
, enterpython3 C:\path\to\ggtex.py C:\path\to\file.tex
-
The translated code will be saved in file
C:\path\to\file.tex.ggtex
. Open it in any text editor, copy its entire contents and paste them into the Geogebra input bar.
-
The file passed to
ggtex
must contain a LaTeX math snippet, optionally surrounded by display math markers\[
and\]
, not a complete LaTeX document. -
Everything in the snippet must be in math mode.
-
If you want to display text along with the math, use
\text{}
. -
You can embed Geogebra commands that generate text — e.g., values and definitions of Geogebra objects, fractions, formulae etc. — using the
@
delimiter. -
Here is a more complex example:
\fbox{ \textbf{Completing the square:}\\ \\ \begin{aligned} @a@ x^2 + @b@ x &= @a@ \left( x^2 + @FractionText(b/a)@ x \right) \\ &= @a@ \left( x^2 + @FractionText(b/a)@ x + @FractionText(b^2/(4*a^2))@ - @FractionText(b^2/(4*a^2))@ \right) \\ &= @a@ \left( x + @FractionText(b/(2a))@ \right)^2 - @FractionText(b^2/(4a))@ \end{aligned} }
-
This, after being translated by
ggtex
and entered in Geogebra, renders as -
Try this example and play with the sliders in Geogebra.
-
The Geogebra text command reference lists some pretty powerful functions to produce text objects such as
-
Continued fractions
-
Fraction representations/approximations of real numbers: try
FractionText(pi)
-
Numbers in scientific notation
-
Surd representations: try
SurdText(2.439230484541326)
-
and more
-
-
Geogebra’s Computer Algebra commands can also be useful in text objects.