# Crop the image of LaTeX formula

How to automatically crop the white space (maximum thickness horizontal/vertical white border) around the formula in image, generated, say, by means of some of online LaTeX formula editors (actually I use EqualX standalone editor)?

For the formula:

n_i =
\begin{vmatrix}
p_1^1  & p_1^2  & \dots  & p_1^{i - 1} & 1      & p_1^{i + 1} & \dots  & p_1^D  \\
p_2^1  & p_2^2  & \dots  & p_2^{i - 1} & 1      & p_2^{i + 1} & \dots  & p_2^D  \\
\vdots & \vdots & \ddots & \vdots      & \vdots & \vdots      & \ddots & \vdots \\
p_D^1  & p_D^2  & \dots  & p_D^{i - 1} & 1      & p_D^{i + 1} & \dots  & p_D^D  \notag
\end{vmatrix}


There is an image created:

I specially add the one-pixel black border at the edge of the image to illustrate, that there is a plenty of extra space, which is possible to cut off.

How to do it automatically (maybe by means of imagemagick utility)? There are a bunch of similar images for one-liner formulas, which I want to inline into html-text.

Are there useful commands, which can I prepend into preamble of document, that allows me to atchieve desired?

• Use the standalone documentclass – Herr K. Jan 21 '15 at 19:16
• If you want to use already existing pdfs, use the pdfcrop program. It can automatically remove white borders. – Juri Robl Jan 21 '15 at 19:20
• By the way, if you want to embed math into html, you may want to check out MathJax. – Herr K. Jan 21 '15 at 19:22
• Welcome to TeX.SX! – Adam Liter Jan 21 '15 at 19:26
• @KevinC I can't use it in the blog I want. – Orient Jan 21 '15 at 19:31

Use the standalone document class:

# MWE

\documentclass[border=2pt]{standalone}
\usepackage{mathtools}
\begin{document}
$n_i = \begin{vmatrix} p_1^1 & p_1^2 & \dots & p_1^{i - 1} & 1 & p_1^{i + 1} & \dots & p_1^D \\ p_2^1 & p_2^2 & \dots & p_2^{i - 1} & 1 & p_2^{i + 1} & \dots & p_2^D \\ \vdots & \vdots & \ddots & \vdots & \vdots & \vdots & \ddots & \vdots \\ p_D^1 & p_D^2 & \dots & p_D^{i - 1} & 1 & p_D^{i + 1} & \dots & p_D^D \notag \end{vmatrix}$
\end{document}


# Output

• Not works for me. But maybe the source of failure is invisible fields: in EqualX I can't manage whole the document completely. – Orient Jan 21 '15 at 19:29
• I was mistaken. In the fact, there is a difference in images generated. – Orient Jan 21 '15 at 19:46
• @Orient: Thanks. If you want to crop further, you may change the parameter of border to 1pt or even 0pt. – Herr K. Jan 22 '15 at 2:29