Difference between revisions of "Public:Writing LaTeX"

m
m (Xy package)
 
(22 intermediate revisions by the same user not shown)
Line 13: Line 13:
Go to ''Edit'' of this page to see how it's done (especially see the top of the text where I define new macros the same way as we would do in the regular LaTeX). Internally it uses MathJax as its LaTeX engine. See this [https://math.meta.stackexchange.com/questions/5020/mathjax-basic-tutorial-and-quick-reference/ mathoveflow thread] for reference.
Go to ''Edit'' of this page to see how it's done (especially see the top of the text where I define new macros the same way as we would do in the regular LaTeX). Internally it uses MathJax as its LaTeX engine. See this [https://math.meta.stackexchange.com/questions/5020/mathjax-basic-tutorial-and-quick-reference/ mathoveflow thread] for reference.


Note that there are minor differences with LaTeX on this Wiki. Inline mathematics is typeset with <code><nowiki>$$...$$</nowiki></code>, <code>\(...\)</code>, and <code>&lt;math&gt;</code> HTML tag. This means that <code><nowiki>$...$</nowiki></code> '''won't work!''' And display style maths is written with <code>\[...\]</code>, <code>\begin{XXX}...\end{XXX}</code>, where <code>XXX</code> can be, for example, <code>align</code>.
Note that there are minor differences with LaTeX on this Wiki. Inline mathematics is typeset with <code>\(...\)</code>, and <code>&lt;math&gt;...&lt;/math&gt;</code> HTML tag. This means that <code><nowiki>$...$</nowiki></code> '''won't work!''' And display style maths is written with <code>\[...\]</code>, <code>\begin{XXX}...\end{XXX}</code>, where <code>XXX</code> can be, for example, <code>align</code>.




See for example this $$\Ek A$$ and <math>\Pk A</math> and also the following:
See for example this \(\Ek A\) and <math>\Pk A</math> and also the following:


\[ \Ek A =\ ... \]
\[ \Ek A =\ ... \]
Line 24: Line 24:
\end{align}
\end{align}


Note that the advantage of <code>\(...\)</code> is that it is also valid LaTeX, so it can be then just copy-pasted into papers, when in rush :-).


== Commutative diagrams ==
== Commutative diagrams ==

Originally we only could use amscd and matrices or arrays to display diagrams. Now, after upgrading MathJax to version 3 we can also use the Xy pic syntax and even form diagrams with diagonal arrows and loops without hacks! These three individual options are demonstrated below.

=== Matrices/arrays ===
For commutative diagrams the simplest option is to just use arrays:
For commutative diagrams the simplest option is to just use arrays:


Line 36: Line 41:
\end{array}\]
\end{array}\]


or like so
\[
\newcommand{\ra}[1]{\kern-1.5ex\xrightarrow{\ \ #1\ \ }\phantom{}\kern-1.5ex}
\newcommand{\ras}[1]{\kern-1.5ex\xrightarrow{\ \ \smash{#1}\ \ }\phantom{}\kern-1.5ex}
\newcommand{\da}[1]{\bigg\downarrow\raise.5ex\rlap{\scriptstyle#1}}
\begin{array}{c}
0 & \ra{f_1} & A & \ra{f_2} & B & \ra{f_3} & C & \ra{f_4} & D & \ra{f_5} & 0 \\
\da{g_1} & & \da{g_2} & & \da{g_3} & & \da{g_4} & & \da{g_5} & & \da{g_6} \\
0 & \ras{h_1} & 0 & \ras{h_2} & E & \ras{h_3} & F & \ras{h_4} & 0 & \ras{h_5} & 0 \\
\end{array}
\]
Complicated diagrams can be made by just stacking arrays/matrices in layers, e.g.
\[
\matrix{
\mathbb C(A)
& \xrightarrow{h_t}
& B \\
{}_{\epsilon^{\mathbb C}} \downarrow
& \matrix{
\nwarrow {}^{\iota_f} & & {}^g \nearrow \\
& \mkern-20mu X \xrightarrow{\quad\phi\quad} Y \mkern-20mu & \\
\swarrow {}_{f} & & {}_{\iota_g} \searrow
}
& \uparrow {}_{\epsilon^{\mathbb D}} \\
A
& \underset{h_b}{\xleftarrow{\quad}}
& \mathbb D(B)
}
\]

=== CD package ===
Another option is to use CD
Another option is to use CD
<math>\require{AMScd}</math>
<math>\require{amscd}</math>
\begin{CD}
\begin{CD}
\mathbb{Z}/p^n\mathbb{Z} @>{\theta_{n+1,\alpha}}>> U_1/U_{n+1}\\
\mathbb{Z}/p^n\mathbb{Z} @>{\theta_{n+1,\alpha}}>> U_1/U_{n+1}\\
Line 43: Line 79:
\mathbb{Z}/p^{n-1}\mathbb{Z} @>{\theta_{n,\alpha}}>> U_1/U_n
\mathbb{Z}/p^{n-1}\mathbb{Z} @>{\theta_{n,\alpha}}>> U_1/U_n
\end{CD}
\end{CD}
However, CD doesn't support diagnoal arrows [https://math.meta.stackexchange.com/questions/14986/is-it-possible-to-draw-a-diagonal-arrow-in-a-commutative-diagram]. Note that to use CD one has to include <code>&lt;math&gt;\require{AMScd}&lt;/math&gt;</code> somewhere in the text. Basic documentation of CD can be found [https://www.jmilne.org/not/Mamscd.pdf here].
However, CD doesn't support diagnoal arrows [https://math.meta.stackexchange.com/questions/14986/is-it-possible-to-draw-a-diagonal-arrow-in-a-commutative-diagram]. Note that to use CD one has to include <code>&lt;math&gt;\require{amscd}&lt;/math&gt;</code> somewhere in the text. Basic documentation of CD can be found [https://www.jmilne.org/not/Mamscd.pdf here].

=== Xy package ===

And finally, with [https://sonoisa.github.io/xyjax-v3/xyjax-v3.html XyJax package], we can now create fancy diagrams with diagonal arrows!

\begin{xy}
\xymatrix {
U \ar@/_/[ddr]_y \ar@{.>}[dr]|{\langle x,y \rangle} \ar@/^/[drr]^x \\
& X \times_Z Y \ar[d]^q \ar[r]_p & X \ar[d]_f \\
& Y \ar[r]^g & Z
}
\end{xy}

The basic pattern is:
<code>
\begin{xy}
\xymatrix {
...
}
\end{xy}
</code>
or simply within a math environment e.g. as
<code>
\( \xymatrix { ... } \)
</code>

[https://sonoisa.github.io/xyjax-v3/xyjax-v3.html This page] at the bottom includes more example diagrams. For more details about the syntax see the original [https://www.tug.org/applications/Xy-pic/ Xy pic docummentation] which includes the [https://anorien.csc.warwick.ac.uk/mirrors/CTAN/macros/generic/diagrams/xypic/doc/xyguide.pdf official guide] and also these [https://www.math.arizona.edu/~swig/documentation/xypic/Xypic.pdf great slides] (by Cameron McLeman) with many more nice examples.

There is also an online visual editor [https://darknmt.github.io/res/xypic-editor/ Xypic-editor] that can do basic diagrams.

'''Selected useful examples'''

Basic commutative diagrams, potentially with fancy arrows:
\[
\xymatrix{
A\ar[r]^f\ar[d]_h & B\ar[dl]^g \\
C
}
\qquad
\xymatrix@1{
A\ar@{->>}[r]^f\ar@{=}[d]_h & B\ar@{=>}[d]^g \\
C\ar@{>->}[r]_h & D \ar@{-->}[lu]
}
\]
typeset with <code>\ar@{->>}</code>, <code>\ar@{>->}</code>, <code>\ar@{=>}</code>, <code>\ar@{-->}</code>, <code>\ar@{=}</code>, etc.
Shiftings, bend arrows as well as loops are also allowed:
\[
\xymatrix{
A & B \ar@<1ex>[l] \ar@<1ex>[l];[]
}
\qquad
\xymatrix@1{
A
\ar@/^3pc/[r]
\ar@/^2pc/[r]
\ar@/^1pc/[r]
\ar@/_1pc/[r]
\ar@/_2pc/[r]
\ar@/_3pc/[r]
&
B
}
\qquad
\xymatrix{
A \ar@(ru,lu)[]_{\id_A}
&
B \ar@(ld,d)[l]
}
\]

Notice the parameter <code>\xymatrix@1{ ... }</code> which ensures enough spacing within nodes. The simple bending is written e.g. as <code>\ar@/_2pc/[r]</code> or <code>\ar@/^3pc/[r]</code> and the fancy bend arrows are specified by <code>\ar@(<out>,<in>)</code>, e.g. <code>\ar@(ru,lu)</code>. Lastly <code>\ar@<1ex></code> shifts the arrow along the y axis.

For positioning of the labels, Xy-pic uses the following syntax <code>\ar[r]^(.3){+}</code> to produce
\[\xymatrix@1{A\ar[r]^(.3){+}&B}\]

== Collapsible sections ==

For writing parts of text that are collapsed and the viewer needs to click on "Expand" to see them, there is a simple trick. Just put the desired text within a div like this:

<code><nowiki>
&lt;div class="mw-collapsible mw-collapsed"&gt;
...
&lt;/div&gt;
</nowiki></code>

This is especially handy when hiding proofs, which can be done as follows:

<code><nowiki>
&lt;div class="proof mw-collapsible mw-collapsed"&gt;
(a proof goes here)
&lt;/div&gt;
</nowiki></code>

== Theorem "environments" ==

We also have CSS classes for standard mathematical environments, such as the following:

<div class="theorem">
This is a theorem.
</div>

<div class="proposition">
This is a proposition.
</div>

<div class="lemma">
This is a lemma.
</div>

<div class="corollary">
This is a corollary.
</div>

<div class="definition">
This is a definition.
</div>

<div class="example">
This is an example.
</div>

<div class="observation">
This is an observation.
</div>

which can be typeset by writing
<code>
&lt;div class="XXX"&gt;
...
&lt;/div&gt;
</code>
where <code>XXX</code> is one of "theorem", "proposition", "lemma", etc.

Sadly, we lack any way of referencing between them. Therefore, it is advised to give these environments names in their description and then simply refer to the written name.


== Preambles ==
If one prefers to use TikZ diagrams or XY, it's possible to prepare the diagram in [http://presheaf.com/ presheaf.com] and then just add a link to the generated image. For example, this one


To define new LaTeX commands, the it is preferred to add something like the following at the beginning of the page.
http://presheaf.com/cache/d3e436z2t5w3p603o2v6838s494d1r32.png
<pre>
<div style="display:none;"><math>
\newcommand\Ek{\mathbb E_k}
\newcommand\Pk{\mathbb P_k}
</math></div>
</pre>
The div style makes sure that there's no additional blank line inserted.


To create the "under construction" warning, just use the following
or (preferably) also include a link to the source (so that it can be easily eddited if needed):


<pre>
[http://presheaf.com/?d=d3e436z2t5w3p603o2v6838s494d1r32 <img src="http://presheaf.com/cache/d3e436z2t5w3p603o2v6838s494d1r32.png" title="click to go to presheaf.com for editing"/>]
<div style="text-align: center; background: yellow; padding: 2em;" >
'''UNDER CONSTRUCTION'''
</div>
</pre>

Latest revision as of 13:39, 4 September 2023

\( \newcommand\Ek{\mathbb E_k} \newcommand\Pk{\mathbb P_k} \)

This page serves as an example of how to write LaTeX formulas on this wiki. Go to Edit of this page to see how it's done (especially see the top of the text where I define new macros the same way as we would do in the regular LaTeX). Internally it uses MathJax as its LaTeX engine. See this mathoveflow thread for reference.

Note that there are minor differences with LaTeX on this Wiki. Inline mathematics is typeset with \(...\), and <math>...</math> HTML tag. This means that $...$ won't work! And display style maths is written with \[...\], \begin{XXX}...\end{XXX}, where XXX can be, for example, align.


See for example this \(\Ek A\) and \(\Pk A\) and also the following:

\[ \Ek A =\ ... \] and \begin{align} \Pk A = ... \end{align}

Note that the advantage of \(...\) is that it is also valid LaTeX, so it can be then just copy-pasted into papers, when in rush :-).

Commutative diagrams

Originally we only could use amscd and matrices or arrays to display diagrams. Now, after upgrading MathJax to version 3 we can also use the Xy pic syntax and even form diagrams with diagonal arrows and loops without hacks! These three individual options are demonstrated below.

Matrices/arrays

For commutative diagrams the simplest option is to just use arrays:

\[ \begin{array}{ccc} 0 & \xrightarrow{i} & A & \xrightarrow{f} & B & \xrightarrow{q} & C & \xrightarrow{d} & 0\\ \downarrow & \searrow & \downarrow & \nearrow & \downarrow & \searrow & \downarrow & \nearrow & \downarrow\\ 0 & \xrightarrow{j} & D & \xrightarrow{g} & E & \xrightarrow{r} & F & \xrightarrow{e} & 0 \end{array}\]

or like so \[ \newcommand{\ra}[1]{\kern-1.5ex\xrightarrow{\ \ #1\ \ }\phantom{}\kern-1.5ex} \newcommand{\ras}[1]{\kern-1.5ex\xrightarrow{\ \ \smash{#1}\ \ }\phantom{}\kern-1.5ex} \newcommand{\da}[1]{\bigg\downarrow\raise.5ex\rlap{\scriptstyle#1}} \begin{array}{c} 0 & \ra{f_1} & A & \ra{f_2} & B & \ra{f_3} & C & \ra{f_4} & D & \ra{f_5} & 0 \\ \da{g_1} & & \da{g_2} & & \da{g_3} & & \da{g_4} & & \da{g_5} & & \da{g_6} \\ 0 & \ras{h_1} & 0 & \ras{h_2} & E & \ras{h_3} & F & \ras{h_4} & 0 & \ras{h_5} & 0 \\ \end{array} \] Complicated diagrams can be made by just stacking arrays/matrices in layers, e.g. \[ \matrix{ \mathbb C(A) & \xrightarrow{h_t} & B \\ {}_{\epsilon^{\mathbb C}} \downarrow & \matrix{ \nwarrow {}^{\iota_f} & & {}^g \nearrow \\ & \mkern-20mu X \xrightarrow{\quad\phi\quad} Y \mkern-20mu & \\ \swarrow {}_{f} & & {}_{\iota_g} \searrow } & \uparrow {}_{\epsilon^{\mathbb D}} \\ A & \underset{h_b}{\xleftarrow{\quad}} & \mathbb D(B) } \]

CD package

Another option is to use CD \(\require{amscd}\) \begin{CD} \mathbb{Z}/p^n\mathbb{Z} @>{\theta_{n+1,\alpha}}>> U_1/U_{n+1}\\ @VVV @VVV\\ \mathbb{Z}/p^{n-1}\mathbb{Z} @>{\theta_{n,\alpha}}>> U_1/U_n \end{CD} However, CD doesn't support diagnoal arrows [1]. Note that to use CD one has to include <math>\require{amscd}</math> somewhere in the text. Basic documentation of CD can be found here.

Xy package

And finally, with XyJax package, we can now create fancy diagrams with diagonal arrows!

\begin{xy} \xymatrix { U \ar@/_/[ddr]_y \ar@{.>}[dr]|{\langle x,y \rangle} \ar@/^/[drr]^x \\ & X \times_Z Y \ar[d]^q \ar[r]_p & X \ar[d]_f \\ & Y \ar[r]^g & Z } \end{xy}

The basic pattern is: \begin{xy} \xymatrix { ... } \end{xy} or simply within a math environment e.g. as \( \xymatrix { ... } \)

This page at the bottom includes more example diagrams. For more details about the syntax see the original Xy pic docummentation which includes the official guide and also these great slides (by Cameron McLeman) with many more nice examples.

There is also an online visual editor Xypic-editor that can do basic diagrams.

Selected useful examples

Basic commutative diagrams, potentially with fancy arrows: \[ \xymatrix{ A\ar[r]^f\ar[d]_h & B\ar[dl]^g \\ C } \qquad \xymatrix@1{ A\ar@{->>}[r]^f\ar@{=}[d]_h & B\ar@{=>}[d]^g \\ C\ar@{>->}[r]_h & D \ar@{-->}[lu] } \] typeset with \ar@{->>}, \ar@{>->}, \ar@{=>}, \ar@{-->}, \ar@{=}, etc. Shiftings, bend arrows as well as loops are also allowed: \[ \xymatrix{ A & B \ar@<1ex>[l] \ar@<1ex>[l];[] } \qquad \xymatrix@1{ A \ar@/^3pc/[r] \ar@/^2pc/[r] \ar@/^1pc/[r] \ar@/_1pc/[r] \ar@/_2pc/[r] \ar@/_3pc/[r] & B } \qquad \xymatrix{ A \ar@(ru,lu)[]_{\id_A} & B \ar@(ld,d)[l] } \]

Notice the parameter \xymatrix@1{ ... } which ensures enough spacing within nodes. The simple bending is written e.g. as \ar@/_2pc/[r] or \ar@/^3pc/[r] and the fancy bend arrows are specified by \ar@(<out>,<in>), e.g. \ar@(ru,lu). Lastly \ar@<1ex> shifts the arrow along the y axis.

For positioning of the labels, Xy-pic uses the following syntax \ar[r]^(.3){+} to produce \[\xymatrix@1{A\ar[r]^(.3){+}&B}\]

Collapsible sections

For writing parts of text that are collapsed and the viewer needs to click on "Expand" to see them, there is a simple trick. Just put the desired text within a div like this:

<div class="mw-collapsible mw-collapsed"> ... </div>

This is especially handy when hiding proofs, which can be done as follows:

<div class="proof mw-collapsible mw-collapsed"> (a proof goes here) </div>

Theorem "environments"

We also have CSS classes for standard mathematical environments, such as the following:

This is a theorem.

This is a proposition.

This is a lemma.

This is a corollary.

This is a definition.

This is an example.

This is an observation.

which can be typeset by writing <div class="XXX"> ... </div> where XXX is one of "theorem", "proposition", "lemma", etc.

Sadly, we lack any way of referencing between them. Therefore, it is advised to give these environments names in their description and then simply refer to the written name.

Preambles

To define new LaTeX commands, the it is preferred to add something like the following at the beginning of the page.

<div style="display:none;">\(
\newcommand\Ek{\mathbb E_k}
\newcommand\Pk{\mathbb P_k}
\)</div>

The div style makes sure that there's no additional blank line inserted.

To create the "under construction" warning, just use the following

<div style="text-align: center; background: yellow; padding: 2em;" >
'''UNDER CONSTRUCTION'''
</div>