3

I am attempting to use the standalone package in LaTeX to generate images of practice math questions that will be displayed for an audience as part of a presentation. The final output needs to be PNG images in a 16:9 aspect ratio.

I have figured out how to use the standalone package combined with the minipage package to output images that are properly formatted. But the last step is getting them to output with a consistent 16:9 aspect ratio.

Currently my code looks like this:

\documentclass[convert,border=1pt]{standalone}

\usepackage{amsmath}

\begin{document}
\begin{minipage}

\noindent
For $i = \sqrt{-1}$, what is the sum $(7 + 3i) + (-8 + 9i)$?
\\[1\baselineskip]
\noindent
A) $-1 + 12i$ \\[0.5\baselineskip]
B) $-1 - 6i$  \\[0.5\baselineskip]
C) $15 + 12i$ \\[0.5\baselineskip]
D) $15 - 6i$

\end{minipage}
\end{document}

Any advice is greatly appreciated!

  • By the way, would the client accept a vector format such as SVG? That will give much better results than raster graphics, if they are an option. – Davislor Jun 5 at 17:00
  • Unfortunately, no. I appreciate the suggestion, and I agree wholeheartedly. However, this particular project is an exercise in workarounds :) – 1Teaches2Learn Jun 6 at 6:17
3

You need to specify a width for minipage (or use varwidth). You can also specify a height.

Note, the first [c] isn't important unless you are trying to align boxes side by side. The second [c] centers the contents inside the box. Other options are [t] (top), [b] (bottom) and [s] (stretch, must include vertical glue).

\documentclass[convert,border=1pt]{standalone}

\usepackage{amsmath}

\begin{document}
\begin{minipage}[c][4.5cm][c]{8cm}
%\noindent% \parindent=0pt inside a minipage
For $i = \sqrt{-1}$, what is the sum $(7 + 3i) + (-8 + 9i)$?
\\[1\baselineskip]
\noindent
A) $-1 + 12i$ \\[0.5\baselineskip]
B) $-1 - 6i$  \\[0.5\baselineskip]
C) $15 + 12i$ \\[0.5\baselineskip]
D) $15 - 6i$

\end{minipage}
\end{document}

Just for fun:

\documentclass[convert,border=1pt]{standalone}

\usepackage{amsmath}

\begin{document}
\sbox0{For $i = \sqrt{-1}$, what is the sum $(7 + 3i) + (-8 + 9i)$?}% measure width
\begin{minipage}[c][0.5625\wd0][s]{\wd0}

\usebox0\\[\fill]

A) $-1 + 12i$ \\[\fill]
B) $-1 - 6i$  \\[\fill]
C) $15 + 12i$ \\[\fill]
D) $15 - 6i$

\end{minipage}
\end{document}
  • Thanks! I think that "for fun" part is going to lead to what I need. I should have specified: The client is asking for 1000 of these! Some will be significantly longer word problems, etc. So the challenge is that it always needs to output at the 16:9 aspect ratio. I appreciate your guidance. And FYI: I left you an up arrow...it just doesn't display until I get more reputation! – 1Teaches2Learn Jun 5 at 0:40
  • @1Teaches2Learn While upvoting might not work yet you might accept this answer (checkmark below voting arrows) if it solved your problem. – TeXnician Jun 5 at 5:50
  • So it goes! Thanks again for the help! – 1Teaches2Learn Jun 6 at 6:24
  • Just confirming a month later on that this solution did in fact meet my needs, and we are now creating product using a version of your fix. I truly appreciate your help and this community. Thank you! – 1Teaches2Learn Jun 30 at 2:07
2

The geometry package works with standalone. You will need to turn off the crop and preview options to prevent them from resizing the page. Since this turns page numbers back on, suppress them again with \pagenumbering{gobble}.

\documentclass[convert={density=75, imagemagick, convertexe=magick},
               crop=false,
               preview=false,
               12pt]{standalone}
\usepackage[paperwidth=16cm, paperheight=9cm]{geometry}
\pagenumbering{gobble}

\usepackage{mathtools}
\usepackage{unicode-math}

\DeclareRobustCommand\ICr{I_{C_r}}
\DeclareRobustCommand\arr[1]{\symbf{#1}}

\begin{document}
\Huge
\begin{align*}
  \ICr(x, y) &= \begin{cases}
                  0 &\text{ if } r > \left\lVert(x,y)\right\rVert \\
                  1 &\text{ otherwise}
                \end{cases} \\
           s &= \sum_{a \in \arr{A}} \sum_{p \in \arr{P}} \ICr(p, a)
\end{align*}
\end{document}

enter image description here

Another option for this type of project is the beamer package followed by an external command to convert each page to a separate PNG.

  • Thank you for this answer. I had actually wondered if geometry or beamer could solve this problem. I haven't learned beamer yet, so I was apprehensive to try. But this answer makes me want to try! – 1Teaches2Learn Jun 6 at 6:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.