Re: [AUCTeX-devel] Regex best practice
Mosè Giordanowrites: > 2015-11-24 21:13 GMT+01:00 Arash Esbati : >> >> Mosè Giordano writes: >> >>> Probably yes: so you want to match the whole \declaretheoremstyle >>> macro, but saving only the mandatory argument, right? >> >> Yes, exactly. > > The problem of your regex is that will match *everything* until the > last closing bracket. This is good when you test your regex in a > simple case, but will fail in a real document with other commands > taking optional and mandatory arguments. Thanks for your response. Your are right, I missed that completely. > Is the non paired "]" in > > anothername = {valu-es[]}]{} , > > intended? No, it was just part of the experiment. > If so, I don't have a solution at hand, otherwise, if you're sure you > have always paired brackets, you can use something like > > > "declaresomething\\[\\(?:[^][]*\\(?:\\[[^][]*\\(?:\\[[^][]*\\(?:\\[[^][]*\\][^][]*\\)*\\][^][]*\\)*\\][^][]*\\)*\\)\\][ > \t\n\r]*{[ \t\n\r]*\\(.*\\)[ \t\n\r]*}" The existence of brackets is not guaranteed, it is the optional argument. I will play around with your suggestion; I have to decode it first ;-) Best, Arash ___ auctex-devel mailing list auctex-devel@gnu.org https://lists.gnu.org/mailman/listinfo/auctex-devel
Re: [AUCTeX-devel] Regex best practice
Hi Mosè, Mosè Giordanowrites: > Probably yes: so you want to match the whole \declaretheoremstyle > macro, but saving only the mandatory argument, right? Yes, exactly. Best, Arash ___ auctex-devel mailing list auctex-devel@gnu.org https://lists.gnu.org/mailman/listinfo/auctex-devel
Re: [AUCTeX-devel] Regex best practice
Hi Arash, 2015-11-24 21:13 GMT+01:00 Arash Esbati: > Hi Mosè, > > Mosè Giordano writes: > >> Probably yes: so you want to match the whole \declaretheoremstyle >> macro, but saving only the mandatory argument, right? > > Yes, exactly. The problem of your regex is that will match *everything* until the last closing bracket. This is good when you test your regex in a simple case, but will fail in a real document with other commands taking optional and mandatory arguments. Consider for example --8<---cut here---start->8--- \declaresomething[% key = value , name = {[Optional]Value} , anothername = {valu-es[]}]{} , colframe = red!75!black, fonttitle= \bfseries , enhanced , attach boxed = {yshift=-2mm} , title= #2 ] { some1thing } \othercommand[optional]{mandatory} --8<---cut here---end--->8--- `re-builder' highlights "mandatory", with your regex. In addition, it doesn't seem to work at all with XEmacs, but I don't know why. Is the non paired "]" in anothername = {valu-es[]}]{} , intended? If so, I don't have a solution at hand, otherwise, if you're sure you have always paired brackets, you can use something like "declaresomething\\[\\(?:[^][]*\\(?:\\[[^][]*\\(?:\\[[^][]*\\(?:\\[[^][]*\\][^][]*\\)*\\][^][]*\\)*\\][^][]*\\)*\\)\\][ \t\n\r]*{[ \t\n\r]*\\(.*\\)[ \t\n\r]*}" (I'm sorry for the hard-wrapping, replace the newline with a space) which is inspired by `LaTeX-auto-index-regexp-list'. Bye, Mosè ___ auctex-devel mailing list auctex-devel@gnu.org https://lists.gnu.org/mailman/listinfo/auctex-devel
Re: [AUCTeX-devel] Regex best practice
Hi Arash, 2015-11-21 23:20 GMT+01:00 Arash Esbati: > Hi Mosè, > > Mosè Giordano writes: > >> 2015-11-19 20:58 GMT+01:00 Arash Esbati : > >>> looking at some packages, the optional arguments for some commands are >>> getting more and more complex, e.g. >>> >>> --8<---cut here---start->8--- >>> \declaresomething[% >>> key = value , >>> name = {[Optional]Value} , >>> anothername = {valu-es[]}]{} , >>> colframe = red!75!black, >>> fonttitle= \bfseries , >>> enhanced , >>> attach boxed = {yshift=-2mm} , >>> title= #2 >>> ] >>> { >>> some1thing >>> } >>> --8<---cut here---end--->8--- >>> >>> I was thinking about a general regex-solution how to add these kind of >>> beasts to AUCTeX parser. My solution is currently: >>> >>> --8<---cut here---start->8--- >>> declaresomething[ \t\n\r%]*\\(?:\\[\\(?:[\t\n\r[:print:]]*\\)\\]\\)?[ >>> \t\n\r%]*{[ \t\n\r%]*\\([[:print:]]+\\)[ \t\n\r%]*} >>> --8<---cut here---end--->8--- >>> >>> Any comments? Admittedly, the last two `[ \t\n\r%]' are excessive, but >>> you never know. >> >> Ehm, sorry but I didn't get what you want to match (re-builder >> highlights "some1thing") and where you want to add this regex. > > My apologies for being brief and not clear. Please consider the > following MWE: > > --8<---cut here---start->8--- > \documentclass[a4paper,10pt]{article} > > \usepackage{amsthm} > \usepackage{thmtools} > > \declaretheoremstyle[% > spaceabove= 6pt , > spacebelow= 6pt , > headfont = \normalfont\bfseries , > notefont = \mdseries\scshape, > notebraces= {[}{]} , > bodyfont = \normalfont\itshape , > postheadspace = 1em , > qed = \qedsymbol > ]{mystyle} > > \declaretheorem[style=mystyle]{styledtheorem} > > \begin{document} > > \begin{styledtheorem}[Euclid] > For every prime $p$\dots > \end{styledtheorem} > > \end{document} > --8<---cut here---end--->8--- > > Suppose I want to write a `thmtools.el'. If I want to catch and process > user defined styles (in this case "mystyle"), I would currently do: > > --8<---cut here---start->8--- > (defvar LaTeX-thmtools-declaretheoremstyle-regexp > `(,(concat "declaretheoremstyle[ \t\n\r%]*" > "\\(?:\\[\\(?:[\t\n\r[:print:]]*\\)\\]\\)?" > "[ \t\n\r%]*" > "{" > "[ \t\n\r%]*\\([[:print:]]+\\)[ \t\n\r%]*" > "}"))) > > (TeX-auto-add-type "thmtools-declaretheoremstyle" "LaTeX") > > (TeX-add-style-hook > "thmtools" > (lambda () >(TeX-auto-add-regexp LaTeX-thmtools-declaretheoremstyle-regexp) >...)) > --8<---cut here---end--->8--- > > My question is: Is there any other, better solution for this regexp? I > am looking a general solution to handle this kind of cases. I hope it > is more clear now. Probably yes: so you want to match the whole \declaretheoremstyle macro, but saving only the mandatory argument, right? Bye, Mosè ___ auctex-devel mailing list auctex-devel@gnu.org https://lists.gnu.org/mailman/listinfo/auctex-devel
Re: [AUCTeX-devel] Regex best practice
Hi Arash, 2015-11-19 20:58 GMT+01:00 Arash Esbati: > Hi all, > > looking at some packages, the optional arguments for some commands are > getting more and more complex, e.g. > > --8<---cut here---start->8--- > \declaresomething[% > key = value , > name = {[Optional]Value} , > anothername = {valu-es[]}]{} , > colframe = red!75!black, > fonttitle= \bfseries , > enhanced , > attach boxed = {yshift=-2mm} , > title= #2 > ] > { > some1thing > } > --8<---cut here---end--->8--- > > I was thinking about a general regex-solution how to add these kind of > beasts to AUCTeX parser. My solution is currently: > > --8<---cut here---start->8--- > declaresomething[ \t\n\r%]*\\(?:\\[\\(?:[\t\n\r[:print:]]*\\)\\]\\)?[ > \t\n\r%]*{[ \t\n\r%]*\\([[:print:]]+\\)[ \t\n\r%]*} > --8<---cut here---end--->8--- > > Any comments? Admittedly, the last two `[ \t\n\r%]' are excessive, but > you never know. Ehm, sorry but I didn't get what you want to match (re-builder highlights "some1thing") and where you want to add this regex. Bye, Mosè ___ auctex-devel mailing list auctex-devel@gnu.org https://lists.gnu.org/mailman/listinfo/auctex-devel
Re: [AUCTeX-devel] Regex best practice
Hi Mosè, Mosè Giordanowrites: > 2015-11-19 20:58 GMT+01:00 Arash Esbati : >> looking at some packages, the optional arguments for some commands are >> getting more and more complex, e.g. >> >> --8<---cut here---start->8--- >> \declaresomething[% >> key = value , >> name = {[Optional]Value} , >> anothername = {valu-es[]}]{} , >> colframe = red!75!black, >> fonttitle= \bfseries , >> enhanced , >> attach boxed = {yshift=-2mm} , >> title= #2 >> ] >> { >> some1thing >> } >> --8<---cut here---end--->8--- >> >> I was thinking about a general regex-solution how to add these kind of >> beasts to AUCTeX parser. My solution is currently: >> >> --8<---cut here---start->8--- >> declaresomething[ \t\n\r%]*\\(?:\\[\\(?:[\t\n\r[:print:]]*\\)\\]\\)?[ >> \t\n\r%]*{[ \t\n\r%]*\\([[:print:]]+\\)[ \t\n\r%]*} >> --8<---cut here---end--->8--- >> >> Any comments? Admittedly, the last two `[ \t\n\r%]' are excessive, but >> you never know. > > Ehm, sorry but I didn't get what you want to match (re-builder > highlights "some1thing") and where you want to add this regex. My apologies for being brief and not clear. Please consider the following MWE: --8<---cut here---start->8--- \documentclass[a4paper,10pt]{article} \usepackage{amsthm} \usepackage{thmtools} \declaretheoremstyle[% spaceabove= 6pt , spacebelow= 6pt , headfont = \normalfont\bfseries , notefont = \mdseries\scshape, notebraces= {[}{]} , bodyfont = \normalfont\itshape , postheadspace = 1em , qed = \qedsymbol ]{mystyle} \declaretheorem[style=mystyle]{styledtheorem} \begin{document} \begin{styledtheorem}[Euclid] For every prime $p$\dots \end{styledtheorem} \end{document} --8<---cut here---end--->8--- Suppose I want to write a `thmtools.el'. If I want to catch and process user defined styles (in this case "mystyle"), I would currently do: --8<---cut here---start->8--- (defvar LaTeX-thmtools-declaretheoremstyle-regexp `(,(concat "declaretheoremstyle[ \t\n\r%]*" "\\(?:\\[\\(?:[\t\n\r[:print:]]*\\)\\]\\)?" "[ \t\n\r%]*" "{" "[ \t\n\r%]*\\([[:print:]]+\\)[ \t\n\r%]*" "}"))) (TeX-auto-add-type "thmtools-declaretheoremstyle" "LaTeX") (TeX-add-style-hook "thmtools" (lambda () (TeX-auto-add-regexp LaTeX-thmtools-declaretheoremstyle-regexp) ...)) --8<---cut here---end--->8--- My question is: Is there any other, better solution for this regexp? I am looking a general solution to handle this kind of cases. I hope it is more clear now. Cheers, Arash ___ auctex-devel mailing list auctex-devel@gnu.org https://lists.gnu.org/mailman/listinfo/auctex-devel