3 Exercises

Exercise 8.

Set the document language (warning: babel can crash the document if running locally, read the answer for more details).

Answer.

Use the class option british, english, french, etc, and load the babel package. Unfortunately, passing the language as an option to the babel package itself can crash . Make sure to use class options for the time being, just as in the template.

\documentclass[american]{article}
\usepackage{babel} % <- good
\usepackage[american]{babel} % <- will crash LaTeXML with TeX Live 2025 and later
Exercise 9.

Upload a SCORM package to your VLE.

Exercise 10.

Set the SCORM package description using \hypersetup.

Answer.

After loading the hyperref package, add:

\usepackage{hyperref}
\hypersetup{pdfsubject={This description should appear automatically in your VLE.}}
Exercise 11.

Add some subsections to your document. Change the configuration (where?) so that the the document is split by subsection, or not split at all.

Answer.

This type of change goes into GNUmakefile. If you do not have one, fish it out of the bookml folder. Add the following line somewhere (normally before include bookml/bookml.mk):

SPLITAT=subsection

or, to avoid splitting altogether,

SPLITAT=

splits by either section or chapter by default, depending on the document class.

Exercise 12.

Divert a block of content (for example, a difficult TikZ picture) to a ‘BookML image’.

Answer.

Wrap the block within

\begin{bmlimage}
...problematic content...
\end{bmlimage}

This generates a ‘BookML image’, i.e. an image compiled via and converted to SVG without seeing what it is. To divert all TikZ pictures, add the following to your preamble, after loading TikZ.

\bmlImageEnvironment{tikzpicture}

You may as well hide TikZ completely from to save about 30 seconds using

\iflatexml\else
\usepackage{tikz}
% put the rest of your tikz libraries and configs here
\fi
\bmlImageEnvironment{tikzpicture}
Exercise 13.

Add an alternative text to an image (possibly also a BookML image).

Answer.

When using \includegraphics, add the alt={} key:

\includegraphics[alt={a right-angled triangle ...}]{triangle}

For TikZ pictures, and any other picture, use:

\end{tikzpicture}\bmlDescription{...}

This also works for BookML images. There must be no other content between the picture and \bmlDescription (sometime even an empty space can cause issues).

Exercise 14.

Create a foldable environment using the HTML <details> tag, and embed a YouTube video.

Answer.

BookML supports adding HTML tags by roughly typing them as is.

\<details>\<summary>Reveal the answer.\</summary>
Suppose by contradiction [...].
\</details>

The rules are:

  • the initial <> must be preceded by a backslash \<;

  • each tag MUST be closed, so <br> must be written as \<br/> (or \<br>\</br>, but let people see that);

  • attributes must have quoted values, so allowfullscreen must become allowfullscreen="";

  • special characters like &, %, # must be prefixed with a backslash too.

This mechanism is a little fragile, due to the mismatch between internal model and HTML, so use it only when cannot help: foldable environments and videos.

Exercise 15.

Add a simple SageMathCell, like the following one:

Answer.

In the preamble, add

\bmlRawHTML{<script src="https://sagecell.sagemath.org/static/embedded_sagecell.js"></script><script>sagecell.makeSagecell(\{"inputLocation": ".sage"\});</script>}

In the document,

\iflatexml
\<div class="sage">
\<script type="text/x-sage">1+2\</script>
\</div>
\else
\begin@@{lstlisting}
1+2
\end@@{lstlisting}
\fi

You should probably create an environment that does all of that for you, and possibly add some custom styling (either using supported packages like framed, or by adding your own CSS to the bmluser folder).

Exercise 16.

Create two versions of the same file, say one with the solutions to some exercises, and one without.

Answer.

Adopt the same strategy you normally use. My tip for working with BookML is that you create two files. For instance, create a secondary file exercises-without-solutions.tex like the following:

% \documentclass <- trick BookML into compiling this file
\def\withoutSolutions{}
\input{exercises-with-solutions}

In exercises-with-solutions.tex, check if \withoutSolutions is defined to decide if solutions must be included or not. Then BookML will compile both files to separate SCORM packages. For instance:

