Hello Paul,

Thank you for the response. Actually, I have had some success with coming
up with a fix for this, I just wasn't sure about the best way to share it
here on the mailing list. When png's are generated using dvipng, you can
instruct dvipng to also print the position of the baseline to stdout using
a command line option "-height*". dvisvgm, on the other hand, I suspect is
a lost cause.

I have cobbled together a solution which can be viewed here
<https://github.com/vatsal-singhal/org-latex-preview-ascent-fixup> for
creating overlays with dvipng with the correct values of ascent. The
quality of the code may be low, due to my inexperience with elisp and emacs
in general. My solution involves overriding the org-format-latex function
and introducing additional params to the org-preview-latex-process-alist. I
have made use of the fact that all stdout output of the spawned dvipng
process is piped into a hidden buffer by default, in order to read the
positions of the baseline.

Additionally, there's an older, and popular project here
<https://abode.karthinks.com/org-latex-preview/> that has fixed this issue
in addition to several QoL improvements to latex preview in org mode. I am
under the impression that the project is on its way to be included into org
at some point soon. So that's that. I recommend checking it out, since the
speedups are impressive.

Thanks and Regards
Vatsal Singhal


On Wed, Jun 24, 2026 at 6:33 PM Paul Bryan <[email protected]> wrote:

> > However I am observing an issue with the vertical > alignment of the
> images displaying the equations. More specifically, the > "base lines" of
> the characters in the overlaid images does not seem to > match the base
> line of the surrounding text in the final output as > displayed on the
> screen.
>
> I'm not sure if you can do anything about this. Repeating your example
> here:
>
> _ $x$ $y$ _ some text
> _ $xyT$ _ some text
>
> org-latex-preview will use that value of the variable
> org-preview-latex-default-process to generate the preview. The value of
> that variable should be one of the options listed in the variable
> org-preview-latex-process-alist. The default is dvipng which will run
> LaTeX and then dvipng to generate a png, then display that (as an overlay I
> think) where the TeX was.
>
> In the first example, there will be two png's: one for x, then one for y,
> then followed by the text. So it's just two image files. There's no way for
> emacs to know where the baselines were supposed to be and so can't
> vertically align the images so their contents have matching baselines.
>
> In the second example, LaTeX generates output with the correct baselines 
> *within
> the png*. Then org-latex-preview overlays a single png which is already
> correctly alignment within the image.
>
> Instead of png's, you can use svg's. See org-preview-latex-default-process
> for options. But I'm not sure that would be any help. Maybe someone else
> knows some clever tricks.
>
> Personally, I just accept that sometimes LaTeX previews look a little
> weird. I did tweak the png conversion a little to increase the size a bit
> and add some padding to make it more readable, but that tends to make
> things look even worse sometimes!
>
> – *Paul*
>
> * From*: Vatsal Singhal <vatsal+singhal+%[email protected]%3E>
> * To*: [email protected]
> * Date*: Thu, 4 Jun 2026 12:08:05 +0530
> * Subject*: [BUG] Improper vertical alignment of images generated by
> org-latex-preview [9.7.11 (release_9.7.11 @
> /usr/share/emacs/30.2/lisp/org/)]
>
> Hi,
>
> I am trying to use org-mode for creating math notes and am using the
> org-latex-preview command in order to view the equations within them as
> rendered images. However I am observing an issue with the vertical
> alignment of the images displaying the equations. More specifically, the
> "base lines" of the characters in the overlaid images does not seem to
> match the base line of the surrounding text in the final output as
> displayed on the screen.
>
> This issue is primarily visible when the glyphs of the equation are
> imbalanced in the amount of space occupied below and above the base
> line. For example, consider the letter "y": it takes up space below the
> base line, but not above.
>
> For a demonstration, consider that the org document contains the
> following two lines:
>
> _ $x$ $y$ _ some text
> _ $xyT$ _ some text
>
> I am including a screenshot of what is displayed on my screen after
> generating the latex previews using the org-latex-preview command.For
> clarity, I have drawn colored lines to show the alignment. The equation
> fragments containing solely x or y seem to be improperly aligned, while
> the equation fragment 'xyT' seems to be properly aligned.
>
> Environment Details:
>
> I am using emacs 30.2 on a linux installation. I also have a texlive
> installation (2026.1-1) and am using dvisvgm for generating the
> previews.
>
> I have customized org-format-latex-options to the following value (only
> really set the scale to 1.8):
>
> (:foreground default :background default :scale 1.8 :html-foreground
>          "Black" :html-background "Transparent" :html-scale 1.0
>          :matchers ("begin" "$1" "$" "$$" "\\(" "\\["))))
>
> Additionally, I am using a variable width font: Cardo.
>
> Emacs  : GNU Emacs 30.2 (build 2, x86_64-pc-linux-gnu, GTK+ Version
> 3.24.52, cairo version 1.18.4)
> Package: Org mode version 9.7.11 (release_9.7.11 @
> /usr/share/emacs/30.2/lisp/org/)
>
> Thanks,
> Vatsal Singhal
>
>

Reply via email to