Skip to content
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
6 changes: 4 additions & 2 deletions doc/guide/author/topics.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3538,7 +3538,7 @@ displayed line, and there are no <c>\\</c>s. Use <c>\amp</c> to mark the alignm
<subsection xml:id="interactive-program-codelens">
<title>Interactive Programs, CodeLens</title>

<p><term>CodeLens</term> is an interactive version of a computer program, which can be visualized by stepping through the code one statement at a time, watching output, variables, and other data structures change. So it is similar to a debugger, except the reader does not set breakpoints or modify program data on-the-fly. This is possible automatically for several different languages when your <init>HTML</init> is hosted on a Runestone server (<xref ref="runestone"/>). This may also be accomplished <q>in browser</q> when hosted on any old generic web server. The catch is that for a generic server a publisher must generate <term>trace data</term> in advance, typically with the PreTeXt-CLI (<xref ref="processing-CLI"/>). Place the <tag>interactive</tag> attribute on a <tag>program</tag> element with the value <c>codelens</c> to elect this behavior (<c>no</c> is the default value). Also, be sure to specify a language from the supported languages: Python, Java, C, and C++. Consult <xref ref="table-program-interactive"/> below for a summary of various combinations. When an output format does not support an interactive CodeLens instance, the fallback is a static program listing. The <tag>program</tag> should have an <attr>xml:id</attr> that will be used as a unique identifier for the generated trace file needed by the codelens.</p>
<p><term>CodeLens</term> is an interactive version of a computer program, which can be visualized by stepping through the code one statement at a time, watching output, variables, and other data structures change. So it is similar to a debugger, except the reader does not set breakpoints or modify program data on-the-fly. This is possible automatically for several different languages when your <init>HTML</init> is hosted on a Runestone server (<xref ref="runestone"/>). This may also be accomplished <q>in browser</q> when hosted on any old generic web server. The catch is that for a generic server a publisher must generate <term>trace data</term> in advance, typically with the PreTeXt-CLI (<xref ref="processing-CLI"/>). Place the <tag>interactive</tag> attribute on a <tag>program</tag> element with the value <c>codelens</c> to elect this behavior (<c>no</c> is the default value). Also, be sure to specify a language from the supported languages: Python, Java, C, and C++. Consult <xref ref="table-program-interactive"/> below for a summary of various combinations. When an output format does not support an interactive CodeLens instance, the fallback is a static program listing, possibly with a link to the interactive version (see <xref ref="interactive-program-activecode"/> for how to configure the links). The <tag>program</tag> should have an <attr>xml:id</attr> that will be used as a unique identifier for the generated trace file needed by the codelens.</p>

<p>Sometimes, there is uninteresting setup to get through before the portion of the program the author wants to illustrate. The author can use <attr>starting-step</attr> to specify the instruction number that the interactive should start at. Code before that will be fast-forwarded through and execution will begin at the indicted step. Note that <attr>starting-step</attr> is a <q>Step</q> number in the execution sequence, not a line number in the source code. You may have to run the Codelens once to find the right step to start at.</p>

Expand All @@ -3554,7 +3554,9 @@ displayed line, and there are no <c>\\</c>s. Use <c>\amp</c> to mark the alignm

<p><term>ActiveCode</term> is an interactive environment where a reader may work on code through repeated edit-compile-test cycles. Code can be provided by an author as a complete program to be modified, a partial program to be completed, or nothing at all. One good example is that maybe header files, import statement, and similar are provided, and a skeleton of a main entry-point procedure is also provided. Then a reader can concentrate on the more conceptual parts of the programming. Some languages will be executable <q>in browser</q> on any old generic web server, while others must be on a Runestone server (<xref ref="runestone"/>) where a <url href="https://github.com/trampgeek/jobe" visual="github.com/trampgeek/jobe">Jobe Server</url> is running to support the execution.</p>

<p>Place the <attr>interactive</attr> attribute on a <tag>program</tag> element with the value <c>activecode</c> to elect this behavior (<c>no</c> is the default value). Also, be sure to specify a language from the supported languages. Consult <xref ref="table-program-interactive"/> below for a summary of various combinations. When an output format does not support an interactive ActiveCode instance, the fallback is a static program listing.</p>
<p>Place the <attr>interactive</attr> attribute on a <tag>program</tag> element with the value <c>activecode</c> to elect this behavior (<c>no</c> is the default value). Also, be sure to specify a language from the supported languages. Consult <xref ref="table-program-interactive"/> below for a summary of various combinations.</p>

