Discussion:
[AUCTeX] Entering maths
Denis Bitouzé
2017-06-13 10:51:14 UTC
Permalink
Hi,

does AUCTeX provide something making life easier for inline-math
expressions (`|' standing for the cursor position):

- `\(|\)',
- `$|$' (OK, it's easy to type two dollar signs and go back to write the
expression between the dollar signs, but would be better if done by
a shortcut)?

In the same vein, I know constructing display-math expressions with
`\[...\]':

- has some drawbacks if `amsmath' is not loaded,
- is synonym to `\begin{equation*}...\end{equation*}' if `amsmath' is
loaded,

but does AUCTeX provide something for `\[|\]'?

All the best.
--
Denis
Mosè Giordano
2017-06-13 11:09:36 UTC
Permalink
Hi Denis,
Post by Denis Bitouzé
Hi,
does AUCTeX provide something making life easier for inline-math
- `\(|\)',
- `$|$' (OK, it's easy to type two dollar signs and go back to write the
expression between the dollar signs, but would be better if done by
a shortcut)?
Yes, of course ;-) You have to customize the `TeX-electric-math'
option (https://www.gnu.org/software/auctex/manual/auctex.html#index-TeX_002delectric_002dmath):


-- User Option: TeX-electric-math
If the variable is non-nil and you type '$' outside math mode,
AUCTeX will automatically insert the opening and closing symbols
for an inline equation and put the point between them. The opening
symbol will blink when 'blink-matching-paren' is non-nil. If
'TeX-electric-math' is nil, typing '$' simply inserts '$' at point,
this is the default.

Besides 'nil', possible values for this variable are '(cons "$"
"$")' for TeX inline equations '$...$', and '(cons "\\(" "\\)")'
for LaTeX inline equations '\(...\)'.

If the variable is non-nil and point is inside math mode right
between a couple of single dollars, pressing '$' will insert
another pair of dollar signs and leave the point between them.
Thus, if 'TeX-electric-math' is set to '(cons "$" "$")' you can
easily obtain a TeX display equation '$$...$$' by pressing '$'
twice in a row. (Note that you should not use double dollar signs
in LaTeX because this practice can lead to wrong spacing in typeset
documents.)

In addition, when the variable is non-nil and there is an active
region outside math mode, typing '$' will put around the active
region symbols for opening and closing inline equation and keep the
region active, leaving point after the closing symbol. By pressing
repeatedly '$' while the region is active you can toggle between an
inline equation, a display equation, and no equation. To be
precise, '$...$' is replaced by '$$...$$', whereas '\(...\)' is
replaced by '\[...\]'.

If you want to automatically insert '$...$' in plain TeX files, and
'\(...\)' in LaTeX files by pressing '$', add the following to your init
file
(add-hook 'plain-TeX-mode-hook
(lambda () (set (make-variable-buffer-local 'TeX-electric-math)
(cons "$" "$"))))
(add-hook 'LaTeX-mode-hook
(lambda () (set (make-variable-buffer-local 'TeX-electric-math)
(cons "\\(" "\\)"))))
Post by Denis Bitouzé
In the same vein, I know constructing display-math expressions with
- has some drawbacks if `amsmath' is not loaded,
I believe this is fixed if you have a recent LaTeX version (2015/01/01
or newer, which is in TeX Live 2016).
Post by Denis Bitouzé
- is synonym to `\begin{equation*}...\end{equation*}' if `amsmath' is
loaded,
but does AUCTeX provide something for `\[|\]'?
If you set `LaTeX-electric-left-right-brace'
(https://www.gnu.org/software/auctex/manual/auctex.html#index-LaTeX_002delectric_002dleft_002dright_002dbrace)
to non nil, as you as you type "\[", the closing "\]" is inserted
after point.

Bye,
Mosè
Denis Bitouzé
2017-06-13 12:21:00 UTC
Permalink
Post by Mosè Giordano
Hi Denis,
Hi Mosé,
Post by Mosè Giordano
Post by Denis Bitouzé
Hi,
does AUCTeX provide something making life easier for inline-math
- `\(|\)',
- `$|$' (OK, it's easy to type two dollar signs and go back to write the
expression between the dollar signs, but would be better if done by
a shortcut)?
Yes, of course ;-) You have to customize the `TeX-electric-math'
[...]
Ooops, sorry for the noise: I looked at the AUCTeX documentation, but
not at the right place:
┌────
│ https://www.gnu.org/software/auctex/manual/auctex/Mathematics.html
└────

IMHO, too bad TeX-electric-math is nil by default...

As an extra question, documentation says:

By pressing repeatedly $ while the region is active you can toggle
between an inline equation, a display equation, and no equation. To be
precise, ‘$...$’ is replaced by ‘$$...$$’, whereas ‘\(...\)’ is
replaced by ‘\[...\]’.

But how to get:

- ‘$|$’ with an "unrepeated" `$',
- ‘\[|\]’ with an "repeated" `$'?
Post by Mosè Giordano
Post by Denis Bitouzé
In the same vein, I know constructing display-math expressions with
- has some drawbacks if `amsmath' is not loaded,
I believe this is fixed if you have a recent LaTeX version (2015/01/01
or newer, which is in TeX Live 2016).
Ah, good to know!
Post by Mosè Giordano
Post by Denis Bitouzé
- is synonym to `\begin{equation*}...\end{equation*}' if `amsmath' is
loaded,
but does AUCTeX provide something for `\[|\]'?
If you set `LaTeX-electric-left-right-brace'
(https://www.gnu.org/software/auctex/manual/auctex.html#index-LaTeX_002delectric_002dleft_002dright_002dbrace)
to non nil, as you as you type "\[", the closing "\]" is inserted
after point.
OK.

Thanks!
--
Denis
Mosè Giordano
2017-06-13 12:52:17 UTC
Permalink
Post by Denis Bitouzé
IMHO, too bad TeX-electric-math is nil by default...
I'd expect some people complaining about any value we'd choose as default ;-)
Post by Denis Bitouzé
- ‘$|$’ with an "unrepeated" `$',
- ‘\[|\]’ with an "repeated" `$'?
The associations "$...$" → "$$...$$" and "\(...\)" → "\[...\]" are
hard-coded in `TeX-insert-dollar', there is currently no easy way to
overturn them.

Bye,
Mosè
Denis Bitouzé
2017-06-13 13:04:23 UTC
Permalink
Post by Mosè Giordano
Post by Denis Bitouzé
IMHO, too bad TeX-electric-math is nil by default...
I'd expect some people complaining about any value we'd choose as default ;-)
Except that this is the only one which is complainable :)
Post by Mosè Giordano
Post by Denis Bitouzé
- ‘$|$’ with an "unrepeated" `$',
- ‘\[|\]’ with an "repeated" `$'?
The associations "$...$" → "$$...$$" and "\(...\)" → "\[...\]" are
hard-coded in `TeX-insert-dollar', there is currently no easy way to
overturn them.
Very bad news, indeed...
--
Denis
g***@gmail.com
2017-06-13 13:19:34 UTC
Permalink
Hi Denis, take a look at the smartparens package (available on Elpa):

https://github.com/Fuco1/smartparens/wiki

I use it to get self-inserting parentheses and dollar signs instead of
Auctex's electric capabilities, and it works fine for the most part.
Maybe it'll give you more customization possibilities.
Denis Bitouzé
2017-06-13 15:14:12 UTC
Permalink
Post by Mosè Giordano
Hi Denis,
Hi,
Post by Mosè Giordano
https://github.com/Fuco1/smartparens/wiki
I use it to get self-inserting parentheses and dollar signs instead of
Auctex's electric capabilities, and it works fine for the most part.
Maybe it'll give you more customization possibilities.
Nice indeed.

But too bad pressing repeatedly $ while the region is active, it doesn't
toggle between ‘$|$‘ and ‘\[|\]‘ (hitting the backslash key on a French
keyboard is a nightmare): I'll probably open an issue on this subject on
the github repository of `smartparens'.
--
Denis
Jean-Jacques Rétorré
2017-06-13 16:12:17 UTC
Permalink
mar. 13 juin 2017, Denis Bitouzé <***@wanadoo.fr> disait :

<snip>

(hitting the backslash key on a French keyboard is a nightmare)

As an example

,----
| (define-key key-translation-map [?µ] [?\\])
`----

and the very useless key "µ" is now "\"

On a french PC keyboard, The worst is probably the "`" key.
It is a lot of useless key you can re-use...

--
JJR.
g***@gmail.com
2017-06-13 17:58:26 UTC
Permalink
Post by Jean-Jacques Rétorré
,----
| (define-key key-translation-map [?µ] [?\\])
`----
and the very useless key "µ" is now "\"
Indeed, and there are similar solutions for Windows if you use that
operating system – let me know if you want more information.

Another possibility is Autohotkey (also Unix and Windows).

These key-remapping solutions are probably the best for you, Denis, as
I imagine the backslash also haunts you outside of Emacs.

Sorry for going off-Auctex topic now.
Denis Bitouzé
2017-06-14 06:50:30 UTC
Permalink
Post by g***@gmail.com
Post by Jean-Jacques Rétorré
,----
| (define-key key-translation-map [?µ] [?\\])
`----
and the very useless key "µ" is now "\"
Indeed, and there are similar solutions for Windows if you use that
operating system – let me know if you want more information.
I'm using Linux.
Post by g***@gmail.com
Another possibility is Autohotkey (also Unix and Windows).
These key-remapping solutions are probably the best for you, Denis, as
I imagine the backslash also haunts you outside of Emacs.
Indeed.

I guess Autohotkey is not necessary on Linux: `xkb' lets you remap any
key on the keyboard. But, anyway, I'd like to keep most of the keys like
they are :)

Thanks!
--
Denis
Denis Bitouzé
2017-06-14 06:39:30 UTC
Permalink
Post by Jean-Jacques Rétorré
<snip>
(hitting the backslash key on a French keyboard is a nightmare)
As an example
,----
| (define-key key-translation-map [?µ] [?\\])
`----
and the very useless key "µ" is now "\"
Indeed.

I made a mistake since I already used such a trick for the backslash
(with "²" instead of "µ" :) In fact, I had "[" and "]" in mind.
Post by Jean-Jacques Rétorré
On a french PC keyboard, The worst is probably the "`" key.
It is a lot of useless key you can re-use...
The problem is, "[" and "]" and "@" and "}" are nightmares as well on
French keyboards ;)
--
Denis
David Kastrup
2017-06-14 06:54:23 UTC
Permalink
Post by Denis Bitouzé
Post by Jean-Jacques Rétorré
<snip>
(hitting the backslash key on a French keyboard is a nightmare)
As an example
,----
| (define-key key-translation-map [?µ] [?\\])
`----
and the very useless key "µ" is now "\"
Indeed.
I made a mistake since I already used such a trick for the backslash
(with "²" instead of "µ" :) In fact, I had "[" and "]" in mind.
Post by Jean-Jacques Rétorré
On a french PC keyboard, The worst is probably the "`" key.
It is a lot of useless key you can re-use...
French keyboards ;)
Frankly, I never use anything but a U.S. keyboard layout (with whatever
actual keyboard layout may be printed on the keys themselves) with some
mode shift or whatever else provides compose-key similar functionality.
Yes, I write German texts with that as well. Emacs does offer

