protz / LatexIt

An extension for Thunderbird that allows you to generate LaTeX in your emails and send it as inline images
http://www.xulforum.org/go_code
37 stars 16 forks source link

Change regex to check successfully for preview package #78

Closed sphh closed 3 years ago

sphh commented 4 years ago

Find the preview package even if there is any comment before the line including it. (Closes #77 and #76)

protz commented 3 years ago

not sure why this change is needed... * should subsume ? so why make the regexp more restrictive?

sphh commented 3 years ago

Let me think. I did that 3½ months ago …

Ah, I remember (https://github.com/protz/LatexIt/issues/77#issue-733032602 and https://github.com/protz/LatexIt/issues/76): If I have a preamble like this:

%&latex
\documentclass{article}
\usepackage{utf8}
\usepackage[active,displaymath,textmath]{preview}
\pagestyle{empty}
…

(or any other with a comment before the preview line) the old regex did not find the line with preview in it, because [^%]* became greedy and swallowed everything after the first %, including the preview line.

Possibly there are better ways, but it worked for me.

msprotz commented 3 years ago

Ok, it's a little restrictive since it may now no longer accept something like \usepackage... (two leading spaces). Let me know if you want to change the [^%]? to :space:* (or whatever the syntax is) or if you think this is fine as it is.

sphh commented 3 years ago

I see your point. This might work (not tested, because I am already on TB 78 …):

      var re = /^\s*[^%]?\\usepackage\[(.*,\s*)?active(,.*)?\]{(.*,\s*)?preview(,.*)?}/m;
sphh commented 3 years ago

I really cannot remember anymore, why I had to do it that way. Wenn I tried it today with the old regex it worked without any problems.

I close this PR.