<p>When an output format does not support an interactive ActiveCode instance, the fallback is a static program listing. The static listing is possibly supplemented with a link and QR code to access an HTML version. To get these links, you must specify a base <init>URL</init> (see <xref ref="online-baseurl"/>). If you have a base <init>URL</init> and want to disable the QR codes, you can set the <attr>static-qrcodes</attr> attribute to no <c>"no"</c> in the publisher variable <c>common/program</c>.</p>

<warning>
<title>Labels and XML IDs</title>
Expand Down
2 changes: 1 addition & 1 deletion pretext/lib/pretext.py
Original file line number Diff line number Diff line change
Expand Up @@ -2644,7 +2644,7 @@ def qrcode(xml_source, pub_file, stringparams, xmlid_root, dest_dir):
# Simple version: qr_image = qrcode.make(url), has border
if has_image:
# error correction up to 25%
error_correction = qrcode.constants.ERROR_CORRECT_Q
error_correction = qrcode.constants.ERROR_CORRECT_H
else:
# error correction up to 7%
error_correction = qrcode.constants.ERROR_CORRECT_L
Expand Down
3 changes: 3 additions & 0 deletions xsl/entities.ent
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,6 @@
<!-- are added, then this need not change -->
<!-- Typical use: self::exercise and boolean(&INLINE-EXERCISE-FILTER;) -->
<!ENTITY INLINE-EXERCISE-FILTER "parent::article|parent::paragraphs|parent::chapter|parent::section|parent::subsection|parent::subsubsection|parent::handout">

<!-- interactive elements that need a QR code generated -->
<!ENTITY QRCODE-INTERACTIVES "audio[@source|@href]|video[@source|@href|@youtube|@youtubeplaylist|@vimeo]|interactive|program[@interactive != '' and @interactive != 'no']">
68 changes: 64 additions & 4 deletions xsl/extract-qrcode.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ You should have received a copy of the GNU General Public License
along with MathBook XML. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************-->

<!DOCTYPE xsl:stylesheet [
<!ENTITY % entities SYSTEM "entities.ent">
%entities;
]>

<!-- This stylesheet locates video/@youtube elements and -->
<!-- prepares a Python dictionary necessary to extract a -->
<!-- thumbnail for each video from the YouTube servers -->
Expand All @@ -36,6 +41,9 @@ along with MathBook XML. If not, see <http://www.gnu.org/licenses/>.
<xsl:import href="./pretext-assembly.xsl"/>
<xsl:import href="./pretext-common.xsl"/>

<!-- Need pretext-html to set up chunking for containing-filename -->
<xsl:import href="./pretext-html.xsl"/>

<!-- Get a "subtree" xml:id value -->
<!-- Then walk the XML source tree -->
<!-- applying specializations below -->
Expand All @@ -46,18 +54,70 @@ along with MathBook XML. If not, see <http://www.gnu.org/licenses/>.
<!-- Avoid Catch-22: default assembly/pre-processor providews output -->
<!-- for a conversion to a static format, but that format will *replace* -->
<!-- "audio", "video", "interactive" by a static version (a -->
<!-- "sidebyside") and it will not beavailable for extraction. -->
<!-- "sidebyside") and it will not be available for extraction. -->
<xsl:variable name="exercise-style" select="'dynamic'"/>

<!-- Are filters here irrelevant? Just for the implementation of "static-url"? -->
<xsl:template match="audio[@source|@href]|video[@source|@href|@youtube|@youtubeplaylist|@vimeo]|interactive" mode="extraction">
<!-- Make sure url's are generated with .html extension -->
<xsl:variable name="file-extension" select="'.html'"/>

<!-- Override extraction-wrapper so we can provide single error and not attempt -->
<!-- to write files if no base URL is defined. -->
<xsl:template match="*" mode="extraction-wrapper">
<xsl:choose>
<xsl:when test="$b-has-baseurl">
<xsl:message>PTX:INFO: Writing qrcode-urls.txt</xsl:message>
<xsl:apply-templates select="." mode="extraction"/>
</xsl:when>
<xsl:otherwise>
<xsl:message>PTX:ERROR: Base URL must be specified to generate QR codes</xsl:message>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<!-- Standard traversal generates temp text file for python qrcode generation -->
<xsl:template match="&QRCODE-INTERACTIVES;" mode="extraction">
<!-- Each line of the text file is a URL, space, assembly-id -->
<xsl:apply-templates select="." mode="static-url"/>
<!-- Do not use a comma, since a YouTube playlist has -->
<!-- commas as separators, and they show up in the URL. -->
<!-- So a space instead. See comments in Python consumer. -->
<xsl:text> </xsl:text>
<xsl:apply-templates select="." mode="visible-id" />
<xsl:variable name="assembly-id">
<xsl:apply-templates select="." mode="assembly-id"/>
</xsl:variable>
<xsl:value-of select="$assembly-id"/>
<xsl:text>&#xa;</xsl:text>

