-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.Rmd
184 lines (104 loc) · 6.33 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
---
output:
github_document:
pandoc_args: --webtex
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
[![Lifecycle:
experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental)
<!-- badges: end -->
# ggtex-gawk
# Description
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.awk` is a tiny script written in [the `gawk` language](https://www.gnu.org/software/gawk/) to translate from modified LaTeX math mode to Geogebra code to define text objects.
With `ggtex.awk`, while using your favorite LaTeX text editor, you can reference Geogebra objects surrounding them with the symbol `@`.
If you want to preview the contents of your text, you can use the preview feature of your LaTeX editor, or you can compile your LaTeX document to your favorite format.
When you are done editing your math text in, say, file `mymath.tex`, you use `ggtex.awk` to convert it to file `mymath.gg.tex`, which is still valid LaTeX but now contains the Geogebra definitions of all math text in the original file.
You can compile the converted file `mymath.gg.tex` (e.g., to PDF) if you wish.
When you're satisfied, you can copy each chunk of Geogebra math code (contained in a verbatim environment in the `gg.tex` file) and paste it into the Geogebra input bar.
`ggtex.awk` is a command-line script. It must be run in a terminal.
You need to have the [GNU awk (`gawk`) language](https://www.gnu.org/software/gawk/) installed to run `ggtex.awk`.
# Installation
## GNU-Linux
1. Install `gawk` using your package manager or from [this site](https://pkgs.org/download/gawk).
1. [Download the file `ggtex.awk`](https://cdn.jsdelivr.net/gh/fnaufel/ggtex-gawk@latest/ggtex.awk) and save it somewhere, preferably in `~/bin`.
1. Make it executable (if necessary, replace `~/bin` with the directory where you saved the file):
```
chmod a+x ~/bin/ggtex.awk
```
## Windows
1. Install `gawk` from [this site](http://gnuwin32.sourceforge.net/packages/gawk.htm).
1. [Download the file `ggtex.awk`](https://cdn.jsdelivr.net/gh/fnaufel/ggtex-gawk@latest/ggtex.awk) and save it somewhere.
# Usage
## Using `ggtex.awk` on GNU-Linux
### Method 1
1. Suppose you saved the `ggtex.awk` file as `path/to/ggtex.awk` and made it executable.
1. Open a terminal running bash.
1. To convert a file named `path/to/file.tex`, enter
```
path/to/ggtex.awk path/to/file.tex
```
or, if `ggtex.awk` was saved in a directory in your PATH, enter
```
ggtex.awk path/to/file.tex
```
1. The translated code will be saved in file `path/to/file.gg.tex`. Open it in any text editor, copy the contents of the desired verbatim environment and paste them into the Geogebra input bar.
### Method 2
1. Suppose you saved the `ggtex.awk` file as `path/to/ggtex.awk`.
1. Open a terminal running bash.
1. To convert a file named `path/to/file.tex`, enter
```
gawk -f path/to/ggtex.awk path/to/file.tex
```
1. The translated code will be saved in file `path/to/file.gg.tex`. Open it in any text editor, copy the contents of the desired verbatim environment and paste them into the Geogebra input bar.
## Using `ggtex.awk` on Windows
### Method 1
1. This will work if your Windows system is configured to execute `.awk` files by sending them to the `gawk` interpreter. If it doesn't work, try method 2 below.
1. Suppose you saved the `ggtex.awk` file as `C:\path\to\ggtex.awk`.
1. Open a terminal.
1. To convert a file named `C:\path\to\file.tex`, enter
```
C:\path\to\ggtex.awk C:\path\to\file.tex
```
1. The translated code will be saved in file `C:\path\to\file.tex.ggtex`. Open it in any text editor, copy the contents of the desired verbatim environment and paste them into the Geogebra input bar.
### Method 2
1. Suppose you saved the `ggtex.awk` file as `C:\path\to\ggtex.awk`.
1. Open a terminal.
1. To convert a file named `C:\path\to\file.tex`, enter
```
gawk -f C:\path\to\ggtex.awk C:\path\to\file.tex
```
1. The translated code will be saved in file `C:\path\to\file.tex.ggtex`. Open it in any text editor, copy the contents of the desired verbatim environment and paste them into the Geogebra input bar.
# How to write LaTeX code for `ggtex.awk`
* The file passed to `ggtex.awk` can be a full LaTeX source document. `ggtex.awk` will ignore everything outside of display math --- i.e., everything outside of blocks delimited by `\[` and `\]`.
* There may be more than one math display blocks in the file. All of them will be converted to Geogebra math code.
* If you want to display text in Geogebra along with the math, use `\text{}` inside your math display block.
* 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:
```LaTeX
\boxed{
\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.awk` and entered in Geogebra, renders as
![](examples/example.png)
* Try this example and play with the sliders in Geogebra.
* See the original and converted files in the [examples folder](examples).
# Useful Geogebra functions for text objects
* The [Geogebra text command reference](https://wiki.geogebra.org/en/Text_Commands) 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](https://wiki.geogebra.org/en/CAS_Specific_Commands) can also be useful in text objects.