Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geogebra material-id implemented using implicit slate #2238

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion examples/sample-article/sample-article.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8203,6 +8203,16 @@ along with MathBook XML. If not, see <http://www.gnu.org/licenses/>.

<p>Then mimic the examples that follow, using GeoGebra API commands documented at <url href="https://wiki.geogebra.org/en/Reference:GeoGebra_Apps_API">Geogebra API Manual</url>, but do not include the <c>ggbApplet.</c> or <c>applet.</c> used in examples to prefix the functions<mdash/>that part of the code will be provided automatically by <pretext/>.</p>

<p>There are some optional control elements that Geogebra provides, such as the presence of the toolbar and the reset button. These can be controlled by adding the following additional attributes to the <c>slate</c> and are automatically included in the initialization for the Geogebra applet.
<ul>
<li><p><c>toolbar="yes"</c>: add the Geogebra toolbar above the material</p></li>
<li><p><c>algebra-input="yes"</c>: add an entry box below the material to add graphical objects using algebra formulas or Geogebra graphical commands</p></li>
<li><p><c>reset-icon="yes"</c>: enable the reset icon</p></li>
<li><p><c>shift-drag-zoom="yes"</c>: enable ability to drag and zoom the viewing context</p></li>
<li><p><c>zoom-buttons="yes"</c>: enable buttons that control zoom</p></li>
</ul>
</p>

<p>Jack Green created an applet on the Classroom Resources site with ID <c>D4s2v4ft</c>, which you may view at <url href="https://www.geogebra.org/m/D4s2v4ft" visual="www.geogebra.org/m/D4s2v4ft"/>. Suppose you would like to use this in your project, but change something about it. We will change something trivial, making the <m>y</m>-axis ticks be separated <m>5</m> apart instead of <m>10</m> apart. We also decide we want a different aspect ratio and overall width. One gotcha: the original applet is loaded and then <pretext/> uses <attr>width</attr> and <attr>aspect</attr> attributes to resize the viewing window using the top left corner as an anchor. This does not rescale axes and that may leave you with important elements missing from the viewing window. So here we reset the viewing window to return to values that are in the original. Lastly, we disable zooming, which is not helpful for this applet. To do each of these things, we rely on the GeoGebra API manual at <url href="https://wiki.geogebra.org/en/Reference:GeoGebra_Apps_API" visual="wiki.geogebra.org/en/Reference:GeoGebra_Apps_API">Geogebra API Manual</url>. It is important to use one command per line.</p>

<figure>
Expand Down Expand Up @@ -8577,7 +8587,7 @@ along with MathBook XML. If not, see <http://www.gnu.org/licenses/>.

<p>Once you find a material that looks instructive, it will be at a <init>URL</init> such as<cd>https://www.geogebra.org/m/KGn2d4Qd</cd> and you want to pick off the identifier on the end, in this case <c>KGn2d4Qd</c>. Then author<cd>&lt;interactive geogebra="KGn2d4Qd" /&gt;</cd> At this writing (2018-02-04) you will want to place this inside a <c>figure</c>, with a caption, as we do right now with material <c>KGn2d4Qd</c>.</p>

<p>The shape of the material will be fixed, so guess (or measure with an on-screen ruler), the aspect ratio and use that in the <tag>interactive</tag> element. If the width of the original material is anything other than 800 pixels, you should add <attr>material-width</attr> with the actual material width (units are pixels).</p>
<p>The shape of the material will be fixed, so determine the dimensions (measure with an on-screen ruler or inspect the underlying definition). Use <attr>material-width</attr> and <attr>material-height</attr> with the actual material width and height (units are pixels). These are treated by Geogebra as internal coordinate dimensions and are separate from the physical layout dimensions that appear in your text. In the absence of these attributes, default values are 800 pixels for the width and a height based on the provied aspect ratio.</p>

<figure>
<caption>Right Triangle Paradox</caption>
Expand All @@ -8590,6 +8600,7 @@ along with MathBook XML. If not, see <http://www.gnu.org/licenses/>.
<li><p><c>algebra-input="yes"</c>: add an entry box below the material to add graphical objects using algebra formulas or Geogebra graphical commands</p></li>
<li><p><c>reset-icon="yes"</c>: enable the reset icon</p></li>
<li><p><c>shift-drag-zoom="yes"</c>: enable ability to drag and zoom the viewing context</p></li>
<li><p><c>zoom-buttons="yes"</c>: enable buttons that control zoom</p></li>
</ul>
</p>

Expand Down
89 changes: 89 additions & 0 deletions xsl/pretext-assembly.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,95 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
</xsl:if>
</xsl:template>

<!-- ######################################## -->
<!-- Enrichment of Geogebra interactives -->
<!-- ######################################## -->

<!-- Expand reference to Geogebra by material-id to use -->
<!-- an implicit applet approach with a slate to better -->
<!-- facilitate all of the applet control parameters. -->
<xsl:template match="interactive[@geogebra]" mode="enrichment">
<xsl:param name="default-aspect" select="'1:1'" />
<xsl:variable name="ggbMaterialWidth">
<xsl:choose>
<xsl:when test="@material-width">
<xsl:value-of select="@material-width"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>800</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="aspect-ratio">
<xsl:apply-templates select="." mode="get-aspect-ratio">
<xsl:with-param name="default-aspect" select="$default-aspect" />
</xsl:apply-templates>
</xsl:variable>
<xsl:variable name="ggbMaterialHeight">
<xsl:choose>
<xsl:when test="@material-height">
<xsl:value-of select="@material-height"/>
</xsl:when>
<xsl:when test="$aspect-ratio=''"/>
<xsl:otherwise>
<xsl:value-of select="round($ggbMaterialWidth div $aspect-ratio)" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="slate-copy-attr" select="'toolbar algebra-input reset-icon shift-drag-zoom zoom-buttons'"/>
<xsl:variable name="interactive-drop-attr" select="concat($slate-copy-attr, ' geogebra material-width material-height')"/>
<interactive>
<xsl:attribute name="platform">
<xsl:text>geogebra</xsl:text>
</xsl:attribute>
<xsl:if test="not(@aspect)">
<xsl:attribute name="aspect">
<xsl:value-of select="$aspect-ratio"/>
</xsl:attribute>
</xsl:if>
<!-- Restore all of the original attributes not processed separately -->
<xsl:copy-of select="@*[not(contains($interactive-drop-attr, local-name()))]"/>
<slate>
<xsl:attribute name="xml:id">
<xsl:value-of select="@assembly-id"/>
<xsl:text>-ggb-slate</xsl:text>
</xsl:attribute>
<xsl:attribute name="surface">
<xsl:text>geogebra</xsl:text>
</xsl:attribute>
<xsl:attribute name="material">
<xsl:value-of select="@geogebra"/>
</xsl:attribute>
<xsl:attribute name="material-width">
<xsl:value-of select="$ggbMaterialWidth"/>
</xsl:attribute>
<xsl:if test="$ggbMaterialHeight != ''">
<xsl:attribute name="material-height">
<xsl:value-of select="$ggbMaterialHeight"/>
</xsl:attribute>
</xsl:if>
<xsl:copy-of select="@*[contains($slate-copy-attr, local-name())]"/>
</slate>
</interactive>
</xsl:template>

<!-- The following attributes are transferred from the #interactive -->
<!-- to the corresponding generated #slate when material-id is given -->
<!-- Cut them from the interactive parent. -->
<xsl:template match="interative/@geogebra
| interactive[@geogebra]/@toolbar
| interactive[@geogebra]/@algebra-input
| interactive[@geogebra]/@reset-icon
| interactive[@geogebra]/@shift-drag-zoom
| interactive[@geogebra]/@material-width
| interactive[@geogebra]/@material-height" mode="enrichment" />

<xsl:template match="@toolbar|@algebra-input|@reset-icon|@shift-drag-zoom|@material-width|@material-height" mode="geogebra-slate-attributes">
<xsl:copy-of select="node()"/>
</xsl:template>
<!-- No other attributes are transferred to the slate. -->
<xsl:template match="*" mode="geogebra-slate-attributes"/>


<!-- ############# -->
<!-- Source Repair -->
Expand Down
159 changes: 69 additions & 90 deletions xsl/pretext-html.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -9479,87 +9479,6 @@ along with MathBook XML. If not, see <http://www.gnu.org/licenses/>.
</iframe>
</xsl:template>

