Subtract integer from floats and integers in \foreach loop - (pdf)Latex [Overleaf] - latex

I would like to subtract the integer 1 from the names of the files I have included in the for loop. Although this works for the integer values, the float doesn't decrease by one, but rather shows '63.1-1' for example. Would like help with this. Thank you!
I have tried using the math operator, using '\the\numexpr\x-1\relax'. The former didn't work for both floats and integers, while the later only worked for integers. You can find my code here:
\usepackage{graphicx, pgffor}
\foreach \x in {59, 60.1, 60.2, 62, 63.1, 63.2, 65, 66.1, 66.2, 67.1}{%
\parbox{.4\textwidth}{\centering\includegraphics[width=\linewidth]{Figures/Graphs/Picture\x.png}\par \tiny Slide \the\numexpr\x-1\relax}\space%
}%

Tikz or PGF does not evaluate numbers. Use evaluate as directive inside foreach with an additional variable. As to the \numexpr, it only works with integers.
\documentclass[12pt, a4paper]{article}
\usepackage{graphicx,pgffor}
\begin{document}
\noindent
\foreach \x [evaluate=\x as \y using {\x-1}]
in {59, 60.1, 60.2, 62, 63.1, 63.2, 65, 66.1, 66.2, 67.1}{%
\parbox{.4\textwidth}{%
\centering
\includegraphics[width=\linewidth]{example-image-duck}
\par\small Slide \y}\space}
\end{document}
Edit. You can also work out the number using \pgfmathparse{}\pgfmathresult combo. The last line would be:
\par\small Slide \pgfmathparse{\x-1}\pgfmathresult}\space}

Related

Using numbers as input in \newenvironment 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}

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.

How can I calculate with optional parameter in \newcommand block?

I want to have a grid-command which is adjustable to the wanted height. Here is what I did:
\newcommand{\vhlines}[1]{
\hspace{1em}
\setlength{\unitlength}{0.75cm}
\begin{picture}(22,#1)
\color{lightgray}
\linethickness{0.075mm}
\multiput(0,0)(1,0){21}
{\line(0,1){#1}} % need to subtract 1 from #1
\multiput(0,0)(0,1){#1}
{\line(1,0){20}}
\end{picture}
}
If I call, e.g., \vhlines{16} I find the vertical lines to be too long on the upper end. They are correct if I write a 15 instead of the #1 in the line with the comment.
Is there an elegant way to do this?
You can perform elementary numeric (integer) expressions using \numexpr:
\documentclass{article}
\usepackage{xcolor}
\newcommand{\vhlines}[1]{%
\hspace{1em}%
\setlength{\unitlength}{0.75cm}%
\begin{picture}(22,#1)
\color{lightgray}
\linethickness{0.075mm}
\multiput(0,0)(1,0){21}
{\line(0,1){\numexpr#1-1}}
\multiput(0,0)(0,1){#1}
{\line(1,0){20}}
\end{picture}
}
\begin{document}
\noindent
\vhlines{4}
\end{document}
Alternatively, for more complex expressions, add to your preamble
\usepackage{xparse}
\ExplSyntaxOn
\cs_new_eq:NN \calc \fp_eval:n
\ExplSyntaxOff
which would allow you to use \calc{<your numerical expression>}.

Two statements next to curly brace in an equation

How can I write an equation with one curly brace ({), and on the right-hand side next to the curly, two statements in two different lines?
You can try the cases env in amsmath.
\documentclass{article}
\usepackage{amsmath}
\begin{document}
\begin{equation}
f(x)=\begin{cases}
1, & \text{if $x<0$}.\\
0, & \text{otherwise}.
\end{cases}
\end{equation}
\end{document}
That can be achieve in plain LaTeX without any specific package.
\documentclass{article}
\begin{document}
This is your only binary choices
\begin{math}
\left\{
\begin{array}{l}
0\\
1
\end{array}
\right.
\end{math}
\end{document}
This code produces something which looks what you seems to need.
The same example as in the #Tombart can be obtained with similar code.
\documentclass{article}
\begin{document}
\begin{math}
f(x)=\left\{
\begin{array}{ll}
1, & \mbox{if $x<0$}.\\
0, & \mbox{otherwise}.
\end{array}
\right.
\end{math}
\end{document}
This code produces very similar results.
Are you looking for
\begin{cases}
math text
\end{cases}
It wasn't very clear from the description. But may be this is what you are looking for http://en.wikipedia.org/wiki/Help:Displaying_a_formula#Continuation_and_cases
To answer also to the comment by #MLT, there is an alternative to the standard cases environment, not too sophisticated really, with both lines numbered. This code:
\documentclass{article}
\usepackage{amsmath}
\usepackage{cases}
\begin{document}
\begin{numcases}{f(x)=}
1, & if $x<0$\\
0, & otherwise
\end{numcases}
\end{document}
produces
Notice that here, math must be delimited by \(...\) or $...$, at least on the right of & in each line (reference).
Or this:
f(x)=\begin{cases}
0, & -\pi\leqslant x <0\\
\pi, & 0 \leqslant x \leqslant +\pi
\end{cases}
Here is a way to manually control the size of brace, if cases or \left\{ doesn't provide suitable brace size you want.
\begin{math}
\biggl\{
\begin{array}{l}
statement1\\
statement2
\end{array}
\end{math}
You can choose among \bigl\{ \Bigl\{ \biggl\{ \Biggl\{ to adjust brace size from the smallest to the largest.
Image of different braces
From left to right: cases \left\{ biggl\{ Bigl\{

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