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.
Related
In latex, I need to start an item in an enumerate list with an align* environment, but this environment starts with a new line, leaving an ugly empty space.
What I'm trying to achieve:
e^{ix}=cos x+i sin x
e^{i\pi} = -1
e^{i\pi}+1=0
What I'm trying:
\begin{enumerate}
\item \begin{align*}
e^{ix}&=\cos x+i\sin x\\
e^{i\pi}&=-1\\
e^{i\pi}+1&=0
\end{align*}
\end{enumerate}
Is there some other environment for this?
(I know that it is not recommended to start an item with a displayed math formula, but in this case I need to.)
As a workaround:
\documentclass{article}
\usepackage{mathtools}
\begin{document}
\begin{enumerate}
\item \hfill$\begin{aligned}[t]
e^{ix}&=\cos x+i\sin x\\
e^{i\pi}&=-1\\
e^{i\pi}+1&=0
\end{aligned}$\hfill\mbox{}
\end{enumerate}
\end{document}
A hack similar to the one in the accepted answer: the environment matrix needs no package to work and has no visible delimiters:
\documentclass{article}
\begin{document}
\begin{enumerate}
\item $\begin{matrix}
e^{ix}&=\cos x+i\sin x\\
e^{i\pi}&=-1\\
e^{i\pi}+1&=0
\end{matrix}$
\end{enumerate}
\end{document}
The output seems to me similar to the one you wanted to achieve:
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}
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.
I'm pretty new to latex and I'm trying to create a format for exam questions that would make write as few latex as possible.
For the moment I wrote this code:
\documentclass{article}
%the question environment wrapping every exam questions
\newenvironment{q}[2] {
\newcounter{answerCounter} %used for display of answer number with question
\setcounter{answerCounter}{0}
\newcommand{a}[1] {
\item a\value{answerCounter}: ##1
%I used double hyphen on previous line because i'm within an environment
\addtocounter{answerCounter}{1}
}
\item q#1: #2
%the 1st param of q (the environment) is the question number, 2nd is the question itself
\begin{itemize}
} { \end{itemize} }
\begin{document}
\begin{itemize}
\begin{q}{1}{to be or not to be?}
\a{to be}
\a{not to be}
\end{q}
\begin{q}{2}{are you john doe?:}
\a{No i'm Chuck Norris}
\a{maybe}
\a{yes}
\end{q}
\end{itemize}
\end{document}
and I want it to display this:
but when I do pdflatex exam.tex I get the following first 2 errors (there are more but I don't want to flood you with information):
! Missing control sequence inserted.
<inserted text>
\inaccessible
l.21 \begin{q}{1}{to be or not to be?}
?
(/usr/share/texlive/texmf-dist/tex/latex/base/omscmr.fd)
! LaTeX Error: Command \to be unavailable in encoding OT1.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.22 \a{to be}
?
Have i called/defined my environments and commands wrongly? Thanks.
Here are some things to consider:
Environments are defined with a name, as in \newenvironment{someenv}, while commands are defined with their control sequence, as in \newcommand{\somecmd}. Note the \. This is the main problem with your code.
LaTeX defines a number of single-character control sequences, typically used for accents on symbols. After correcting your example for (1) above, \a is already defined. Instead, define something more descriptive to increase code readability.
You may have some spurious spaces inserted as part of your code. These are prevented with strategic placements of %. See What is the use of percent signs (%) at the end of lines?
Defining commands within other commands (like a new counter) could lead to problems, or make things unnecessarily slow (in larger documents and usage). Rather define the counter outside an environment - in the global scope - and then just reset the number as needed.
\documentclass{article}
\newcounter{answerCounter} %used for display of answer number with question
%the question environment wrapping every exam questions
\newenvironment{question}[2] {%
\setcounter{answerCounter}{0}%
\newcommand{\ans}[1]{%
\stepcounter{answerCounter}%
\item a\theanswerCounter: ##1
%I used double hyphen on previous line because i'm within an environment
}
\item q#1: #2
%the 1st param of q (the environment) is the question number, 2nd is the question itself
\begin{itemize}
} { \end{itemize} }
\begin{document}
\begin{itemize}
\begin{question}{1}{To be or not to be?}
\ans{to be}
\ans{not to be}
\end{question}
\begin{question}{2}{Are you John Doe?}
\ans{No I'm Chuck Norris}
\ans{maybe}
\ans{yes}
\end{question}
\end{itemize}
\end{document}
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: