help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: LaTeX templates (or just templates in general)


From: Tim X
Subject: Re: LaTeX templates (or just templates in general)
Date: Sun, 17 May 2009 11:29:35 +1000
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.93 (gnu/linux)

Jean Magnan de Bornier <jean@bornier.net> writes:

> Orri <orritomasson@gmail.com> wrote :
>
> | I am rather new to emacs.
>>
> | I have used the editor TextMate on mac and it has a very nice feature I like
> | and was wondering how I can acheive a similar thing in emacs.
>>
> | When I am in latex mode in textmate and write temp[tabkey], I can choose
> | from a list of code segments to insert to the current file (or buffer).  I
> | often use this to insert frequently used code segments (3-10 lines) to
> | achieve tasks I frequently do. These segments are stored in a folder named
> | ~/Library/Applications Support/LaTeX/Templates
>>
> | I know I can use [C-x i], But it takes so much time to write the correct
> | path every single time.
> | So I am looking for something like [C-x i] except it by default starts in
> | specified directory (rather than the current directory). 
>>
> | I know I can of course, in every latex project directory specify a symbolic
> | link (with a short name) to this directory, but I find it to be too much of
> | dirty hack.
>>
> | Does anyone have any suggestions about how to acieve this?
>
> Hi,
>
> I have several elisp functions defined in my .emacs file to help me the
> way you think: here is one to add a frame to a beamer document:
>
> .....................
> (defun addframe ()
>   "Ouvre une frame dans beamer" 
>  (interactive)
>    (insert "\\begin{frame}
>  \\frametitle{}
> \\end{frame}")
>   (backward-char 13)
>   (indent-for-tab-command)
> )
>
> (global-set-key (kbd "C-c f") 'addframe)
> ....................
>
> You can write many of those to your needs...


I find tempo, which comes with emacs, to be good for this sort of
thing. I have various template files that ae loaded at startup and bound
to various keys. Usually, I do this in a load hook for the mode. I have
one general purpose template I use for headers. e.g.

(tempo-define-template "generic-header"
        '((format "%s" comment-start)
          "      Filename: " (file-name-nondirectory (buffer-file-name)) 'n
          (format "%s" comment-start) " Creation Date: "
          (format-time-string "%A, %d %B %Y %I:%M %p %Z") 'n
          (format "%s" comment-start) " Last Modified: " 'n
          (format "%s" comment-start)
          "        Author: Tim Cross <tcross@some.place.com>" 'n
          (format "%s" comment-start) "   Description:" 'n
          (format "%s" comment-start) 'n
          'n))

;;; Lets setup some key bindings.

(global-set-key [(f5)] 'tempo-template-generic-header)

The above template uses the setting of the modes current comment
character to insert a file header that has a dynamic last modified
timestamp that is automatically updated when I save the file. 

What I find useful with tempo modes is that you can have it prompt for
values that it can then insert multiple times. For example, I have the
following template for creating plsql spec files

(tempo-define-template "plsql-package-spec"
                '("CREATE OR REPLACE PACKAGE " (p "Package name: " pname) 'n
                  "IS" 'n
                  'n
                  "-- Unique package identifier" '> 'n
                  "pkg_id CONSTANT urs.identifier := '" (s pname) "';" '> 'n
                  "pkg_ver CONSTANT urs.version := 1.00;"
                  'n 'n 'n
                  "END " (s pname) ";" 'n
                  "/" 'n))

this template prompts me for the name of the package and inserts it into
the definition line and sets a constant in the package. 

In addition to prompting for values that can be used multiple times in
your template, you can also control where the cursor is left and whether
or not the template should take note of mode indentation etc. 

It takes a bit of playing around to get the feel for the package, but
once you have a handle on it, its quite easy to create new templates. 

I define various hot keys to insert the templace. For example, in
plsql-mode, I hit C-c s to inisert a package spec, C-c p to insert a
procedure skeleton etc. 

There is also skeleton-mode, that is another template system for
emacs. It is a bit harder to get your head wrapped around, but it is
very powerful. 

You can also achieve a lot of template like functionality with abbrev
mode. 

I don't actually have any templates for latex as I finid the auctex
package handles it all pretty well 'out of the box'. If your using
beamer or some such package, you can re-evaluate so that it has some
knowledge about the various macros and commands. Inserting a new beamer
frame is then just a keystroke away. 

HTH

Tim

-- 
tcross (at) rapttech dot com dot au


reply via email to

[Prev in Thread] Current Thread [Next in Thread]