<!-- Also generate a sidecar XML file with name based on assembly-id -->
<!-- File will contain the URL for this interactive. -->
<!-- For URLs within the book, static outputs will not be able to use -->
<!-- mode="static-url" directly, as it depends on the chunking set by -->
<!-- the HTML conversion. So generate now and save to file. -->
<exsl:document href="{$generated-directory-source}qrcode/{$assembly-id}-url.xml" method="xml" indent="yes" encoding="UTF-8">
<interactive-url>
<xsl:attribute name="url">
<xsl:apply-templates select="." mode="static-url"/>
</xsl:attribute>
</interactive-url>
</exsl:document>
</xsl:template>

<!-- Second traversal to generate XML file with URLS that is part of final product -->
<xsl:template match="@*|node()" mode="url-extraction">
<xsl:apply-templates select="@*|node()" mode="url-extraction"/>
</xsl:template>

<xsl:template match="&QRCODE-INTERACTIVES;" mode="url-extraction">
<interactive-url>
<xsl:attribute name="url">
<xsl:apply-templates select="." mode="static-url"/>
</xsl:attribute>
<!-- need to use assembly-id as the value will be read during representations -->
<!-- pass of assembly before visible-id is available -->
<xsl:attribute name="id">
<xsl:apply-templates select="." mode="assembly-id" />
</xsl:attribute>
</interactive-url>
</xsl:template>

