TransWikia.com

Redefine commands / Remove left spacing for equations in LaTeX Preview (also in Emacs AUCTeX)

TeX - LaTeX Asked by HBS on July 31, 2021

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. 🙂

One Answer

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?).

Answered by HBS on July 31, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP