Discussion:
help with LaTeX-add-environment for pspicture
Patrick Drechsler
2005-01-29 13:19:56 UTC
Permalink
Remember to cover the basics, that is, what you expected to happen and
what in fact did happen.

If the bug (or problem) is triggered by a specific (La)TeX
file, you should try to produce a minimal sample file showing the
problem and include it in your report.

Your bug report will be posted to the AUCTeX mailing list.

Hi,

I'm trying to customize an environment so that pressing `C-c C-e'
offers me the correct behavior for the pspicture
environment. The problem I'm having is that the syntax for this
environment is a bit different from LaTeX default
environments. `pspicture' has a mandatory and an optional
argument which are both set in parenthesis. The two arguments
define the picture size (x0,y0)(x1,y1). When the optional
argument (x0,y0) is dropped x0 and y0 are set to (0,0) by
PSTricks.

Example usage:

--8<------------------------schnipp------------------------->8---
\documentclass{minimal}
\usepackage{pstricks}
\begin{document}
\begin{pspicture}(-1,-1)(1,1)
\psgrid%
\psline(0,0)(1,1)
\end{pspicture}

\vspace{5ex}

\begin{pspicture}(1,1) % equals \begin{pspicture}(0,0)(1,1)
\psgrid%
\psline(0,0)(1,1)
\end{pspicture}

\end{document}
--8<------------------------schnapp------------------------->8---

What I've come up with so far (after reading section 12.3 in the
AUCTeX manual) is passing a single optional argument:

--8<------------------------schnipp------------------------->8---
(add-hook 'LaTeX-mode-hook
'(lambda nil
(LaTeX-add-environments
'("pspicture" (lambda (env &rest ignore)
(LaTeX-insert-environment
env
(let ((overlay (read-input "(Optional) x0,y0: ")))
(unless (zerop (length overlay))
(format "(%s)" overlay)))))))))
--8<------------------------schnapp------------------------->8---

Besides the fact that I do not really understand how the above
works (I'm just experimenting with stuff I found in beamer.el) I
haven't been able to squeeze the mandatory argument in.

Could somebody give me a pointer on what needs to be
added/changed in the above? Or should I take a completely
different approach to this problem?

TIA,

Patrick

Emacs : GNU Emacs 21.3.50.2 (i686-pc-linux-gnu, X toolkit, Xaw3d scroll bars)
of 2005-01-13 on trurl
Package: AUCTeX 11.54

current state:
==============
(setq
window-system 'x
LaTeX-version "2e"
TeX-style-path '("style/" "auto/"
"/home/patrick/uni/literature/bibtex-files/style/"
"/home/patrick/.TeX/style/"
"/usr/share/doc/.TeX/style/"
"/usr/doc/.TeX/style/"
"/home/patrick/uni/literature/bibtex-files/auto/"
"/home/patrick/.TeX/auto/"
"/usr/share/doc/.TeX/auto/"
"/usr/doc/.TeX/auto/"
"/usr/local/share/emacs/site-lisp/auctex/style/"
"/usr/local/var/auctex/")
TeX-auto-save t
TeX-parse-self t
TeX-master t
)
Ralf Angeli
2005-01-29 16:07:40 UTC
Permalink
Post by Patrick Drechsler
I'm trying to customize an environment so that pressing `C-c C-e'
offers me the correct behavior for the pspicture
environment. The problem I'm having is that the syntax for this
environment is a bit different from LaTeX default
environments. `pspicture' has a mandatory and an optional
argument which are both set in parenthesis. The two arguments
define the picture size (x0,y0)(x1,y1). When the optional
argument (x0,y0) is dropped x0 and y0 are set to (0,0) by
PSTricks.
[...]
Post by Patrick Drechsler
Besides the fact that I do not really understand how the above
works (I'm just experimenting with stuff I found in beamer.el) I
haven't been able to squeeze the mandatory argument in.
Does the following function do what you want?

(lambda (env &rest ignore)
(LaTeX-insert-environment
env
(let ((lower-left (read-input "(Optional) Lower left corner (x0,y0): "))
(upper-right (read-input "Upper right corner (x1,y1): ")))
(concat (unless (zerop (length lower-left)) (format "(%s)" lower-left))
(format "(%s)" upper-right)))))
--
Ralf
Patrick Drechsler
2005-01-29 16:25:50 UTC
Permalink
Post by Ralf Angeli
Post by Patrick Drechsler
I'm trying to customize an environment so that pressing `C-c
C-e' offers me the correct behavior for the pspicture
environment.
[...]
Post by Ralf Angeli
Does the following function do what you want?
[...snipped working code...]

Works like a charm! Thank you very much for the quick solution!

Cheers

Patrick
--
Computers are good at following instructions,
but not at reading your mind. -- Donald Knuth
Loading...