<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=iso-8859-1" http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 8.00.6001.18812">
<STYLE></STYLE>
</HEAD>
<BODY bgColor=#ffffff>
<DIV><FONT size=1>
<P>message from TeXworks user</P>
<P><FONT size=2>I am very new to Lua as no doubt the following will confirm, but 
I have been able to hobble this together from the Tutorials and chm help and 
other Lua Wiki resources.</FONT></P>
<P><FONT size=2>Share it in case it inspires any one else...</FONT></P>
<P><FONT size=2>(Also wondering, does TW object expose any more properties or 
methods please?</FONT></P>
<P><FONT size=2>Paul</FONT></P>
<P><FONT size=2>--[[TeXworksScript<BR>Title: Sentance Case<BR>Description: Puts 
Selection into Sentance Case beware of Proper Names being lowercased<BR>Author: 
Paul A Norman From gleanings in Lua chm help Lua 5.1 Reference Manual, wiki, and 
tutorials<BR>Version: 0.4<BR>Date: 2009-09-02<BR>Script-Type: 
standalone<BR>]]<BR>-- Sentance Case</FONT></P>
<P><FONT size=2>&nbsp;txt = TW.getSelectedText()</FONT></P>
<P><FONT size=2>&nbsp;txt = string.lower(txt) -- normlaise case beware of Proper 
Names being lowercased</FONT></P>
<P><FONT size=2>&nbsp;txt = txt:gsub("^%s*(.-)%s*$", "%1") -- trims spaces from 
front and, back - is impnt for checking for period dot (uk fullstop)</FONT></P>
<P><FONT size=2>&nbsp;txt = " " .. txt:gsub("^%l", string.upper)&nbsp; -- puts 
first letter into capital adds space to front</FONT></P>
<P><FONT size=2>&nbsp;&nbsp;&nbsp; &nbsp;i = string.len(txt)</FONT></P>
<P><FONT size=2>&nbsp;&nbsp;&nbsp; rr = txt:sub(i)</FONT></P>
<P><FONT size=2>&nbsp;if rr ~= "." then txt = txt .. "." end</FONT></P>
<P><FONT size=2>&nbsp; txt = txt ..&nbsp; " " -- adds space to end to avoid 
collissions, LaTeX doesn't worry about extra spaces if we over do it</FONT></P>
<P><FONT size=2>&nbsp;TW.replaceSelectedText(txt)</FONT></P>
<P><FONT size=2>----------------</FONT></P>
<P><FONT size=2>--[[TeXworksScript<BR>Title: Trim<BR>Description: Trims 
Selection<BR></FONT><FONT size=2>Author: Paul A Norman From gleanings in Lua chm 
help Lua 5.1 Reference Manual, wiki, and tutorials<BR>Version: 0.1<BR>Date: 
2009-09-02<BR>Script-Type: standalone<BR>]]<BR>-- Trim blanks from front and 
back</FONT></P><FONT size=2>
<P><BR>&nbsp;txt = TW.getSelectedText()</P>
<P>&nbsp;txt = txt:gsub("^%s*(.-)%s*$", "%1")</P>
<P>&nbsp;TW.replaceSelectedText(txt)</P>
<P>------------------</P>
<P>--[[TeXworksScript<BR>Title: Title Case<BR>Description: Puts Selection into 
Title Case<BR>Author: Paul A Norman From gleanings in Lua chm help Lua 5.1 
Reference Manual, wiki, and tutorials<BR>Version: 0.1<BR>Date: 
2009-09-02<BR>Script-Type: standalone<BR>]]<BR>--Change an entire string to 
Title Case (i.e. capitalise the first letter of each word)</P>
<P>local function tchelper(first, rest)<BR>&nbsp; return 
first:upper()..rest:lower()<BR>end<BR>-- Add extra characters to the pattern if 
you need to. _ and ' are<BR>--&nbsp; found in the middle of identifiers and 
English words.<BR>-- We must also put %w_' into [%w_'] to make it handle normal 
stuff<BR>-- and extra stuff the same.<BR>-- This also turns hex numbers into, 
eg. 0Xa7d4</P>
<P>&nbsp;txt = TW.getSelectedText()</P>
<P>&nbsp;txt = string.lower(txt)</P>
<P>&nbsp;txt = txt:gsub("(%a)([%w_']*)", tchelper)</P>
<P>&nbsp;TW.replaceSelectedText(txt)<BR><BR>-----------------------</P>
<P>--[[TeXworksScript<BR>Title: Date Time<BR>Description: Puts Date Time 
in<BR>Author: Paul A Norman From gleanings in Lua chm help Lua 5.1 Reference 
Manual, wiki, and tutorials<BR>Version: 0.1<BR>Date: 2009-09-02<BR>Script-Type: 
standalone<BR>]]</P>
<P>-- txt = TW.getSelectedText()</P>
<P>&nbsp;TW.replaceSelectedText(os.date())</P>
<P>--------------------------</P>
<P>--[[TeXworksScript<BR>Title: Lowercase<BR>Description: Puts Selection into 
Lowercase<BR>Author: Paul A Norman From gleanings in Lua chm help Lua 5.1 
Reference Manual, wiki, and tutorials<BR>Version: 0.1<BR>Date: 
2009-09-02<BR>Script-Type: standalone<BR>]]</P>
<P>&nbsp;txt = TW.getSelectedText()</P>
<P>&nbsp;txt = string.lower(txt)</P>
<P>&nbsp;TW.replaceSelectedText(txt)<BR><BR>-----------------------</P>
<P>--[[TeXworksScript<BR>Title: Uppercase<BR>Description: Puts Selection into 
Uppercase<BR>Author: Paul A Norman From gleanings in Lua chm help Lua 5.1 
Reference Manual, wiki, and tutorials<BR>Version: 0.1<BR>Date: 
2009-09-02<BR>Script-Type: standalone<BR>]]</P>
<P>&nbsp;txt = TW.getSelectedText()</P>
<P>&nbsp;txt = string.upper(txt)</P>
<P>&nbsp;TW.replaceSelectedText(txt)<BR></P></FONT></FONT></DIV></BODY></HTML>