[texhax] Eplain TeX: problem with \@optionalarg (in use with Emacs and Xdvi) (was: Eplain TeX: problem with \@optionalarg)

Rodolfo Medina rodolfo.medina at gmail.com
Mon Feb 14 15:54:35 CET 2011


Heiko Oberdiek <heiko.oberdiek at googlemail.com> writes:

> On Sun, Feb 13, 2011 at 04:48:03PM +0000, Rodolfo Medina wrote:
>
>> Heiko Oberdiek <heiko.oberdiek at googlemail.com> writes:
>> 
>> > On Sun, Feb 13, 2011 at 01:50:01PM +0000, Rodolfo Medina wrote:
>> >
>> >> it is suggested the following code:
>> >> 
>> >>      \makeatletter
>> >>      % \mo{m}[o]
>> >>      \def\mo#1{\def\mo at arg{#1}\@getoptionalarg\fin at mo}
>> >> 
>> >>      \def\fin at mo{\vskip1pc
>> >>       \message{^^JArg: \mo at arg}%
>> >>       \message{^^JOptional arg: \@optionalarg}%
>> >>      }
>> >> 
>> >> Now, I wish to put a condition there:
>> >> 
>> >>    \ifx\@optionalarg\empty
>> >>         \fin at mo
>> >>    \else
>> >>         \@getoptionalarg\fin at mo
>> >>    \fi
>> >
>> > \@getoptionalarg defines \@optionalarg. Therefore \@getoptionalarg
>> > must be called first. Then you can test inside \fin at mo.
>> 
>> 
>> Thanks.  But how can I do that in practice?  
>
> \def\mo#1{%
>   \def\mo at arg{#1}%
>   \@getoptionalarg\fin at mo
> }
> \def\fin at mo{%
>   \ifx\@optionalarg\empty
>     \message{^^JOptional argument empty or not given}%
>   \else
>     \vskip1pc %
>     \message{^^JArg: \mo at arg}%
>     \message{^^JOptional arg: \@optionalarg}%
>   \fi
> }


Many thanks to Heiko.

If anyone has the patience to do a little test, I need help with a certain
problem, occurring when I do, in the above code, `\@getoptionalarg\fin at mo'
instead of simply `\fin at mo', i.e. when I use the command \@getoptionalarg.  In
other words, that command gives me some little problem with the forward search
performed with Emacs and Xdvi.  The problem only occurs when the optional
argument is void.

I'm attaching the file test2.tex.  Here is the file `.emacs':

--------------------------------------------------------------------------
;; Forward and inverse search:
(add-to-list 'load-path (expand-file-name "~/lib/emacs"))
(require 'xdvi-search)
(add-hook 
 'LaTeX-mode-hook 
 (lambda () (local-set-key "\C-x\C-j" 'xdvi-jump-to-line-fullpath))) 
(add-hook 
 'TeX-mode-hook 
 (lambda () (local-set-key "\C-x\C-j" 'xdvi-jump-to-line-fullpath))) 
(server-start)

;; load auctex:
(load "auctex.el" nil t t)
--------------------------------------------------------------------------

Besides, you have to have xdvi and AucTeX installed on your system, and also
Eplain of course.  Besides, at:

 http://paste.debian.net/107578/

I posted the file `xdvi-search.el', and at:

 http://paste.debian.net/107579/

the file `srctex.sty'.  Now:

1) create the above file `~/.emacs';
2) put xdvi-search.el in ~/lib/emacs;
3) put `test2.tex' and srctex.sty in the same directory;
4) process the file with `tex test2'.

Now, with point at line 26 in test2.tex, type `C-x C-j': the dvi file will be
created, and you will be on the first paragraph, which is wrong.  But if you
put `[]' at the end of line 26, save the file, process it again and repeat `C-x
C-j', you will be, in the dvi file, on the right place.  So the problem occurs
when the optional argument is void.

I wish to know if that error can be avoided and how.

Thanks for any help
Rodolfo


-------------- next part --------------
A non-text attachment was scrubbed...
Name: test2.tex
Type: text/x-tex
Size: 854 bytes
Desc: not available
URL: <http://tug.org/pipermail/texhax/attachments/20110214/76624f5d/attachment-0001.bin>


More information about the texhax mailing list