2

When I run

\documentclass{article}

\usepackage{amsmath}
\usepackage[active, tightpage, displaymath]{preview}

\begin{document}

\begin{equation*}
1+2 = 3
\end{equation*}

\end{document}

I get the following result enter image description here

I checked this question "Crop equations with preview package" but the solutions provided there, using external script or replace equations all inline, don't work for me because that image snippet will be used for Emacs auctex preview that automatically inserts "\usepackage[options...]{preview}" to the original tex document, generate equation snippets, then overlay them on the equation strings making the editing like more WYSIWYG-ish.

Anyway, Emacs auctex variable preview-default-preamble enables me to insert some custom strings to the preamble when it generates the preview images, so I was looking for something like

\renewcommand{\begin{equation*}}{\begin{math}\displaystyle}
\renewcommand{\end{equation*}}{\end{math}}

to be inserted to the preamble when I run preview-document.

But those naively written \renewcommand commands don't work of course. I know that I can use \renewcommand or even \def or \let to redefine macros, but how can I do it for the macro with certain arguments? More directly,

What should I put in the preamble so that whenever the compiler sees \begin{equation*} it replaces it with \begin{math}\displaymath and run it?

PS. This may look like an XY question, but I'm also interested in finding the solution because I have something else that I could do with that. :-)

1
  • 1
    You may find it useful to read up on \renewenvironment etc and understand how LaTeX environments work. – ShreevatsaR Dec 12 '20 at 3:59
1

Thanks for ShreevatsaR's comment, I found it and it was simple! I don't know why I was so obsessed with macros, but I just put

\renewenvironment{equation*}{\begin{math}\displaystyle}{\end{math}}

and it worked perfect. (I could not put $ in place of \begin{math} and \end though but that's not a big issue and is understandable why it doesn't work.)

I'll also edit the title because this thing with preview with that spacing has been an minor annoyance for quite a long time for me (cf. how to set preview-latex left indentation on formulas?).

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.