Creating LaTeX environments with Autohotkey the easy way

Here’s a neat little script (bound to Alt-e) which requests an environment name from the user. If the entered string has e.g. the form "itemize3" it creates

\begin{itemize}
\item
\item 
\item 
end{itemize} 

and puts the cursor directly after the first \item.

If the entered string includes no number at the end (e.g. „itemize“), just the environment is created.

!e::
InputBox, UserEnv, Environment, Please enter an environment!, , 240, 120
If ErrorLevel
	return
Else 
if( RegExMatch(UserEnv, "(.*?)(\d+)$", splitted) ) {
	Send \begin{{}%splitted1%{}}{Enter}
		Loop %splitted2% {
			Send \item {Enter}
		}
	Send \end{{}%splitted1%{}}{Up}
	count2 := splitted2 - 1 
	Loop %count2% {
		Send {Up}
	}			
} 
Else 
	Send \begin{{}%UserEnv%{}}{Enter 2}\end{{}%UserEnv%{}}{Up}
return

Thx to MCL for providing help with the regexp!

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website