<!-- Geogebra -->
<!-- Similar again, but with options fixed -->
<xsl:template match="interactive[@geogebra]" mode="iframe-interactive">
<xsl:param name="default-aspect" select="'1:1'" />
<xsl:variable name="ggbToolBar">
<xsl:choose>
<xsl:when test="@toolbar='yes'">
<xsl:text>true</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>false</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="ggbAlgebraInput">
<xsl:choose>
<xsl:when test="@algebra-input='yes'">
<xsl:text>true</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>false</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="ggbResetIcon">
<xsl:choose>
<xsl:when test="@reset-icon='yes'">
<xsl:text>true</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>false</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="ggbShiftDragZoom">
<xsl:choose>
<xsl:when test="@shift-drag-zoom='yes'">
<xsl:text>true</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>false</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="ggbMaterialWidth">
<xsl:choose>
<xsl:when test="@material-width">
<xsl:value-of select="@material-width"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>800</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="aspect-ratio">
<xsl:apply-templates select="." mode="get-aspect-ratio">
<xsl:with-param name="default-aspect" select="$default-aspect" />
</xsl:apply-templates>
</xsl:variable>
<xsl:variable name="ggbMaterialHeight">
<xsl:choose>
<xsl:when test="@material-height">
<xsl:value-of select="@material-height"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="round($ggbMaterialWidth div $aspect-ratio)" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- iframe options not implemented: -->
<!-- smb = show menu bar -->
<!-- asb = allow style bar -->
<!-- rc = enable right click options -->
<!-- ld = enable label drag -->
<!-- ctl = click to launch -->
<iframe src="https://www.geogebra.org/material/iframe/id/{@geogebra}/width/{$ggbMaterialWidth}/height/{$ggbMaterialHeight}/border/888888/smb/false/stb/{$ggbToolBar}/stbh/{$ggbToolBar}/ai/{$ggbAlgebraInput}/asb/false/sri/{$ggbResetIcon}/rc/false/ld/false/sdz/{$ggbShiftDragZoom}/ctl/false">
<xsl:apply-templates select="." mode="html-id-attribute"/>
<xsl:apply-templates select="." mode="size-pixels-attributes" />
</iframe>
</xsl:template>

<!-- CalcPlot3D -->
<!-- A bit more complicated, as the configuration -->
<!-- is a query string of a URL, and we can specify -->
Expand Down Expand Up @@ -9976,18 +9895,78 @@ along with MathBook XML. If not, see <http://www.gnu.org/licenses/>.
<xsl:value-of select="@geogebra" />
<xsl:text>",&#xa;</xsl:text>
</xsl:when>
<!-- Now must be authored in source, so we can check for -->
<!-- setting perspective via an attribute. This bypasses -->
<!-- a bug where using "setPerspective()" in source caused -->
<!-- the focus to be grabbed here. -->
<xsl:otherwise>
<xsl:if test="@perspective">
<xsl:text>perspective:"</xsl:text>
<xsl:value-of select="@perspective"/>
<xsl:text>",&#xa;</xsl:text>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
<!-- Perspective must be authored in source, so we can check -->
<!-- setting perspective via an attribute. This bypasses a -->
<!-- bug where using "setPerspective()" in source caused the -->
<!-- focus to be grabbed here. -->
<xsl:if test="@perspective">
<xsl:text>perspective:"</xsl:text>
<xsl:value-of select="@perspective"/>
<xsl:text>",&#xa;</xsl:text>
</xsl:if>
<xsl:if test="@toolbar">
<xsl:text>showToolBar: </xsl:text>
<xsl:choose>
<xsl:when test="@toolbar='yes'">
<xsl:text>true</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>false</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:text>,&#xa;</xsl:text>
</xsl:if>
<xsl:if test="@algebra-input">
<xsl:text>showAlgebraInput: </xsl:text>
<xsl:choose>
<xsl:when test="@algebra-input='yes'">
<xsl:text>true</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>false</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:text>,&#xa;</xsl:text>
</xsl:if>
<xsl:if test="@reset-icon">
<xsl:text>showResetIcon: </xsl:text>
<xsl:choose>
<xsl:when test="@reset-icon='yes'">
<xsl:text>true</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>false</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:text>,&#xa;</xsl:text>
</xsl:if>
<xsl:if test="@shift-drag-zoom">
<xsl:text>enableShiftDragZoom: </xsl:text>
<xsl:choose>
<xsl:when test="@shift-drag-zoom='yes'">
<xsl:text>true</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>false</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:text>,&#xa;</xsl:text>
</xsl:if>
<xsl:if test="@zoom-buttons">
<xsl:text>showZoomButtons: </xsl:text>
<xsl:choose>
<xsl:when test="@zoom-buttons='yes'">
<xsl:text>true</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>false</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:text>,&#xa;</xsl:text>
</xsl:if>
<xsl:text>width:</xsl:text><xsl:value-of select="$material-width" />
<xsl:text>,&#xa;</xsl:text>
<xsl:text>height:</xsl:text><xsl:value-of select="$material-height" />
Expand Down