vim-instant-markdown icon indicating copy to clipboard operation
vim-instant-markdown copied to clipboard

Auto scroll marker html tag inside latex formulas causes TeX parse error

Open philip4096 opened this issue 3 years ago • 6 comments

Problem summary

When the marker html tag used to mark the current line (for auto scroll) is inserted inside a multiline latex formula, the formula cannot be parsed, and it does not show in the output.

Expected

Somehow detect if the current line is inside a latex formula and place the marker before or after.

Environment Information

mac, vim 8

Provide the debug output (required)

From the log file

Formula
\begin{aligned}
   \int_a^b u(x) v'(x) \, dx  <a name="#marker" id="marker"></a>
   & = \Big[u(x) v(x)\Big]_a^b - \int_a^b u'(x) v(x) \, dx\\[6pt]
   & = u(b) v(b) - u(a) v(a) - \int_a^b u'(x) v(x) \, dx.
\end{aligned}
 contains the following errors:
 [
  "TeX parse error: You can't use 'macro parameter character #' in math mode"
]

philip4096 avatar Mar 21 '22 11:03 philip4096

Detecting math formula would be the right thing to do, but can be hard. Contributions welcome. One could use let g:instant_markdown_slow = 1 to reduce preview updates.

ashwinvis avatar Mar 21 '22 21:03 ashwinvis

How about placing the marker on the next empty line (or at the end of the file)? Empty lines seem to be forbidden inside math formulas and markdown paragraphs are separated by empty lines so there should always be an empty line (or end of file) nearby.

philip4096 avatar Mar 22 '22 10:03 philip4096

Good suggestion, but only, if there is content after the equation.

The only drawback is if the user is working at the end of a file writing a very long paragraph. Then if we place the marker before the paragraph, the preview is not where the cursor is; and if the marker is at the end of the file then it meddles with the equation.

ashwinvis avatar Mar 22 '22 17:03 ashwinvis

Yes, It seems there needs to be content after the marker. So something like this perhaps:

From the current line find the next empty line that is followed by a non-empty line. If the end of the file is reached find the previous empty line followed by a non-empty line (or the first line if there is none). Insert the marker on a new line after this line (new line in order to avoid fusing paragraphs).

As you say this could cause (more) trouble for people writing very long paragraphs that are split into several lines. A solution would be to make this feature optional but on by default (the current problems with equations are much worse in my opinion).

I noticed that 5 is subtracted from the current line number. Why is this necessary?

By the way I really like this plugin. Makes latex math editing a much more enjoyable experience.

22 mars 2022 kl. 18:55 skrev Ashwin V. Mohanan @.***>:  Good suggestion, but only, if there is content after the equation.

The only drawback is if the user is working at the end of a file writing a very long paragraph. Then if we place the marker before the paragraph, the preview is not where the cursor is; and if the marker is at the end of the file then it meddles with the equation.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.

philip4096 avatar Mar 23 '22 09:03 philip4096

I agree. Would you like to give it a go?

Here is the reason for subtracting 5

https://github.com/instant-markdown/vim-instant-markdown/issues/154 https://github.com/instant-markdown/vim-instant-markdown/issues/168

ashwinvis avatar Mar 26 '22 10:03 ashwinvis

There is now a pull request. I am new to vimscript and to and github contributing. Feedback welcome. In my testing I found that placing the marker on the previous empty line worked better and also made the code simpler.

philip4096 avatar Mar 28 '22 10:03 philip4096