4Graphics, images and videos

Graphics and images are imported from files in img/ in your project directory. The types of these files coincide with the file types used for the LaTeX command includegraphics. In addition the file type svg may be included.
The widespread TikZ package from LaTeX is not included with QaDiL, but if you have LaTeX installed on your computer there is also an easy hack for generating standalone graphics files from TikZ for inclusion in QaDiL. This is described below. First we document the basic command for including graphics and images in QaDiL.

4.1 includegraphics

The includegraphics control sequence works almost like the one in regular LaTeX except that dimensions (percents and pixels) in the optional parameter are geared towards html.

\includegraphics{vonNeumann.gif}

\includegraphics[width="50\%"]{tweetmath.png}

4.2 Using LaTeX/TikZ for standalone graphics

A tikzpicture environment is included in QaDiL on an experimental basis. One can, however, with LaTeX/TikZ installed easily generate standalone graphics files for inclusion in QaDiL.
We will describe this using an example. Below is a standalone LaTeX snippet with TikZ code for generating a right triangle.

\documentclass[crop,tikz,convert={outext=.svg,command=\unexpanded{pdf2svg \infile\space\outfile}},multi=false]{standalone}[2012/04/13]
\makeatletter
\begin{document}
\begin{tikzpicture}[scale=8]
\draw (0cm, 0cm) -- (1cm, 0cm) -- (1cm, 1cm) -- (0cm, 1cm) -- (0cm, 0cm);
\draw[thick] (0cm, 0cm) -- (1cm, 1cm);
\draw (0.4cm, 0.5cm) node[above] {$\sqrt{x_1^2 + y_1^2}$};
\draw (0.5cm, 0cm) node[below] {$x_1$};
\draw (1cm, 0.5cm) node[right] {$y_1$};
\end{tikzpicture}
\end{document}

Suppose that you have the conversion program pdf2svg installed and that the above snippet is saved in the file Pythagoras.tex. Then

pdflatex -shell-escape Pythagoras  

gives as output the vector graphics file Pythagoras.svg for inclusion in QaDiL with

\includegraphics{Pythagoras.svg}

assuming that Pythagoras.svg resides in your img/ directory.

4.3 tikzpicture

The tikzpicture environment has been added to QaDiL on an experimental basis and may be used (almost) as in ordinary LaTeX. It is based on https://tikzjax.com/. Here one needs to include tikz as an htmlinclude file before use.

\includehtml{tikz}
:
\begin{document}
:
\begin{center} 
 \begin{tikzpicture}[scale=2]
   \draw (0,0) circle (1in);
 \end{tikzpicture}
\end{center}
:

4.4 Matplotlib

Another option for generating graphics is using the popular matplotlib library for python. Below is a simple example.

import matplotlib
import matplotlib.pyplot as plt

plt.plot([1.35, 1.42, 1.45, 1.52], [35, 50, 40, 45], 'ro')
plt.plot([1.68, 1.70, 1.73, 1.73], [65, 70, 60, 80], 'bo')
plt.axis([1.3, 1.8, 30, 90])
plt.xlabel("height (m)")
plt.ylabel("weight (kg)")

plt.show()
#plt.savefig('ptplot.png')

The above python snippet displays the plot with the option of saving to a png-file. If you uncomment the last line and comment out plt.show(), the plot will be written to the file ptplot.png.

4.5 Embedding videos

In the include file stddefs you will see macros for inclusion of YouTube and Vimeo videos. Let us briefly go through these. We will first define a macro to create an iframe in html

\newcommand{\iframevideo}[1]{<iframe width="100\%" height="360" src="#1" frameborder="0" allowfullscreen></iframe>}

4.5.1 From YouTube

Input to the macro is the YouTube video identifier. It reads

\newcommand{\youtube}[1]{\iframevideo{https://www.youtube.com/embed/#1?rel=0}}

This macro can then be used as.

\youtube{9bZkp7q19f0}

4.5.2 From Vimeo

There is a similar macro for embedding vimeo videos. This macro can be found in the included stddefs file.

\vimeo{375432061}