Implicit linebreaks in LaTeX equations - latex

I wonder if there is any way to invert the way the LaTeX interprets linebreaks in equations? E.g., I dont want to insert them explicitly like,
\begin{gather}
x = y \\
a = c
\end{gather}
, but implicitly like,
\begin{gather}
x = y
a = c
\end{gather}
Thanks.

This is against the intention of TeX’s author, who believed that math must be typeset by hand. I tried obeylines, but to no avail. I guess it’s possible by making new line active, but you should ask the cracks over at Stack Exchange, a branch of Stack Overflow for TeX and LaTeX.

The breqn package will automatically insert linebreaks in equations when the line is full. I don't know of anything that will do break as you ask. If it is a big deal you could use perltex to define a macro that would do it for you. I will try to mock one up as an example.

Related

Can I get LaTeX output with explicitly printed multiplication signs in Math.NET?

I'm using SymbolicExpression.ToLaTeX to generate LaTeX output based on my expression.
Is it possible to add some option to get it to print the following:
Instead of:
No, this was not supported. However, I've addressed this just now, so starting from the next release (newer than 0.21) this will be formatted as:
\mathrm{height} \cdot \mathrm{weight}
Use \cdot
\usepackage{amsmath}
(...)
height $\cdot$ weight
and if you really want to put the words in math mode too, I'd recommend the following:
$$\textrm{height} \cdot \textrm{weight}$$
where \textrm makes text looks 'normal' (or \textit for italics)
Tip for symbol
If you don't know how to get a specific symbol in Tex, you can draw it in Detexify and it gives you the best matches (and tells in which packages they're defined): https://detexify.kirelabs.org/classify.html. For instance:

Multiset notation in LaTeX