\ifcsname withoutSolutions\endcsname
\excludecomment{solution}
\fi
Exercise 17.

Help, my memoir document comes out all wrong! Use \iflatexml to selectively use the book class only when running , so that the PDF looks as you wanted it, and to hide all memoir-specific commands from .

Answer.

You need to ingredients: \iflatexml allows you to run different code for PDF and HTML outputs, but you also need to access \iflatexml before even calling \documentclass! Do as follows:

\RequirePackage{bookml/bookml}
\iflatexml
\documentclass[a4paper,12pt,...]{book}
\else
\documentclass[a4paper,12pt,...]{memoir}
\fi
Exercise 18 (For screen readers).

Launch a screen reader and try navigating through the examples. To launch Microsoft Narrator, on Windows: Ctrl +Win +Enter . To launch VoiceOver on macOS: Fn +Cmd +F5 .

Exercise 19 (For screen readers).

Mark a table row as header (this is not well documented!).

Answer.

I’ll just post an example here taken from the BookML tests:

\begin{tabular}{l|c|c}
\lxBeginTableHead{} Test & MathJax & MathML \\
\hline \lxEndTableHead{}
AMS equations \lxTableRowHead & \href{../amsldoc-equations-mathjax2/}{v2}, \href{../amsldoc-equations-mathjax3/}{v3}, \href{../amsldoc-equations-mathjax4/}{v4} & \href{../amsldoc-equations-nomathjax/}{no MathJax} \\
Mathtools equations \lxTableRowHead & \href{../mathtools-mathjax2/}{v2}, \href{../mathtools-mathjax3/}{v3}, \href{../mathtools-mathjax4/}{v4} & \href{../mathtools-nomathjax/}{no MathJax} \\
\LaTeXML{} equations test \lxTableRowHead & \href{../latexml-t-ams-mathtools-mathjax2/}{v2}, \href{../latexml-t-ams-mathtools-mathjax3/}{v3}, \href{../latexml-t-ams-mathtools-mathjax4/}{v4} & \href{../latexml-t-ams-mathtools-nomathjax/}{no MathJax} \\
Disable MathJax \lxTableRowHead & \href{../disable-mathjax-mathjax2/}{v2}, \href{../disable-mathjax-mathjax3/}{v3}, \href{../disable-mathjax-mathjax4/}{v4} & \href{../disable-mathjax-nomathjax/}{no MathJax} \\
Math variants \lxTableRowHead & \href{../mathvariants-mathjax2/}{v2}, \href{../mathvariants-mathjax3/}{v3}, \href{../mathvariants-mathjax4/}{v4} & \href{../mathvariants-nomathjax/}{no MathJax}
\end{tabular}

The functionality comes from the latexml.sty package, which is automatically available when running BookML.

Exercise 20 (For screen readers, hard).

Using a screen reader, listen to the difference between ϕ(mn)=ϕ(m)ϕ(n)\phi(mn)=\phi(m)\phi(n) and ϕ(mn)=ϕ(m)ϕ(n)\phi(mn)=\phi(m)\phi(n) (if you cannot run a screen reader, right click on the formulas and go to ‘Show Math As > Speech Text’; you may need to refresh the page for the speech to activate). Look at all the macros defined in latexml.sty and find the one responsible for the change, then implement the change yourself.

Given that this confusion between multiplication and function application is pervasive in the wild, you should warn your screen reader users that they must pay attention to the context.

Answer.

Here, neither nor MathJax can definitely guess that ϕ\phi is a function as opposed to a number being multiplied. usually infers that this is a multiplication. Looking at ‘Show Math As > MathML Code’, you can see that there are different ‘invisible operators’, all of which were guessed by .

To ensure that treats a symbol as a function, wrap it in \lxFcn:

\lxFcn{\phi}(mn) = \lxFcn{\phi}(m)\lxFcn{\phi}(n).

Creating your own macros is recommended:

\newcommand{\totient}{\lxFcn{\phi}}

allows you to customise its maths parsing more deeply, and for instance declare that the command \phi itself is a function. However, it requires some pretty good knowledge of how parses mathematical content.