I have a problem with brackets in enviroment "lem", which is defined in preamble. If you compile my MWE you get: "Lem 1 (Yoneda, 1996)", but I want: "Lem 1 [Yoneda, 1996]". How can I reach this?
I google about this problem, but I didn't find the answer.
\documentclass{article}
%\usepackage[T2A]{fontenc}
%\usepackage[cp1251]{inputenc}
%\usepackage[english]{babel}
\newtheorem{lem}{Lem}
\begin{document}
\begin{lem}[Yoneda, 1996]
Let $F$ be a functor from a locally small category ${\mathcal C}$ to
$\mathbf{Set}$. Then for each object $A$ of $\mathcal{C}$, the
natural transformations $\mathrm{Nat}(h_{A},F) = \mathrm{Hom}
(\mathrm{Hom}(A,-),F)$ from $h_{A}$ to $F$ are in one-to-one
correspondence with the elements of $F(A)$. That is,
$\mathrm{Nat}(h_{A},F) \cong F(A)$. Moreover, this isomorphism is
natural in $A$ and $F$ when both sides are regarded as functors from
${\mathcal{C}} \times \mathbf{Set}^{\mathcal {C}}$ to
$\mathbf{Set}$.
\end{lem}
\end{document}
There are a number of ways to achieve this. One primitive way is to update the internal command setting theorems for which an optional argument is provided - \#opargbegintheorem:
\documentclass{article}
\newtheorem{lem}{Lem}
\makeatletter
\renewcommand{\#opargbegintheorem}[3]{%
\trivlist
\item[\hskip\labelsep {\bfseries #1\ #2\ [#3]}]\itshape}% Changed (#3) to [#3]
\makeatother
\begin{document}
\begin{lem}[Yoneda, 1996]
Let\/~$F$ be a functor from a locally small category\/~$\mathcal{C}$ to\/~$\mathbf{Set}$. Then for each object\/~$A$ of\/~$\mathcal{C}$, the
natural transformations\/ $\mathrm{Nat}(h_A, F) = \mathrm{Hom}(\mathrm{Hom}(A, -), F)$ from\/~$h_A$ to\/~$F$ are in one-to-one
correspondence with the elements of\/~$F(A)$. That is,\/ $\mathrm{Nat}(h_A, F) \cong F(A)$. Moreover, this isomorphism is
natural in\/~$A$ and\/~$F$ when both sides are regarded as functors from\/~$\mathcal{C} \times \mathbf{Set}^{\mathcal{C}}$ to\/~$\mathbf{Set}$.
\end{lem}
\end{document}
This will, of course, have a global effect for all theorem-like structures defined via \newtheorem. However, such consistency is often a good thing.
A more adaptable change is shown here using amsthm (can also be used in conjunction with thmtools).
Related
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}
I have a two part question regarding the use of LaTeX in Rmarkdown:
1) When working in Rmarkdown (with the intent to render to PDF), is there a rule for when we should just use the double dollar signs ($$) to write something in LaTeX or when we should use the LaTeX syntax to begin and end all of our LaTeX code (e.g. \documentclass{...}, \begin{document}, \end{document}, etc.
I believe I have read that it is okay to just use the latter option, and Rmarkdown will ignore all of the escaped latex commands if the document is rendered to anything other than PDF.
2) The reason I am asking, in this case, is that I am trying to incorporate some labelled matrix multiplication in an Rmarkdown document I am writing. Specifically, I would like to include some matrices that take the form show on this page. Here is the code:
\documentclass{article}
\usepackage{amsmath}
\newenvironment{spmatrix}[1]
{\def\mysubscript{#1}\mathop\bgroup\begin{pmatrix}}
{\end{pmatrix}\egroup_{\textstyle\mathstrut\mysubscript}}
\begin{document}
\begin{equation}
\begin{spmatrix}{A}
a & b \\
c & d
\end{spmatrix}
\begin{spmatrix}{x}
x_1 \\
x_2
\end{spmatrix}
=
\begin{spmatrix}{b}
b_1 \\
b_2
\end{spmatrix}
\end{equation}
\end{document}
How would one implement this code in Rmarkdown? Do you need to move the \usepackage call into the YAML as suggested in other threads discussing the loading of LaTeX packages in Rmarkdown? Is the first line, \documentclass{article} even needed within an Rmarkdown document?
I'm new to all of this, and thusfar, I've been able to get by using the double dollar signs to set off all my LaTeX code for simple equations and even a simple matrix here and there that I've tried to write, but for mathematical expressions that require more formatting, aligning, multi-line proofs, etc., most of the examples I've encountered are on the TEX boards written with syntax similar to the code above. I haven't been able to figure out how to implement these types of examples in Rmarkdown. Any helpful suggestions or pointers where to better understand this issue would be much appreciated!
It is indeed possible to put most body-level LaTeX constructs into the body of your Rmd file. Other backends will ignore these constructs, but the result might look change. So from my point of view your are binding yourself to PDF output. But that might be fine in your case.
Concerning your concrete problem:
amsmath is already included by the default template, which also takes care of \ḑocumentclass and the document environment.
You need to add the environment definition into a separate tex file (in my case preamble.tex) and include that file via the YAML headers.
You can then use the LaTeX constructs as is in the Rmd body.
Putting things together:
---
output:
pdf_document:
keep_tex: yes
includes:
in_header: preamble.tex
---
\begin{equation}
\begin{spmatrix}{A}
a & b \\
c & d
\end{spmatrix}
\begin{spmatrix}{x}
x_1 \\
x_2
\end{spmatrix}
=
\begin{spmatrix}{b}
b_1 \\
b_2
\end{spmatrix}
\end{equation}
What I'm trying to do: I have a page that consists of pairs of two sentences each. The pairs are separated by a whole line break. My problem is that when I have an odd number of pairs, the second sentence will automatically be placed on the next column.
How can I use LaTeX to make block structures that multicol does not ignore, to keep the two sentences together? If there's better code to solve this problem, or a better column implementation (though I don't believe I can use \twocolumn in the document declaration), please post it.
My current code:
\documentclass{article}
\usepackage{fullpage}
\usepackage{multicol}
\setlength{\parindent}{0pt}
\setlength{\parskip}{\baselineskip}
\newcommand{\pair}[2]{
\emph{#1}\\*
#2
}
\begin{document}
\begin{multicols}{2}
\pair{Sentence 1.}{Sentence 2.}
\pair{Sentence 2 (pair 2).}{Sentence 2 (pair 2).}
\pair{The last pair, first sentence.}{Last sentence.}
\end{multicols}
\end{document}
This generates: http://img541.imageshack.us/img541/3444/columns.png . The second pair is what I am trying to avoid.
Try this:
\newcommand{\pair}[2]{%
\parbox{\hsize}{\emph{#1}\\*#2}\par}
I have a 3x12 matrix I'd like to input into my LaTeX (with amsmath) document but LaTeX seems to choke when the matrix gets larger than 3x10:
\begin{equation}
\textbf{e} =
\begin{bmatrix}
1&1&1&1&0&0&0&0&-1&-1&-1&-1\\
1&-1&0&0&1&1&-1&-1&0&0&1&-1\\
0&0&1&-1&1&-1&1&-1&1&-1&0&0
\end{bmatrix}
\end{equation}
The error: Extra alignment tab has been changed to \cr. tells me that I have more & than the bmatrix environment can handle. Is there a proper way to handle this? It also seems that the alignment for 1's and the -1's are different, is that also expected of the bmatrix?
From the amsmath documentation (texdoc amsmath):
The amsmath package provides some
environments for matrices beyond the
basic array environment of LATEX. The
pmatrix, bmatrix, Bmatrix, vmatrix and
Vmatrix have (respectively) ( ), [
], { }, | |, and ∥
∥ delimiters built in. For naming
consistency there is a matrix
environment sans delimiters. This is
not entirely redundant with the array
environment; the matrix environments
all use more economical horizontal
spacing than the rather prodigal
spacing of the array environment.
Also, unlike the array environment,
you don’t have to give column
specifications for any of the matrix
environments; by default you can have
up to 10 centered columns. (If you
need left or right alignment in a
column or other special formats you
must resort to array.)
i.e. bmatrix defaults to a 10 column maximum.
A footnote adds
More precisely: The maximum number of
columns in a matrix is determined by
the counter MaxMatrixCols (normal
value = 10), which you can change if
necessary using LATEX’s \setcounter or
\addtocounter commands.
If you came to this page looking for the exact command (thanks to Scott Wales for the answer), you want this in your preamble:
\setcounter{MaxMatrixCols}{20}
Where you can replace 20 with the maximum number of columns you want.
The answer by Scott is correct, but I've since learned you can override the alignment. Taken from http://texblog.net/latex-archive/maths/matrix-align-left-right/
\makeatletter
\renewcommand*\env#matrix[1][c]{\hskip -\arraycolsep
\let\#ifnextchar\new#ifnextchar
\array{*\c#MaxMatrixCols #1}}
\makeatother
Now allows the command:
\begin{bmatrix}[r] ....
to have right-alignment!
Instead of a bmatrix you can use +bmatrix from the tabularray package:
\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{amsmath}
\begin{document}
\begin{equation}
\textbf{e} =
\begin{+bmatrix}
1&1&1&1&0&0&0&0&-1&-1&-1&-1\\
1&-1&0&0&1&1&-1&-1&0&0&1&-1\\
0&0&1&-1&1&-1&1&-1&1&-1&0&0
\end{+bmatrix}
\end{equation}
\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: