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?

A T
  • 4,093

3 Answers3

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.

N.N.
  • 36,163
  • That is what Textmate does (with $$-tab). I'd accept that answer if I had asked that question :) – topskip Oct 06 '11 at 06: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!) – Federico Poloni Oct 06 '11 at 07:11
  • I use TeXWorks. Is there a feature like this for it? – A T Oct 06 '11 at 15:19
  • @AT Dunno. Maybe that is for another question. – N.N. Oct 06 '11 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 Oct 09 '11 at 10:08
  • @nightowl I've added instructions that works in many snippets managers. It's as simple as adding that instruction and setting it to be activated by a chosen command. – N.N. Oct 09 '11 at 10:31
  • @nightowl How you use snippet managers depends on the editor you use. What editor are you using? – N.N. Oct 10 '11 at 07:13
  • @nightowl I've never used it. On its homepage it says that it supports "LaTeX code snippets" via "Simple insertion of LaTeX constructs via toolbars and menus". Maybe you can define such snippets yourselves? If need help with this it might fit better as a new question rather than as a discussion here. – N.N. Oct 10 '11 at 07:58
  • Okay, Thanks, shall we erase the comments that are of no relevancy to the question? – night owl Oct 10 '11 at 08:01
  • @nightowl Guess we can leave them as is for the moment. Can always flag them as obsolete or similar later on. If you write a question or find an answer for your editor you might want to link it from a comment here so others with the same problem can find it. – N.N. Oct 10 '11 at 08:15
  • See http://tex.stackexchange.com/questions/31084/snippet-manager-in-texniccenter for how to use snippets in TeXnicCenter. – N.N. Oct 10 '11 at 15:05
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".)

Andrew Stacey
  • 153,724
  • 43
  • 389
  • 751
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 $$ ... $$?.

yannisl
  • 117,160
  • Every guide I've seen has said to avoid $$...$$ due to a variety of issues, yet $...$ doesn't seem to be mentioned as much. http://www.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 Oct 06 '11 at 02: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 Oct 06 '11 at 02: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 Oct 06 '11 at 02:22
  • 1
    @Yiannis: You might not break it in the sense that it stops compiling, but you will lose some features. – Caramdir Oct 06 '11 at 02:24
  • @Caramdir just added a caveat in the answer to cover some of the points you raised. – yannisl Oct 06 '11 at 03:17