C-\ runs the command toggle-input-method (found in global-map), which
is an interactive compiled Lisp function in ‘mule-cmds.el’.

It is bound to C-\, <menu-bar> <options> <mule> <toggle-input-method>.

(toggle-input-method &optional ARG INTERACTIVE)
[...]

but I find that I don't use this except in emergencies (when the Compose
key got lost during some system upgrade and I cannot figure out how to
regain it within minutes).

My mother is actually an American with a history of writing lots of
letters on her U.S. mechanical typewriter, and she is using a German
keyboard layout on computers. I don't get that but probably playing
around with keyboard layouts is beyond her comprehension. And she does
need to write in German occasionally and probably would not get the hang
of a Compose key or other contraption not printed on the keyboard.
--
David Kastrup
Denis Bitouzé
2017-06-14 07:47:03 UTC
Permalink
Post by David Kastrup
Frankly, I never use anything but a U.S. keyboard layout (with
whatever actual keyboard layout may be printed on the keys themselves)
with some mode shift or whatever else provides compose-key similar
functionality.
Wow! I wouldn't be able to type on an AZERTY keyboard with QWERTY
layout...
--
Denis
David Kastrup
2017-06-14 08:22:50 UTC
Permalink
Post by Denis Bitouzé
Post by David Kastrup
Frankly, I never use anything but a U.S. keyboard layout (with
whatever actual keyboard layout may be printed on the keys themselves)
with some mode shift or whatever else provides compose-key similar
functionality.
Wow! I wouldn't be able to type on an AZERTY keyboard with QWERTY
layout...
I actually right now have a keyboard with Æ Ø Å in the place of ;'[ and
where a German keyboard would have Ä Ö Ü (don't ask me in which order).

The guy selling it put a pad of German keytop stickers in the package
but I did not quite see the point in gluing German keytop stickers on a
keyboard I was going to use with U.S. layout.

I think what makes the bulk of getting used to when switching around and
not typing entirely blind is () being shifted 90 on U.S. keyboards and
shifted 89 on German (Danish?) keyboards. That's just too close.
--
David Kastrup
Loading...