Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Does anybody know of a way to create a keyboard short-cut for inserting a set of {}'s and ()'s in TeXnicCenter?

I have looked into defining my own Text Modules in the Insert tab, but this still requires me to press Alt-I-M-6 to insert the "number 6" Text Module (my own). I am looking for something shorter; a Ctrl+Alt+? solution.

share|improve this question

migrated from stackoverflow.com Feb 17 '12 at 1:05

This question came from our site for professional and enthusiast programmers.

    
Welcome to TeX.sx! Your question was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other, otherwise you won't be able to comment on or accept answers or edit your question. –  Werner Feb 17 '12 at 2:23
add comment

1 Answer 1

For this kind of customization, you can use AutoHotkey. It is a Windows-based TSR application that runs in the background and is activated based on certain keystroke scripts.

If you know the AutoHotkey interface, skip over this section...


AutoHotkey bases a keystroke sequence <ks-seq> on its own scripting language and replaces the keystroke combination with some other set of actions <actions> and sends it to the active window. In short, the syntax used (and stored in a file AutoHotkey.ahk, say) is set of expressions of the form

<ks-seq>::<actions>

Here is a list of some of the available commands/keystrokes (taken from AutoHotkey "Send" command documentation):

  • !: Sends an Alt keystroke. For example, Send This is text!a would send the keys This is text and then press Alt+a. Note: !A produces a different effect in some programs than !a. This is because !A presses Alt+SHIFT+A and !a presses Alt+a. If in doubt, use lowercase.

  • +: Sends a SHIFT keystroke. For example, Send +abC would send the text AbC, and Send !+a would press Alt+SHIFT+a.

  • ^: Sends a Ctrl keystroke. For example, Send ^!a would press Ctrl+Alt+a, and Send ^{Home} would send Ctrl+Home. Note: ^A produces a different effect in some programs than ^a. This is because ^A presses Ctrl+SHIFT+A and ^a presses Ctrl+a. If in doubt, use lowercase.

  • #: Sends a WIN keystroke, therefore Send #e would hold down the Windows key and then press the letter e.


...and start reading here again.

As such, you could define the hotkeys

  • Ctrl+Alt+p (short for parentheses) using ^!p::Send (); and
  • Ctrl+Alt+b (short for braces) using ^!b::Send {{}{}}. Note the grouping required for successfully sending { and }.

This is what AutoHotkey.ahk would look like:

; IMPORTANT INFO ABOUT GETTING STARTED: Lines that start with a
; semicolon, such as this one, are comments.  They are not executed.

; Ctrl+Alt+b -> {}
^!b::Send {{}{}}
; Ctrl+Alt+p -> ()
^!p::Send ()

You could append {Left} to each command, which would move the cursor back one spot to between () or {}, if need be. Changes to hotkeys can be made on-the-fly, as long as you "reload the script" before using it.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.