[texworks] Regex for DTX mode

Will Robertson wspr81 at gmail.com
Fri Sep 26 17:21:36 CEST 2008


On 27/09/2008, at 12:05 AM, Jonathan Kew wrote:

> On 26 Sep 2008, at 3:12 PM, Joseph Wright wrote:
>> Yes, background is more of an issue for me too.  I'm thinking that  
>> this
>> allows combinations of properties, which I like the idea of.
>
> So something like "green,bold,bg:yellow"?
>
> I don't want to go too far with this... different fonts, etc... but  
> maybe something more than just text color would be possible.

I like to keep things simple, too (only three or four colors, max, no  
styling). But yeah. Different background colours are definitely nice  
for "switch-mode" documents like DTX files.

iTeXMac's method of being able to use a monospaced font for code and a  
roman font for text was rather nice, but I'd hesitate before  
travelling down that route...

> Note that the current implementation, at least, applies the first  
> match it finds and then skips to the end of the matched text; do you  
> feel there's a need to layer multiple styles on top of each other,  
> rather than this "exclusive" model?

Hum. I reckon for now leave things as is and if people want to blend  
styles they'll have to do it manually. (I.e., define colours for  
commented code and macrocode code individually for the case of DTX  
files.)

I'd much prefer a carefully selected blend of colours rather than an  
unconsidered mix when disparate colouring regexes collide.

***

Speaking of that background colour blending for nested groups, here's  
something like what it would like like:

-------------- next part --------------
A non-text attachment was scrubbed...
Name: texshop_image.pdf
Type: application/pdf
Size: 20612 bytes
Desc: not available
Url : http://tug.org/pipermail/texworks/attachments/20080927/3491c140/attachment-0001.pdf 
-------------- next part --------------



I guess I'm not 100% convinced. Would really make it easier to see  
what was going on when you missed out a }, though.

***

> It would, because it's using whitespace to separate the fields in  
> the configuration file!

:)

> I suppose I should change that, if you're wanting to be able to put  
> explicit spaces (as opposed to general whitespace, \s) into  
> patterns. I was trying to do something rather minimalist.... perhaps  
> too much so!

Well, it wouldn't be so much of a problem if there was an escape char  
for "literal space".

> How about requiring <TAB>s to separate the fields? Then space would  
> be allowed in patterns, and you can still use the \t escape sequence  
> if you need an actual tab there. (That's actually what I did first,  
> then I switched to using any whitespace as the separator; apparently  
> a bad move.)


That's probably a better scheme for now. It would be nice if the  
regexes could be commented and split up over lines, but that's  
probably a bit of an over-ambitious wish. I'm thinking of, say,  
TextMate's regexes for similar things:

begin = '(?x)
	(	# Capture 1
	(\\)	# Marker
	(?:
		(?:sub){0,2}section	# Functions
		  | (?:sub)?paragraph
		  | chapter|part|addpart
		  | addchap|addsec|minisec
	)
	(?:\*)?										
...

I'm not saying that you should add all of the metadata that TextMate  
has, but instead of writing

"dtx prefixes"		^(\s+|\s*%<[A-Za-z\|\&,]+>\s*|\s*%\s*(?!\s*\\begin\ 
{macrocode\}|\s*<\*[A-Za-z\|\&,]+>))

it might be better in the long run to have something a little more  
maintainable:

"dtx prefixes"		'^(
   \s+|   # whitespace
   \s*%<[A-Za-z\|\&,]+>\s*|   # single-line guard
   \s*%\s*(
     ?!\s*\\begin\{macrocode\}|
     \s*<\*[A-Za-z\|\&,]+>
   )  # not after entering a macrocode or opening guard
)'

Cheers,
Will


More information about the texworks mailing list