</xsl:stylesheet>
1 change: 1 addition & 0 deletions xsl/localizations/af-ZA.xml
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
<!-- <localization string-id='query'>Query</localization> -->
<localization string-id='program-activecode'>ActiveCode</localization>
<localization string-id='program-codelens'>CodeLens</localization>
<!-- <localization string-id='program-interactive-available'>Interactive program</localization> -->
<!-- Back matter components -->
<!-- index-part is deprecated, but not abandoned -->
<!-- NB: repurpose translations, maybe move appendix here -->
Expand Down
1 change: 1 addition & 0 deletions xsl/localizations/bg-BG.xml
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
<!-- <localization string-id='query'>Query</localization> -->
<localization string-id='program-activecode'>ActiveCode</localization>
<localization string-id='program-codelens'>CodeLens</localization>
<!-- <localization string-id='program-interactive-available'>Interactive program</localization> -->
<!-- Back matter components -->
<!-- index-part is deprecated, but not abandoned -->
<!-- NB: repurpose translations, maybe move appendix here -->
Expand Down
1 change: 1 addition & 0 deletions xsl/localizations/ca-ES.xml
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
<!-- <localization string-id='query'>Query</localization> -->
<localization string-id='program-activecode'>ActiveCode</localization>
<localization string-id='program-codelens'>CodeLens</localization>
<!-- <localization string-id='program-interactive-available'>Interactive program</localization> -->
<!-- Back matter components -->
<!-- index-part is deprecated, but not abandoned -->
<!-- NB: repurpose translations, maybe move appendix here -->
Expand Down
1 change: 1 addition & 0 deletions xsl/localizations/cs-CZ.xml
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
<!-- <localization string-id='uncategorized'>Uncategorized</localization> -->
<!-- <localization string-id='query'>Query</localization> --> <localization string-id='program-activecode'>ActiveCode</localization>
<localization string-id='program-codelens'>CodeLens</localization>
<!-- <localization string-id='program-interactive-available'>Interactive program</localization> -->
<!-- Back matter components -->
<!-- index-part is deprecated, but not abandoned -->
<!-- NB: repurpose translations, maybe move appendix here -->
Expand Down
1 change: 1 addition & 0 deletions xsl/localizations/de-DE.xml
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
<!-- <localization string-id='query'>Query</localization> -->
<localization string-id='program-activecode'>ActiveCode</localization>
<localization string-id='program-codelens'>CodeLens</localization>
<!-- <localization string-id='program-interactive-available'>Interactive program</localization> -->
<!-- Back matter components -->
<!-- index-part is deprecated, but not abandoned -->
<!-- NB: repurpose translations, maybe move appendix here -->
Expand Down
1 change: 1 addition & 0 deletions xsl/localizations/en-US.xml
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
<!-- and so really *should not* be translated. -->
<localization string-id='program-activecode'>ActiveCode</localization>
<localization string-id='program-codelens'>CodeLens</localization>
<localization string-id='program-interactive-available'>Interactive program</localization>
<!-- Back matter components -->
<!-- index-part is deprecated, but not abandoned -->
<!-- NB: repurpose translations, maybe move appendix here -->
Expand Down
1 change: 1 addition & 0 deletions xsl/localizations/es-ES.xml
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
<!-- <localization string-id='query'>Query</localization> -->
<localization string-id='program-activecode'>ActiveCode</localization>
<localization string-id='program-codelens'>CodeLens</localization>
<!-- <localization string-id='program-interactive-available'>Interactive program</localization> -->
<!-- Back matter components -->
<!-- index-part is deprecated, but not abandoned -->
<!-- NB: repurpose translations, maybe move appendix here -->
Expand Down
1 change: 1 addition & 0 deletions xsl/localizations/fi-FI.xml
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
<!-- <localization string-id='query'>Query</localization> -->
<localization string-id='program-activecode'>ActiveCode</localization>
<localization string-id='program-codelens'>CodeLens</localization>
<!-- <localization string-id='program-interactive-available'>Interactive program</localization> -->
<!-- Back matter components -->
<!-- index-part is deprecated, but not abandoned -->
<!-- NB: repurpose translations, maybe move appendix here -->
Expand Down
1 change: 1 addition & 0 deletions xsl/localizations/fr-CA.xml
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
<!-- <localization string-id='query'>Query</localization> -->
<localization string-id='program-activecode'>ActiveCode</localization>
<localization string-id='program-codelens'>CodeLens</localization>
<!-- <localization string-id='program-interactive-available'>Interactive program</localization> -->
<!-- Back matter components -->
<!-- index-part is deprecated, but not abandoned -->
<!-- NB: repurpose translations, maybe move appendix here -->
Expand Down
1 change: 1 addition & 0 deletions xsl/localizations/fr-FR.xml
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
<!-- <localization string-id='query'>Query</localization> -->
<localization string-id='program-activecode'>ActiveCode</localization>
<localization string-id='program-codelens'>CodeLens</localization>
<!-- <localization string-id='program-interactive-available'>Interactive program</localization> -->
<!-- Back matter components -->
<!-- index-part is deprecated, but not abandoned -->
<!-- NB: repurpose translations, maybe move appendix here -->
Expand Down
1 change: 1 addition & 0 deletions xsl/localizations/hu-HU.xml
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
<!-- <localization string-id='query'>Query</localization> -->
<localization string-id='program-activecode'>ActiveCode</localization>
<localization string-id='program-codelens'>CodeLens</localization>
<!-- <localization string-id='program-interactive-available'>Interactive program</localization> -->
<!-- Back matter components -->
<!-- index-part is deprecated, but not abandoned -->
<!-- NB: repurpose translations, maybe move appendix here -->
Expand Down
1 change: 1 addition & 0 deletions xsl/localizations/it-IT.xml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
<localization string-id='program'>Programma</localization>
<localization string-id='program-activecode'>ActiveCode</localization>
<localization string-id='program-codelens'>CodeLens</localization>
<!-- <localization string-id='program-interactive-available'>Interactive program</localization> -->
<!-- Back matter components -->
<!-- index-part is deprecated, but not abandoned -->
<!-- NB: repurpose translations, maybe move appendix here -->
Expand Down
1 change: 1 addition & 0 deletions xsl/localizations/ku-CKB.xml
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
<!-- and so really *should not* be translated. -->
<localization string-id='program-activecode'>کۆد-چالاکردن</localization>
<localization string-id='program-codelens'>CodeLens</localization>
<!-- <localization string-id='program-interactive-available'>Interactive program</localization> -->
<!-- Back matter components -->
<!-- index-part is deprecated, but not abandoned -->
<!-- NB: repurpose translations, maybe move appendix here -->
Expand Down
4 changes: 2 additions & 2 deletions xsl/localizations/nl-NL.xml
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ along with PreTeXt. If not, see <http://www.gnu.org/licenses/>.
<!-- and so really *should not* be translated. -->
<!--
<localization string-id='program-activecode'>ActiveCode</localization>
<localization string-id='program-codelens'>CodeLens</localization>
-->
<localization string-id='program-codelens'>CodeLens</localization> -->
<!-- <localization string-id='program-interactive-available'>Interactive program</localization> -->
<!-- Back matter components -->
<!-- index-part is deprecated, but not abandoned -->
<!-- NB: repurpose translations, maybe move appendix here -->
Expand Down
Loading