Using numbers as input in \newenvironment LaTeX - latex

I'm trying to make an environment that builds a column vector, and that takes as input the scale factor of the distancing between the rows:
\newenvironment{VEC}[1]{\begin{Bmatrix}\renewcommand{\arraystretch}{#1}}
{\end{Bmatrix}}
I know that the \newenvironment command accepts as input only strings, so I tried with \value{#1} having no successfull result. Any help would be appreciated.

Nothing to do with newenvironment or arguments, you just need to switch the order:
\documentclass{article}
\usepackage{mathtools}
\newenvironment{VEC}[1]{\renewcommand{\arraystretch}{#1}\begin{Bmatrix}}
{\end{Bmatrix}}
\begin{document}
\[
\begin{VEC}{3}
4\\
6\\
\end{VEC}
\]
\end{document}

Related

LaTex how to edit this equation?

I'm having issues turning this word equation into a LaTex equation. It's coming out looking dodgy, please help!
I added a screen shot of the equation I want, and what I end up getting when I copy and paste into LaTex:
WORD:
LATEX CODE:
\mathrm{=\ }\mathrm{C}_\mathrm{0}\mathrm{[1-}6(Dt)1/2aπ2-3Dta2] + 12(Dt)1/2an = 1∞exp(na(Dt)1/2)
and therefore nothing comes out and LaTex doesn't let me run it.
This is absolutely not a proper LaTeX equation code. I don't know what you know about LaTeX, but you cannot just copy and paste from Word or any software to you LaTex editor. Plus, you need to provide your full code for anyone being able to help you.
Anyway, running this MWE should work :
\documentclass[11pt, a4paper, twoside]{report}
% ===== PACKAGES DECLARATION =====
\usepackage{mathtools} % Replaces amsmaths + more features
\usepackage{amsfonts} % Maths fonts package
% ===== DOCUMENT BODY =====
\begin{document}
\begin{equation} % optional : use the "equation*" environment to remove equation number
% optional : use traditional math font by removing the \mathrm{} command
\mathrm{X = C_0 \left[ 1 - \frac{6(Dt)^{1/2}}{a \pi^2} - \frac{3Dt}{a^2}\right] + \frac{12(Dt)^{1/2}}{a} \sum_{n=1}^\infty \exp\left(\frac{na}{(Dt)^{1/2}} \right)}
% optional : remove auto-sized brackets by removing the \left and \right commands
\end{equation}
\end{document}
As written in the code, you may want to remove the equation number and the big auto-sized brackets (that are more readable in my opinion). Just remove the corresponding commands. Also, you should consider using the "normal" math font and not the roman one that is clearly different from the text and helps the reader to separate equations from inline small expressions you could insert in your document.
One first sketch:
\documentclass{article}
\begin{document}
\[
C_0\left[1-\frac{6(Dt)^{\frac{1}{2}}}{a\pi^2}-\frac{3Dt}{a^2}\right]+%
\frac{12(Dt)^{\frac{1}{2}}}{a}\sum^{\infty}_{n=1}%
\exp\left(\frac{na}{(Dt)^{\frac{1}{2}}}\right)
\]
\end{document}
No packages required. The output:
Than you can tune the math fonts and anything else.

Real operations in LaTex

This is a piece of my code.
\newcommand{\number}{2}
\number + 2
Is there any way that a '4' is written instead a '2+2'? (LaTex does the real operation).
Thanks
There are many possibilities to do calculations in latex. Just one option is pgfmath:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\newcommand{\mynumber}{2}
\pgfmathparse{\mynumber+2}
\pgfmathresult
\end{document}

latex error Missing $ inserted

I'm trying to use LaTeX to write my math notes. But I have some problems.
The error is written:
LaTeX error Missing $ inserted
And it doesn't compile correctly:
\documentclass[french,12pt,a4paper]{article}
\usepackage[french]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{fullpage}
\author{
Alexandre Monterroso\\
Université de Fribourg\\
}
\newtheorem{de}{Définition}[subsection]
\newtheorem{theo}{Théorème}[section]
\newtheorem{prop}[theo]{Proposition}
\begin{document}
\section{Combinatoris}
\subsection{Ordered choices}
\begin{itemize}
\item With repetition
\end{itemize}
\begin{theo}
The number of lists (a_{1}, ..., a_{k}) of k not necessarly distincts objects elements (ie. with repetition) from a set n elements is a^{k} (n, k \epsilon N).
\end{theo}
\end{document}
You need to specify math-related content in math mode. So, use
The number of lists ($a_1, \dots, a_k$) of~$k$ not necessarily dist ...
$...$ initiated and closes in-line math mode, while \[...\] initiates and closes display math mode.

Adding an equation or formula to a figure caption in LaTeX

I have a figure in LaTeX with a caption to which I need to add a formula (equation* or displaymath environments). For example:
\documentclass[12pt]{article}
\begin{document}
\begin{figure}[tbph]
\begin{center}
%...
\end{center}
\caption{As you can see
\begin{displaymath}4 \ne 5\end{displaymath}
}
\label{fig:somefig}
\end{figure}
\end{document}
This makes pdflatex angry, though it will produce a PDF.
! Argument of \#caption has an extra }.
<inserted text>
\par
l.9 }
What's the right way to go about adding an equation to a figure caption?
NOTE: Please do not suggest simply using the $ ... $ math environment;
the equation shown is a toy example; my real equation is much more intricate.
See also:
Adding a caption to an equation in LaTeX (the reverse of this question)
Using the package "caption":
\begin{figure}
\begin{center}
...
\captionsetup{singlelinecheck=off}
\caption[.]{
\begin{displaymath}
assoc\_meaning(\lambda x_{SBJ}. followed(x,y) \&actor(x) \nonumber \&actor(y),\lambda x_{SBJ}. maintained(x,\nonumber <(dist\_from(y),1))
\end{displaymath}}
\end{center}
\end{figure}
The square brackets following \caption aren't optional, but leaving them off won't cause an error that looks any different than the one before you added \usepackage{caption} and \captionsetup{...}.
I'm not sure why you do not want to use the $ ... $ solution, because of fractions?
If so, you can use \dfrac instead of \frac.
I would try $ \displaystyle \dfrac{1}{2} \cdot \sum_{i=0}^n i$, i.e. use the \displaystyle command.

Adding a caption to an equation in LaTeX

Well, it seems simple enough, but I can't find a way to add a caption to an equation.
The caption is needed to explain the variables used in the equation, so some kind of table-like structure to keep it all aligned and pretty would be great.
The \caption command is restricted to floats: you will need to place the equation in a figure or table environment (or a new kind of floating environment). For example:
\begin{figure}
\[ E = m c^2 \]
\caption{A famous equation}
\end{figure}
The point of floats is that you let LaTeX determine their placement. If you want to equation to appear in a fixed position, don't use a float. The \captionof command of the caption package can be used to place a caption outside of a floating environment. It is used like this:
\[ E = m c^2 \]
\captionof{figure}{A famous equation}
This will also produce an entry for the \listoffigures, if your document has one.
To align parts of an equation, take a look at the eqnarray environment, or some of the environments of the amsmath package: align, gather, multiline,...
You may want to look at http://tug.ctan.org/tex-archive/macros/latex/contrib/float/ which allows you to define new floats using \newfloat
I say this because captions are usually applied to floats.
Straight ahead equations (those written with $ ... $, $$ ... $$, begin{equation}...) are in-line objects that do not support \caption.
This can be done using the following snippet just before \begin{document}
\usepackage{float}
\usepackage{aliascnt}
\newaliascnt{eqfloat}{equation}
\newfloat{eqfloat}{h}{eqflts}
\floatname{eqfloat}{Equation}
\newcommand*{\ORGeqfloat}{}
\let\ORGeqfloat\eqfloat
\def\eqfloat{%
\let\ORIGINALcaption\caption
\def\caption{%
\addtocounter{equation}{-1}%
\ORIGINALcaption
}%
\ORGeqfloat
}
and when adding an equation use something like
\begin{eqfloat}
\begin{equation}
f( x ) = ax + b
\label{eq:linear}
\end{equation}
\caption{Caption goes here}
\end{eqfloat}
As in this forum post by Gonzalo Medina, a third way may be:
\documentclass{article}
\usepackage{caption}
\DeclareCaptionType{equ}[][]
%\captionsetup[equ]{labelformat=empty}
\begin{document}
Some text
\begin{equ}[!ht]
\begin{equation}
a=b+c
\end{equation}
\caption{Caption of the equation}
\end{equ}
Some other text
\end{document}
More details of the commands used from package caption: here.
A screenshot of the output of the above code:

Resources