Does anyone know how to make (nice looking) double bracket multiset notation in LaTeX, i.e something like (\binom{n}{k}) where there are two outer brackets instead of 1 as in binomial? You can see an example of what I mean in http://en.wikipedia.org/wiki/Multiset under the heading "Multiset coefficients" with the double brackets.
In Wikipedia they typeset it as:
\left(\!\!{n\choose k}\!\!\right)
but although this works well for LaTeX in maths mode, with inline equations the outer bracket becomes much larger than the inner bracket.
I have also tried using
\genfrac{((}{))}{0pt}{}{n}{k}
but it has an error with the double brackets.
I am using \binom as well in my document, so I would like the bracket sizes to be similar for \binom and \multiset.
You can explicitly specify the size of the brackets via
\big( \Big( \bigg( or \Bigg(
Then use \! for negative space to get the brackets closer to each other.
One can use the e-TeX \middle command as follows:
\newcommand{\multibinom}[2]{
\left(\!\middle(\genfrac{}{}{0pt}{}{#1}{#2}\middle)\!\right)
}
This assumes that you are using the AMSmath package. If not, replace \genfrac with the appropriate construct using \atop.
(Of course this is a hack: the proper solution would be scalable glyphs for the doubled parenthesis, but I can't find any fonts that provide it.)
I'm surprised it wasn't googlable either, so I'll provide a solution here for posterity's sake.
It is also possible to define two different new commands, using \tbinom and \dbinom (section 4.11.2 of the User's Guide for the amsmath Package):
\documentclass{article}
\usepackage{amsmath}
\newcommand{\inlinebnm}[2]{\ensuremath{\big(\!\tbinom{#1}{#2}\!\big)}}
\newcommand{\displybnm}[2]{\bigg(\!\!\dbinom{#1}{#2}\!\!\bigg)}
\begin{document}
Text $\inlinebnm{a}{b}$ text. %% inline
Text \inlinebnm{a}{b} text. %% inline (also ok thanks to ensuremath)
\[
\displybnm{a}{b} %% display-style
\]
\end{document}

braces for Math in LaTeX

Is there any convenient way to type in braces in Math in Latex?
Especially when I have already typed in a lot of "(" and ")" instead of "\left(" and "\right)", how can I do a quick replacement? similarly for "{" and "}" and "[" and "]"?
Is it important to make such changes? I am writing a thesis.
Thanks and regards!
BTW: I mainly edit latex file in Texmaker and I know how to use emacs. If there is other editor that can do such replacement in a quick way, please let me know.
EDIT:
If there is nothing taking more than one line height inside the braces, is there any difference in their appearances between using \left and \right and not using? Is it still necessary to use \left and \right ?
The point of the \left( \right) syntax is to have brackets automatically resize to fit their content.
A search/replace is a simple way to correct your brackets (M-% ( RET \left( RET in emacs for example, which will let you check each occurrence), or your editing environment might have a quick way to type them.
Assuming that you don't want to replace ('s with \left('s in your source files, you can try this hack:
\def\oparen{\left(} \def\cparen{\left)}
{\catcode`\(=\active \gdef({\oparen} \catcode`\)=\active \gdef){\cparen}}
\everymath={\catcode`\(=\active \catcode`\)=\active}
But this will probably break some of the macros using parentheses.
The same trick possible with {/} (use with extreme care!) and [/].

LaTeX: How to adjust how the Sum symbol turns out

Not sure if LaTeX counts as programming, or if my question even makes sense, but I have this LaTeX expression (or what you call it):
\sum_{k=1}^n k^2 = 1+4+9+\ldots +n^2 =
\frac{1}{3}n^3 + \frac{1}{2}n^2 + \frac{1}{6}n
The problem is that the k=1 and n comes next to, i.e. after, the sum symbol, instead of above and below it. Is there a way I can change this? I have tried to show visually what I mean below. The sum symbol represented as Xs :
n
XXX XXX n
XXX vs XXX
XXX XXX k=1
k=1
I want the first kind, but am getting the second.
Try
\sum\limits_{k=1}^n k^2
if you want the sum limits to appear above and below the sum sign in an inline equation.
A more general solution to force a formula that is appearing in inline style to appear in display style is to start the formula with a \displaystyle declaration, e.g.
$\displaystyle \sum_{k=1}^n k^2$
This will work for any expression that appears differently in inline and display environments, such as \frac, \int, \lim, etc. You can also control the scope of the \displaystyle command by enclosing the desired expression in braces. For example, if you want the sum in your example formula to appear in display style but not the fractions, you could use
${\displaystyle \sum_{k=1}^n k^2} = 1+4+9+\ldots +n^2 =
\frac{1}{3}n^3 + \frac{1}{2}n^2 + \frac{1}{6}n$
I think you will need to use the equation environment for that:
\begin{equation}
\sum_{k=1}^n k^2 = 1+4+9+\ldots +n^2 = \frac{1}{3}n^3 + \frac{1}{2}n^2 + \frac{1}{6}n
\end{equation}

aligning equations in latex

I have the following code in an attempt to align things in latex using amsmath package:
\begin{alignat}{3}
\text{max} && c^Tx &=\\
\text{s.t.} && Ax &\leq b \\
&& x &\geq 0
\end{alignat}
Basically, i would like for max and s.t. to be in one column, c^Tx, Ax, x to be in second column, and lastly b and 0 to be in the last column. I'm not sure why it doesn't work (it clumps max and c^Tx together for some reason.
if anyone can help me out with this it would be much appreciated!
With math-mode \text{} you should put in some explicit whitespace such as \quad. But max smells like a log-like symbol so you should be using pre-defined \max or self-defined \operatorname{max} instead of \text{max}.
Additionally, the parameter for the alignat environment should be 2 in this case. The param is the number of alignment structures and can be calculated by solving n from a=2n-1 where a is the number of ampersands on a row. However, it doesn't seem to have a difference in this case.
I believe what's happening here is that max and s.t. are being right-aligned, which is running them right up next to c^Tx and Ax. If you just add some whitespace to the right-hand-side of max and s.t., you should be in business.
(Also, laalto is right, you should definitely use \operatorname{max} if max is some sort of operator or function. Though I'm not really sure what you're doing, so maybe it isn't.)

Resources