Embed pictures in Ximera activities.
We’ve seen basic ways to include JPGs, PNGs, and PDFs using \includegraphics.
However, this is not the preferred way to include graphics. Moreover, there are
considerations for positioning of the graphics.
1 Positioning graphics
In LaTeX it is common to place images in the figure environment. We choose
not to use this because figure ‘floats’ the images for ‘optimal’ page layout.
We are not concerned with page layout. When working online, the page is
essentially infinite in length. Moreover, the consumers of the content we
create is for students. Students are unconcerned with awkward page layout.
Students prefer to see images exactly when they are mentioned. With this
said, we suggest wrapping all images in either a center environment or a
(Ximera-specific) image environment. The environment image centers and
automatically scales the contents. If an author finds themselves printing to various
page-sizes, image might be preferred. Moreover, image can be redefined
globally to act identically to center, but center cannot be redefined. In
particular, we utilize this feature of image in this manual to place frames around
graphics.
If you use center, you would write something like:
\begin{center}
\includegraphics[width=5cm]{missionPatch.jpg}
\end{center}
If you use image, you would write something like:
\begin{image}
\includegraphics[width=5cm]{missionPatch.jpg}
\end{image}
The disadvantage of using \includegraphics is that you need to handle the paths to
the images in some way. However, we provide a global graphics path: You may store
all your graphics inside \xmPictures. This means that any required *.jpg, *.png,
and *.pdf can be found, assuming your file isn’t nested too deep. Moreover, we’ve set
up the .gitignore to not ignore *.jpg, *.png, and *.pdf when they are placed in
the xmPictures directory. Finally, while this is currently the easiest method for
adding graphics in Ximera, it might be better if all graphics were placed at
the level of the source file, and then a soft link (using the terminal) could
be made to the xmPictures directory. The advantage here being that if
someone wants to borrow your material, everything they need is in the same
folder.
With this said, TikZ is the preferred method for graphics because code, found in the Ximera LaTeX file, generates the image. No need to worry about graphics paths.
2 TikZ is the preferred method for graphics
Most of TikZ is supported, and these are rendered as PNGs online. For example, the following code
\begin{image}
\begin{tikzpicture}
\begin{axis}[
xmin=-6.4,
xmax=6.4,
ymin=-1.2,
ymax=1.2,
axis lines=center,
xlabel=$x$,
ylabel=$y$,
every axis y label/.style=
{at=(current axis.above origin),anchor=south},
every axis x label/.style=
{at=(current axis.right of origin),anchor=west},
]
\addplot [ultra thick, blue, smooth] {sin(deg(x))};
\end{axis}
\end{tikzpicture}
\end{image}
generates the image below:
When you use TikZ for graphics, you don’t need to worry about the \graphicspath
and your work is completely self-contained.