The original LaTeX source included 17 instances of \begin{trinket} spread across chapters 1–5, 7, and 10. When running make trinket, these environments would be wrapped in JavaScript that rendered the code as interactive "trinkets" hosted on https://books.trinket.io/. (When building the pdf version, the trinket environments would render the same as the other code environments.) Trinket.io is being discontinued, so we developed our own java-runner library for rendering interactive code snippets entirely client side. That way we can provide an interactive version of the textbook hosted on our GitHub Pages site.
The purpose of this issue is to add code to the quarto source files and build process to use java-runner. See the README and examples for usage instructions. A live demo is also available.
The following steps are anticipated:
- Identify the code snippets that were originally marked with
\begin{trinket}. In the quarto files, all of these have been replaced with code fences annotated with {.java language="Java"} and are indistinguishable from other code snippets.
- Create an additional annotation to indicate that this snippet should be wrapped in a
<script type="text/x-java"> element in the build, causing the snippet to be interactive.
- And
javarunner.css and javarunner.js to this repo and include them in the build. (They should be included in every HTML page.)
- Test that all snippets run correctly in the build output.
The above four steps should bring the book into feature parity with the trinket version. To go the extra mile, we could also do the following:
- Identify other code snippets that could be interactive. Trinket required complete programs, but
java-runner can run incomplete snippets: if no class or main method is provided, the code snippet is compiled as if it were in a main method. Some snippets would make sense to be interactive, while others would make more sense to remain as static content.
- Identify code snippets that could be rendered in a JShell-like REPL environment (
<script type="text/x-java-repl">). That way, the reader could see both the code and its output, and the reader could interactively experiment further.
The original LaTeX source included 17 instances of
\begin{trinket}spread across chapters 1–5, 7, and 10. When runningmake trinket, these environments would be wrapped in JavaScript that rendered the code as interactive "trinkets" hosted on https://books.trinket.io/. (When building the pdf version, the trinket environments would render the same as the other code environments.) Trinket.io is being discontinued, so we developed our own java-runner library for rendering interactive code snippets entirely client side. That way we can provide an interactive version of the textbook hosted on our GitHub Pages site.The purpose of this issue is to add code to the quarto source files and build process to use
java-runner. See the README and examples for usage instructions. A live demo is also available.The following steps are anticipated:
\begin{trinket}. In the quarto files, all of these have been replaced with code fences annotated with{.java language="Java"}and are indistinguishable from other code snippets.<script type="text/x-java">element in the build, causing the snippet to be interactive.javarunner.cssandjavarunner.jsto this repo and include them in the build. (They should be included in every HTML page.)The above four steps should bring the book into feature parity with the trinket version. To go the extra mile, we could also do the following:
java-runnercan run incomplete snippets: if no class or main method is provided, the code snippet is compiled as if it were in a main method. Some snippets would make sense to be interactive, while others would make more sense to remain as static content.<script type="text/x-java-repl">). That way, the reader could see both the code and its output, and the reader could interactively experiment further.