Adding New LaTeX Environments

An Alpha user asked on one of the AlphaTcl Mailing Lists:

    Is there any way to assign the LaTeX "proof" environment to some kind of
    keyboard shortcut?  I would like something like

        \begin{proof}

        <tabstop>

        \end{proof}

    I would do an electric completion, but I am not sure how to get the
    newline characters in the completion.  What is the best way to do this?
    I am also interested in defining a similar keyboard shortcut for
    "cases".  Thanks very much.

There are a few different ways to approach this. Unfortunately, the menu command "TeX > LaTeX Menu > Add Menu Template Item" (as described in the Adding LaTeX Menu items page) isn't one of them, because at present it doesn't allow you to easily enter a new line character. This is a known limitation that we hope to address in a future release.

Here are a couple of methods you can try. Note that both of them make use of electrics, and will not actually add the environment to any of the TeX submenus. It is possible that this functionality might be addressed in a later release...



Add a special binding and procedure


Open (or create) your TeXPrefs.tcl file by selecting

Config > TeX Mode Prefs > Edit Prefs File'''

when the active window is in TeX mode.

Add this to your TeXPrefs.tcl file:

    proc TeX::insertProof {} {
        elec::Insertion "\\begin{proof}\n\n••\n\n\\end{proof}"
        return
    }

    Bind 'p' <sz> {TeX::insertProof} TeX

This will bind Control-Shift-P to invoke your new procedure. See the

Help > Keyboard Shortcuts

file for information about the [Bind] command, and how to specify modifiers in the "User Defined Key bindings" section.



Add a new environment "electric completion" body


To use this option, make sure that the preferences

    Accept Any TeX Environment
    Prompt To Create TeX Environment

are turned on, via the

Config > TeX Mode Prefs > Preferences

command. Both of these influence what happens when an unknown electric environment completion is invoked. Once they are turned on, you can type in

    \begin

and press your Completion shortcut. Then type in "proof" and press the Completion shortcut again. If no TeXbodies(proof) variable has been defined you'll be prompted to add the body for this new environment.

The next steps depend on which version of AlphaTcl you are using.

Notes:


(AlphaTcl 8.0 and older) :

Enter this in the dialog text field:

    \r••\r

This method will automatically add the "TeXbodies(proof)" variable to your "prefs.tcl" file that you can then modify later if desired.


(AlphaTcl 8.1a1 or newer) :

Enter this in the dialog text field:

    \\r••\\r

This method will automatically add the "TeXbodies(proof)" variable to your "TeXPrefs.tcl" file that you can then modify later if desired.


(All versions) :

In the future, when you add "proof" to the \begin{} text and press the Completion shortcut this text will be automatically inserted into the active window.

Note that you can also invoke an environment completion by typing in

    b'<envName>

as in

    b'quote

or

    b'proof

Just as with the \begin{} completion, if the appropriate preferences are set and no TeXbodies(<envName>) variable has been defined, you will be prompted to create a new template. Many users find this "contraction" completion very useful, and it is an ideal method for creating new environments.


Category FAQ