LaTeX with no output renders as blank space (empty mjx-container with margins)


It can be useful to have a LaTeX block which generates no output, for example to declare new math operators that are later used in the text.

This mostly works in both preview mode and in Publish, except that there is blank space at the location of the empty $$ … $$ block. This is actually an empty mjx-container with top and bottom margins (identified using the inspect tools) set.

This makes the note start with unnecessary blank space in both preview mode and in Publish.

Steps to Reproduce

Create a new note with contents:


The variance ($\Var(X)$, $\sigma^2$) of a random variable $X$ is the expected value of the squared deviation from the mean of $X$, $\mu = \E[X]$.

Switch to preview mode or publish the note.

Expected result

No empty space where the LaTeX block with no output is located.

Actual result

Empty space where the LaTeX block with no output is located.

Tried Solutions

I tried to hide it in a div with display: none, but then the LaTeX is not processed:

<div style="display: none;">

I also tried to put it inline with single $ … $, but this is less clear and also generated a blank space at the start of the line.

It can sometimes be possible to hide the LaTeX block between to paragraphs, where you want a blank space anyway, but this doesn’t work in the example above where the declarations are used in the first sentence.

There are plugins to enable a global .sty file with LaTeX macros, but this doesn’t work in Publish.

Related Posts

This is essentially identical to Latex commands with no output still render blank lines in preview, but as that post was closed without any solution, I’m reviving the issue here.


  • Operating system: Windows 10
  • Obsidian version: 0.10.2

All the best,

1 Like

we have no way of knowing when the output will be empty or or not. The same thing happens in the mathjax demo page.

I understand. Is there a way to hide the output?
Like what I tried with the div, but that preserves the LaTeX?

(or if you have any other ideas?)

I found a workaround by using the following CSS in a snippet (for the application) and in publish.css (for Publish):

mjx-math:empty {
  display: none;

The empty parent containers (with margins) remain, but the rendered page now looks correct.

thanks and interesting.