IOS - Need to display Latex format text? - ios

I have the following text containing latex commands.
Simplify.
3 \(\dfrac{1}{2} + \biggr[4 + \biggl\{\dfrac{1}{2} \div \biggl(3\dfrac{1}{2} - \dfrac{1}{2} \biggl) \biggl\} \biggr] \times 1\dfrac{1}{2} \)
I have already tried using iosMath but it does not wrap the whole text in my view. I'm told iosMath does not support new line character(\n), is there a way around this?

Try using \\ as the newline character in your syntax.
Also,
bigr and bigl are not supported in iosMath.
When specifying the string in Objective-C, you will need to use two back slash, instead of one. \\ instead of \.
\dfrac will be just \frac.
Take a look at the examples given here.
You can use this tool to try out syntax quickly in browser.
Finally, here is what worked for me:
3 (\frac{1}{2} \\ + [4 + [{\frac{1}{2} \div (3\frac{1}{2} \ - \frac{1}{2} ) ]}] \\ \times 1\frac{1}{2} )

Related

Mixing text and equations in latex

I am working on some algorithm documenation for a project and trying to write out the equations in latex.
The one problem I am encountering and have not found a nice way (assuming there is one) is mixing text and equations in a single line.
Here is an example of what I am doing (and later how I am doing it).
I am defining the equation, and than what each variable means (left aligned text hence the &).
The latex code to generate this
\begin{equation}
A = 3B * 4C + 5D
\end{equation}
Where:
\begin{flalign*}
&A = Something \: cool\\
&B = Something \: cooler\\
&C = Something \: even \: cooler!!\\
\end{flalign*}
My questions are:
Is there a better way to do spaces in between words besides putting \: everywhere?
If I dont put the \: I get this below, all the words are combined?
Is this the most latex idiomatic way to acheive this? Am I missing something that could help me?
So I can get the output the way I want, I just want to make sure its "correct" before I get to deep.
You should never set whole words in math mode. Besides the obvious problem with spaces you noticed, this will also completely mess up the kerning between the letters.
Instead you can use the \text{...} macro from the amsmath package.
The amsmath package also provides the \intertext macro, which you could use to insert Where: while retaining alignment of the equal signs in the equations above and below:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{flalign}
A &= 3B \cdot 4C + 5D\\
\intertext{Where:}
A &= \text{Something cool}\notag\\
B &= \text{Something cooler}\notag\\
C &= \text{Something even cooler!!}\notag
\end{flalign}
\end{document}

How to align multiple equations in Marp (a tool to convert .md files into PDF)?

I've been trying to find a solution to align multiple equations in Marp (a tool to convert .md files into PDF) but can't find a solution.
I tried using \begin{equation}......\end{equation}(which apparently is not supported in Marp), and various combinations of $....$, $$....$$
but can't find a hack.
I'm trying to generate something like :
but instead I get this:
here is my code:
$$ E_{\theta}[\theta] = \int_{\theta}\theta\ p(\theta)\ d\theta $$
$$ E_D[E_{\theta}[\theta|D]] = \int_D\Bigg\{\int_{\theta}\theta\ p(\theta|D)\ d\theta \Bigg\}\ p(D)\ dD $$
What am I missing. There is a solution for R Markdown, but I'm not sure if Marp supports R Markdown. I also can't find a way to import packages in Marp too.
Please help. Thanks.
Put $$ at the start and end of the equations - but not after each each equation.
Then separate each equation with \\.
Put an & before each equals (where you want it to align)
Use the \begin{aligned} and \end{aligned} function.
Here is a simple example:
$$\begin{aligned} 1 + 2 + 3 + 4 &= 10 \\
20 \times 80 &= 1600 \end{aligned}$$
Here is your example in this format:
$$\begin{aligned}E_{\theta}[\theta] &= \int_{\theta}\theta\ p(\theta)\ d\theta \\
E_D[E_{\theta}[\theta|D]] &= \int_D\Bigg\{\int_{\theta}\theta\ p(\theta|D)\ d\theta \Bigg\}\ p(D)\ dD \end{aligned}$$
These these examples when rendered:
math-alignement-results

Typesetting the numbered mathematical formula in latex

How to typeset the following numbered mathematical formula:
Use amsmath's cases environment:
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\[
\Delta(x) = \begin{cases}
1 & \text{if $x > 0$} \\
-1 & \text{if $x < 0$} \\
0 & \text{otherwise}
\end{cases}
\]
\end{document}
Here is one way to do it:
$
\Delta(x)=
\left\{
\begin{matrix}
1 & \mathrm{if}~x>0 \\
-1 & \mathrm{if}~x<0 \\
0 & \mathrm{otherwise}
\end{matrix}
\right.
$
Which produces the equation you wanted like this:
The example LaTeX equation
This type of equation has a few key tricks in it:
The left bracket has to be declared as \{ in order for LaTeX to
know to display it since it is a special character
Also, the left brace has to be resized to match however many rows you include in your equation, which is done by the \left command preceding it. This can also be done for (, [, etc.
Since you have a \left command, it has to be accompanied by a \right}, but you don't want to display the right brace, so the \right. ends the section without displaying the right brace.
The \mathrm command turns the text inside it back to normal text (removing the math mode temporarily) so that your "if" and "otherwise" aren't italicized.
The ~ just adds a little space so that your "if" doesn't collide with the x > 0, which often happens when using mathrm
Alternatively, you can check out this post for other ways to write piecewise functions in LaTeX. I hope this helps.

aligning math equations in Latex

I am trying to align the following equations around the equal sign. What can I do? Thanks! I am using the AMSMath package
$$m\ddot{x}_{1}-K(x_{2}+x_{12})+C(\dot{x}_{12}+\dot{x}_{2})+2C\dot{x}_{1} = fx_{1}$$
$$m\ddot{x}_{2}-K(x_{3}+x_{1})+C(\dot{x}_{1}+\dot{x}_{3})+2C\dot{x}_{2} = fx_{2}$$
$$m\ddot{x}_{3}-K(x_{4}+x_{2})+C(\dot{x}_{2}+\dot{x}_{4})+2C\dot{x}_{3} = fx_{3}$$
\begin{align}
m\ddot{x}_{1}-K(x_{2}+x_{12})+C(\dot{x}_{12}+\dot{x}_{2})+2C\dot{x}_{1} &= fx_{1} \\
m\ddot{x}_{2}-K(x_{3}+x_{1})+C(\dot{x}_{1}+\dot{x}_{3})+2C\dot{x}_{2} &= fx_{2} \\
m\ddot{x}_{3}-K(x_{4}+x_{2})+C(\dot{x}_{2}+\dot{x}_{4})+2C\dot{x}_{3} &= fx_{3}
\end{align}
See the user's guide.
To make a long story short... the following idea of using eqnarray is kind of obvious, but turns out to be a really bad idea. eqnarray brings lots of issues which are solved in amsmath and related packages. Read Lars Madsen: Avoid eqnarray for the details.
\begin{eqnarray*} %% Do avoid eqnarray if possible.
x_1 & = & 1 \\
x_2 & = & 2 \\
x_3 & = & 3
\end{eqnarray*}
(Answer revised with information from Arthur Reutenauer, Thomas and the Madsen paper linked to by Thomas.)
There are several packages to do what you want, one of the most widely used is the AMS' align environment from the amsmath package.
Simplified extract from amsldoc.pdf:
\begin{align}
x&=y \\
x’&=y’ \\
x+x’&=y+y’
\end{align}
The equations are aligned around the symbols that follow & (the equals signs, in this case).

Collapsible minibox environment in LaTeX

I'm trying to learn LaTeX, currently because otherwise, my professors will be nearly unable to read my homework assignments. I've come across something I want to do, but don't seem to be able to, ie. I have searched google (possibly with a poor keyword set) and not found a solution.
The specific case is as follows: I want to put an ams flalign environment inside a box and have multiple such environments side by side. I have achieved this using minipage, but minipage asks for a width. I would like to use the smallest width in which the flalign environment fits. I realize that I can set the width to 0pt, but I can't help wondering if there's something that is intended to do this.
Also, should I be using minipage? Is there another command I don't know?
Thanks for your reply.
EDIT:
An attempted clarification as to what I want to do. I want equations which are standard, known, given, etc. and short on the left. To the right of those, I want relevant derived equations (and maybe their derivations. Further right, I want actual calculations plugged in.
I feel like what I want is a tabular environment with 3 columns, but I don't think I can put an equation environment in a tabular environment.
This looks like what I want when I render it.
\begin{minipage}[t]{0pt}
\begin{flalign*}
\sigma & = F / A&\\
A & = \pi \left(d/2\right)^2&\\
\epsilon &= \frac{\sigma}{E}&\\
\epsilon_{trans} &= - \nu \epsilon_{longi}& \\
\epsilon &= \frac{\Delta l}{l}&\\
l &= \left( \epsilon + 1 \right) \times l_0&
\end{flalign*}
\end{minipage}
\hspace*{0pt}
\begin{minipage}[t]{0pt}
\begin{flalign*}
d & = \unit[1.8]{mm} = \unit[1.8\e{-3}]{m} &\\
F_T & = \unit[1300]{N}&\\
E_{\text{stainless steel}}&=\unit[193\e9]{Pa}&\\
l_0 & = \unit[.2530]{m}&\\
\nu & = .33&\\
\sigma &= \frac{\unit[1300]{N}}{\pi \times \unit[3.24\e{-6}]{m^2}}&&= \boxed{\unit[127.7\e6]{Pa}}\\
&&&=\boxed{\unit[18,524]{psi}}\\
\epsilon &= \frac{\unit[127.7\e6]{Pa}}{\unit[193\e9]{Pa}} &&= \boxed{6.6\e{-2}}\\
\epsilon_{trans} &= -.33 \times 6.6\e{-2} &&=\boxed{-2.2\e{-2}}\\
l &= \left( 6.6\e{-2} + 1 \right) \times \unit[.2530]{m} &&= \boxed{\unit[.2797]{m}}
\end{flalign*}
\end{minipage}
I'm not sure exactly what you're trying to achieve, but amsmath's align* environment might do what you want (without resorting to minipages):
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{align*}
x&=y & X&=Y & a&=b+c & mn&=ab\\
x’&=y’ & X’&=Y’ & a’&=b & m'n'&=a'b'\\
x+x’&=y+y’ & X+X’&=Y+Y’ & a’b&=c’b & m'&=a'
\end{align*}
\end{document}
As to your minipage question: it requires a width because TeX needs to know where to break the lines. If you don't want the line-breaking algorithm to be used, you probably don't want a minipage.
Edit:
If you want multiple columns and don't care about the vertical alignment of material across the columns, that can be obtained easily enough with the multicols package:
\documentclass{article}
\usepackage{multicols}
\usepackage{lipsum}% just for some example text
\begin{document}
% The * version allows the columns to have ragged bottoms.
% The argument 2 is the number of columns.
\begin{multicols*}{2}
\lipsum[1]% one paragraph of Lorem ipsum.. filler text
\vfil% fills the remainder of the column with white space
\columnbreak% force a column break
\lipsum[2]% another paragraph of text
\vfil% fills the remainder of the column with white space
\end{multicols*}
\end{document}
You might find something to help you in the empheq and mathtools packages. empheq allows you to box equations and mathtools should provide some useful environments for stacking them horizontally.

Resources