[texworks] Qtscripts help
st.loeffler at gmail.com
Fri Jan 15 20:59:54 CET 2010
On 2010-01-15 20:02, kap4lin wrote:
> I am trying to replace the newline character by a space. Why does the
> following not work?
> var txt = TW.target.selection;
> txt = txt.replace(/\n/g,' ');
This doesn't work because of weird Qt internals. A Qt TextDocument (to
which TW.target.selection interfaces) uses the Unicode character U+2029
to represent paragraph marks instead of the usual newline characters.
Unfortunately, this Unicode char is outside the range that is usually
accessible by escape codes in regexps. For me, it did work to copy the
character directly from the internet into the script file (replacing the
I used Ubuntu Linux, gedit, and copied from the page
http://unicode.coeurlumiere.com/?n=8192 (note that I didn't see any
selection when selecting the character U+2029 - but it is there). The
character was rendered as a newline, but the script worked. Note however
that this will depend on the encoding the script is loaded with - which
is the default system codec, IIRC.
Actually, I rather consider this a bug (or at least "unexpected
behavior"). It would be great if you could create a new issue on Google
More information about the texworks