auctex-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [AUCTeX-devel] Regex best practice


From: Arash Esbati
Subject: Re: [AUCTeX-devel] Regex best practice
Date: Sat, 21 Nov 2015 23:20:37 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5

Hi Mosè,

Mosè Giordano <address@hidden> writes:

> 2015-11-19 20:58 GMT+01:00 Arash Esbati <address@hidden>:

>> 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]