13

Is there a way to replace the $$ ... $$ macro with the \[ ... \] macros? (and replace inline mathmode as well)

I realised the only way I can write the \sum_{i=1}^{10} t_i is between the \[ ... \] LaTeX maths-mode. It also seems to layout the maths nicer (bigger, with gaps).

However, $$ ... $$ is faster to write... so is there a way to replace the $$ ... $$ macro, to act in the LaTeX fashion?

9
  • Nah, read that that mode isn't supported properly by LaTeX (ref: WikiBooks)
    – A T
    Commented Oct 6, 2011 at 0:49
  • Caramdir: Well whichever is the one for inline want to replace $, and for newline replace $$
    – A T
    Commented Oct 6, 2011 at 0:50
  • 1
    I don't think this is possible, since \[...\] themselves are defined in terms of $$. Or am I wrong?
    – Werner
    Commented Oct 6, 2011 at 1:46
  • 1
    Textmate's LaTeX mode turns $$[tab] into \[ <cursor> \].
    – topskip
    Commented Oct 6, 2011 at 5:56
  • 1
    Related question (which can be used to solve this problem but may break verbatim etc.) math mode - Can I redefine the dollar - TeX - LaTeX Stack Exchange
    – user202729
    Commented Oct 19, 2022 at 18:31

3 Answers 3

14

This is not a direct answer to your question but maybe a better solution: use snippet management to ease writing \[ ... \] constructions. This of course requires an editor with support for snippets management.

You could create a snippet that activates when writing $Tab (or some key command) and when it's activates it inputs

\[

\]

and places the cursor between them.

In many snippets managers this snippet is simply:

\[
$1
\]

For an explanation of how YASnippet, a snippet manager for Emacs, works, see Working with templates.

11
  • That is what Textmate does (with $$-tab). I'd accept that answer if I had asked that question :)
    – topskip
    Commented Oct 6, 2011 at 6:17
  • 2
    Since you are at it, replace it not with \[...\] but with \begin{align*}...\end{align*}. It should be functionally equivalent, easier to read and transform into something else (want numbering? Remove the *. Want to display two equations side-by-side? Just do it!) Commented Oct 6, 2011 at 7:11
  • I use TeXWorks. Is there a feature like this for it?
    – A T
    Commented Oct 6, 2011 at 15:19
  • @AT Dunno. Maybe that is for another question.
    – N.N.
    Commented Oct 6, 2011 at 15:22
  • N.N: Could you please illustrate a MWE if possible? Maybe rendering \[...\] from typing $$ and automatically placing the cursor ready for typing inside the \[cursor\] mode.
    – night owl
    Commented Oct 9, 2011 at 10:08
7

Personally, I think that you should just get into the habit of typing \[ and \] as quickly as possible and I think that you'll find that you soon develop the right "muscle memory" that it becomes as fast as typing $$.

But if you want to do a one shot conversion, then I have a script that might help you. I wrote it a while ago, probably when I was in a similar circumstance (the details are hazy in my memory) and wanted to convert my old files. I still use it when I get sent something by a collaborator or student that uses $$.

You can find it from my website, at https://github.com/loopspace/debuck

(The name is from the American word "buck" for "dollar".)

4

No it is not possible to redefine them the way you want. However, if you write your maths correctly you can use either of them without any problem. Consider this code:

\documentclass{article}
\begin{document}
\fbox{
\begin{minipage}{5cm}
This is a test
$$ \sum_{i=1}^{10} t_i $$
and
$$ \sum_{i=1}^{10} t_i $$
and another
\end{minipage}}
\fbox{
\begin{minipage}{5cm}
This is a test
\[ \sum_{i=1}^{10} t_i \]
and
\[ \sum_{i=1}^{10} t_i \]
and another
\end{minipage}}

%% This will make a slightly different layout
\fbox{
\begin{minipage}[t]{5cm}
This is a test
$$ \sum_{i=1}^{10} t_i $$

and

$$ \sum_{i=1}^{10} t_i $$
and another
\end{minipage}}
\fbox{
\begin{minipage}[t]{5cm}
This is a test
\[ \sum_{i=1}^{10} t_i \]

and

\[ \sum_{i=1}^{10} t_i \]
and another
\end{minipage}}

\fbox{
\begin{minipage}{5cm}
This is a test \math x=y+5 \endmath\  and \ldots

This is a test $ x=y+5$ and \ldots

This is a test \( x=y+5 \) and \ldots
\end{minipage}}
\end{document}

The first two boxes are identical, as they have been written correctly as a single paragraph. The second one the LaTeX way, as you observed in your question is a bit "loose". If you are aware of these differences you can use $$ without any issues. For inline math I always use $ and so far it hasn't caused the universe to collapse into a black hole!

Caveat: If you use any maths packages or amsmath you will be well advised to rather stay with \[..\], although for the example above just using usepackage{amsmath} will provide consistent results for both cases, but will fail if you use the option fleqn. See also Is $ ... $ okay to use, while $$ ... $$ is not recommended? and Why is \[ ... \] preferable to $$ ... $$?.

5
  • Every guide I've seen has said to avoid $$...$$ due to a variety of issues, yet $...$ doesn't seem to be mentioned as much. ctan.org/pkg/l2tabu-english for example. Are you going to break packages like the AMS ones by using the plain-tex math mode?
    – Canageek
    Commented Oct 6, 2011 at 2:13
  • @Canageek You cannot break a package by using it, but you run the risk of inconsistent spacing. In my first example everything is one paragraph and hence there are no issues.
    – yannisl
    Commented Oct 6, 2011 at 2:21
  • 5
    @Canageek: You will certainly break parts of of amsmath like fleqn. You will also probably break some packages that modify math-mode layout (like breqn). \qedhere in equations will also stop working correctly. So I guess you should only use $$ if you really know what you are doing.
    – Caramdir
    Commented Oct 6, 2011 at 2:22
  • 1
    @Yiannis: You might not break it in the sense that it stops compiling, but you will lose some features.
    – Caramdir
    Commented Oct 6, 2011 at 2:24
  • @Caramdir just added a caveat in the answer to cover some of the points you raised.
    – yannisl
    Commented Oct 6, 2011 at 3:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .