LaTeX writing tips: Difference between revisions

From miki
Jump to navigation Jump to search
 
(9 intermediate revisions by the same user not shown)
Line 42: Line 42:
</source>
</source>
* '''Units''' [http://www.ece.ucdavis.edu/~jowens/commonerrors.html] &mdash; Use a non-breaking space between quantity and unit: <code>10~m</code>. Or use package {{deb|siunitx}} package (<code>\SI{10}{m}</code>)
* '''Units''' [http://www.ece.ucdavis.edu/~jowens/commonerrors.html] &mdash; Use a non-breaking space between quantity and unit: <code>10~m</code>. Or use package {{deb|siunitx}} package (<code>\SI{10}{m}</code>)
* '''Numbers''' &mdash; Use <code>\num{123456}</code> along with package {{deb|siunitx}}. Or consider using another package like {{deb|numprint}}.
* Use '''unbreakable space''' in compound names (like <code>Van~Allen</code>)
* Use '''unbreakable space''' in compound names (like <code>Van~Allen</code>)
* '''Comma as decimal point''' &mdash; Surround the comma with braces (or consider using the package {{deb|icomma}}. Additionally, in number list, separate numbers with semicolons:
<source lang=latex>
$x_i\in[-1{,}5;1{,}5]$
</source>


== Conventions and Examples ==
== Conventions and Examples ==
Line 51: Line 56:
* $\lg x$ is the logarithm of $x$ to the base $2$.
* $\lg x$ is the logarithm of $x$ to the base $2$.
* Convention about ''positive'', ''greater than''...
* Convention about ''positive'', ''greater than''...
** ''Positive'' integers are integers ''greater than'' 0, i.e. $x>0$.
** ''Positive'' integers are integers ''greater than'' 0, i.e. $$x>0$$.
** ''Non-positive'' integers are integers ''less than or equal to'' 0, i.e. $x\le 0$.
** ''Non-positive'' integers are integers ''less than or equal to'' 0, i.e. $$x\le 0$$.
** ''Negative'' integers are integers ''less than'' 0, i.e. $x<0$.
** ''Negative'' integers are integers ''less than'' 0, i.e. $$x<0$$.
** ''Non-negative'' integers are integers ''greater than or equal to'' 0, i.e. $x\ge 0$.
** ''Non-negative'' integers are integers ''greater than or equal to'' 0, i.e. $$x\ge 0$$.
: These are the English conventions. The French conventions are different (''positif'' means $x\ge 0$, and ''supérieur'' means ''supérieur ou égal'', and one must say ''strictement supérieur'' to exclude equality).
: These are the English conventions. The French conventions are different: ''positif'' means $$x\ge 0$$, and ''supérieur'' means ''supérieur ou égal'', and ''strictement supérieur'' excludes equality.
;Bitsize
;Bitsize
* A $n$-bit integer $N$ ... we know the high order $(1/4+c)(log_2 N)$ bits of P ... $\lceil log_2 N \rceil$-bit integer
* A $$n$$-bit integer $N$ ... we know the high order $$(1/4+c)(log_2 N)$$ bits of P ... $$\lceil log_2 N \rceil$$-bit integer


;Integers
;Integers
Line 63: Line 68:
{| class=wikitable
{| class=wikitable
|-
|-
|$$\mathbb{N\ Z\ Q\ R}$$<br>
|$\mathbf N$
$$\textsf$\textbf{N Z Q R}}$$
|<code>$\mathbb N$</code><br>
<code>\textsf{\textbf N}</code>
|Sets in algebra are usually denoted with blackboard typeface. Bold sans-serif is also a possible, but a bit less convenient in $\LaTeX$.
|
|-
|$$\mathbb N$$
|<code>$\mathbb N$</code>
|<code>$\mathbb N$</code>
|The set of ''natural numbers'', including 0, i.e. $\N = \{0,1,2,\dotsc\}$
|The set of ''natural numbers'', including 0, $$\{0,1,2,\dotsc\}$$.<br>
Other notations include $$\N^0\ \N_0$$.
|
|-
|$$\mathbb N^*$$
|<code>$\mathbb N^*$</code>
|The set of ''positive natural numbers'', $$\{1,2,\dotsc\}$$.<br>
Other notations include $$\N^+\ \N_1\ \N_{>0}$$.
|
|-
|$$\mathbb Z$$
|<code>$\mathbb Z$</code>
|The set of ''integers'', $\{\dotsc,-2,-1,0,1,2,\dotsc\}$
|<ref name="proofwiki">ProofWiki, {{bibtit|Symbols:Z &mdash; ProofWiki}}, http://www.proofwiki.org/wiki/Symbols:Z, 2013</ref>
|-
|$$\mathbb Z_{\ge 0}$$
(or $$\mathbb Z_+$$)
|<code>$\mathbb Z_{\ge 0}$</code>
(or <code>$\mathbb Z_+$</code>)
|The set of ''non-negative integers'', $$\{0,1,2,\dotsc\}$$
|<ref name="proofwiki"/>
|-
|$$\mathbb Z_{> 0}$$
(or $$\mathbb Z^*_+$$)
|<code>$\mathbb Z_{> 0}$</code>
(or <code>$\mathbb Z_+^*$</code>)
|The set of ''strictly positive integers'', i.e. $$\{1,2,\dotsc\}$$
|<ref name="proofwiki"/>
|-
|$$\{1,2,\dotsc,n\}$$<br>
(or $$\N_{n}^*$$ or $$\Z \left({n}\right)$$)
|<code>$\{1,2,\dotsc,n\}$</code>
|A ''finite set of integers''.
|<ref name=HAC/><ref name="proofwiki"/>
|-
|$$\Z_n$$
|<code>$\Z_n$</code>
|The set of ''integers modulo n'', $$\{0,1,2,\dotsc,n-1\}$$
|<ref name="HAC">Menezes, A., van Oorschot, P., Vanstone, S.: {{bibtit|Handbook of Applied Cryptography}}, 1997</ref>
|-
|$$\Z_n^*$$
|<code>$\Z_n^*$</code>
|
The ''multiplicative group'' of $$\Z_n$$, $$\{a \in \Z_n | \gcd(a,n) = 1\}$$<br>
This is also known as the ''set of coprime integers'' to $$n$$, denoted as $$\Z'_n = \{ k \in \Z_n : a \perp n\}$$
|<ref name=HAC/><ref name="proofwiki"/>
|-
|$$n \mathbb Z$$
|<code>$n \mathbb Z$</code>
|The set of ''integer multiples'' $$n \mathbb Z$$
|<ref name="proofwiki"/>
|}
|}
* Integer sets are usually denoted with the blackboard fonts $\mathbb N$, $\mathbb Z$, $\mathbb Q$, $\mathbb R$, or with bold sans-serif face $\mathbf{\mathsf{N,Z,Q,R}}$ (although <code>$\textsf{$\textbf N$}$</code> gives better results).
** Some authors argue that bold face is the original convention, and blackboard typeface was used for black board only.
* The set of ''integers'' $\Z = \{\dotsc,-2,-1,0,1,2,\dotsc\}$ (source <ref name="proofwiki">ProofWiki, {{bibtit|Symbols:Z &mdash; ProofWiki}}, http://www.proofwiki.org/wiki/Symbols:Z, 2013</ref>).
* The set of ''non-negative integers'' is $\Z_{\ge 0} = \{0,1,2,\dotsc\}$ (or $\Z_+$) (source <ref name="proofwiki"/>)
* The set of ''strictly positive integers'' is $\Z_{> 0} = \{1,2,\dotsc\}$ (or $\Z_+^*$) (source <ref name="proofwiki"/>)
* A ''finite set of integers'' is denoted $\{1,2,\dotsc,n\}$ (source <ref name=HAC/>)
** Alternatively one can use $\N_{n}^*$ or $\Z \left({n}\right)$ (source <ref name="proofwiki"/>)
* The set of ''integers modulo n'' is $\Z_n=\{0,1,2,\dotsc,n-1\}$ (source <ref name="HAC">Menezes, A., van Oorschot, P., Vanstone, S.: {{bibtit|Handbook of Applied Cryptography}}, 1997</ref>)
* The ''multiplicative group of $\Z_n$'' is $\Z_n^* = \{a \in \Z_n | \gcd(a,n) = 1\}$ (source <ref name=HAC/>)
** Also known as the ''set of coprime integers'' to $n$, denoted as $\Z'_n = \{ k \in \Z_n : a \perp n\}$ (source <ref name="proofwiki"/>)
* The set of ''integer multiples'' $n \Z$ (source <ref name="proofwiki"/>)


;Tuples
;Tuples
Line 88: Line 139:


;Matrices
;Matrices
* Vector or matrix transpose: Use <code>^\top</code> $\mathbf M^\top$ (alt. <code>^\mathsf{T}</code> $\mathbf M^\mathsf{T}$, or <code>^\intercal</code> $\mathbf M^\intercal$) [http://tex.stackexchange.com/questions/30619/what-is-the-best-symbol-for-vector-matrix-transpose]
* Vector or matrix transpose: Use <code>^\top</code> $$\mathbf M^\top$$ (alt. <code>^\mathsf{T}</code> $$\mathbf M^\mathsf{T}$$, or <code>^\intercal</code> $$\mathbf M^\intercal$$) [http://tex.stackexchange.com/questions/30619/what-is-the-best-symbol-for-vector-matrix-transpose]
* Vector or matrix conjugate: Use <code>^*</code> $\mathbf A^*$
* Vector or matrix conjugate: Use <code>^*</code> $$\mathbf A^*$$


;Sets
;Sets
* Isomorphism between 2 sets: <code>A \cong B</code> $A \cong B$, or <code>A \simeq B</code>$A \simeq B$.
* Isomorphism between 2 sets: <code>A \cong B</code> $$A \cong B$$, or <code>A \simeq B</code>$$A \simeq B$$.


;Functions
;Functions
* Example of function definitions:
* Example of function definitions:
{| width=100%
|-
|width=50%|
<source lang=latex>
$$\begin{array}{llll}
$$\begin{array}{llll}
f : & \Z_N \to \Z_N & \qquad f^{-1}: & \Z_N \to \Z_N\\
f : & \Z_N \to \Z_N & \qquad f^{-1}: & \Z_N \to \Z_N\\
& x \mapsto x^e \bmod N & & x \mapsto x^d \bmod N
& x \mapsto x^e \bmod N & & x \mapsto x^d \bmod N
\end{array}$$
\end{array}$$
</source>
* Inline function definition: $f$ is defined as $f : \{0,1\}^* \to \ZZ_{N}$, $x\mapsto b^x\bmod N$.
|
$$\begin{array}{llll}
f : & \Z_N \to \Z_N & \qquad f^{-1}: & \Z_N \to \Z_N\\
& x \mapsto x^e \bmod N & & x \mapsto x^d \bmod N
\end{array}$$
|}
* Inline function definition:
{| width=100%
|-
|width=50%|
<source lang=latex>
$$f : \{0,1\}^* \to \ZZ_{N}$$, $$x\mapsto b^x\bmod N$$
</source>
|align=center|
$$f$$ is defined as $$f : \{0,1\}^* \to \ZZ_{N}$$, $$x\mapsto b^x\bmod N$$
|}

;Logic
* <code>\iff</code> and <code>\implies</code> (do not use with other arrows symbols like <code>\Leftrightarrow</code>))
{| width=100%
|-
|width=50%|
<source lang=latex>
$$A \iff B$$
$$P \implies Q$$
</source>
|
$$A \iff B$$

$$P \implies Q$$
|}


== References ==
== References ==

Latest revision as of 07:56, 31 October 2022

Layout and Typesetting

See also: English writing tips

  • Maintain the relation 1 paragraph = 1 thought across the document.
  • English requires longer space after the dots terminating a sentence (see \@); French does not (see \frenchspacing}.
  • Add footnote after the word or sentence they refer to (i.e. after the comma or periodrelated to a sentence after the terminating dot.
  • Avoid ligatures crossing morpheme boundary in a composite word, like shelfful ([1])
  • Use ` and ' or `` and as quotation marks in English (or << and >> in French)
  • Use the correct dash for each use (X-rated, page 13--67, yes---or no?, $-1$)
  • Use \dots{} instead of \dots to add a space after the dots:
This is the end\dots Bye!        # Bad
This is the end\dots{} Bye!      # Good
  • Use the correct semantic \dotsx command, depending on context:
We have the series $A_1,A_2,\dotsc$,                  % for comma list
the sum $A_1+A_2+\dotsb$,                             % for binary op
the orthogonal product $A_1A_2\dotsm$,                % for multiplication dots
the infinite integral $$\int_{A_1}\int_{A_2}\dotsi$$. % for dots with integrals
  • Use roman style for 'd' in the differential:
\newcommand{\ud}{\,\mathrm{d}}
\begin{equation*}
\int_a^b f(x)\ud x
\end{equation*}
  • Use \textsubscript{} or \textsuperscript{} for subscripts our superscripts outside math (like CO2 or 4th). The preferred option for ordinals in mathematics texts (or even english) seems to use $n$th or $n$-th (like nth or n-th) [2], [3], [4]. Yet another option is $n^{\text{th}}$ (with amsmath package). Finally, there is the package nth that can render ordinal with \nth{4} but it only works with numbers.
The $4$th, or the $4$-th, or the $4^{\text{th}}$ or the $4^{\text{\tiny{th}}}$ or the $4$\textsuperscript{th} or \nth{4}?
  • Cut long line by adding a % at the cut to avoid LaTeX adding unwanted space where the cut occurs:
  \State $u \gets (v_i - x)\cdot C_i \bmod \rsamod_i$, $x \gets x + u \cdot% This comment will prevent LaTex adding space
    \prod_{j=1}^{i-1}\rsamod_j$
  • When using cleveref, use \Cref{} instead of \cref{} at the beginning of a sentence to enforce capitalization.
  • Interword spaces [5] — “TeX assumes a period ends a sentence unless it follows an uppercase letter.” (Lamport p. 14). So, put a \ in a sentence like Smith et al.\ say that .... And, if an uppercase letter ends a sentence, do a \@ before the period: In the class, I gave Bob a C\@..
  • The small package xspace (by David Carlisle) defines the \xspace command, for use at the end of macros that produce text. It adds a space unless the macro is followed by certain punctuation characters.[1].
\newcommand\eg{e.g.\@\xspace}
\newcommand\ie{i.e.\@\xspace}
\newcommand\etc{etc.\xspace}
  • Units [6] — Use a non-breaking space between quantity and unit: 10~m. Or use package siunitx package (\SI{10}{m})
  • Numbers — Use \num{123456} along with package siunitx. Or consider using another package like numprint.
  • Use unbreakable space in compound names (like Van~Allen)
  • Comma as decimal point — Surround the comma with braces (or consider using the package icomma. Additionally, in number list, separate numbers with semicolons:
$x_i\in[-1{,}5;1{,}5]$

Conventions and Examples

See also latex_templates examples. __MATHJAX_DOLLAR__

Usual conventions
  • $\ln x$ is the natural logarithm of $x$; that is, the logarithm of $x$ to the base $e$.
  • $\lg x$ is the logarithm of $x$ to the base $2$.
  • Convention about positive, greater than...
    • Positive integers are integers greater than 0, i.e. $$x>0$$.
    • Non-positive integers are integers less than or equal to 0, i.e. $$x\le 0$$.
    • Negative integers are integers less than 0, i.e. $$x<0$$.
    • Non-negative integers are integers greater than or equal to 0, i.e. $$x\ge 0$$.
These are the English conventions. The French conventions are different: positif means $$x\ge 0$$, and supérieur means supérieur ou égal, and strictement supérieur excludes equality.
Bitsize
  • A $$n$$-bit integer $N$ ... we know the high order $$(1/4+c)(log_2 N)$$ bits of P ... $$\lceil log_2 N \rceil$$-bit integer
Integers
$$\mathbb{N\ Z\ Q\ R}$$

$$\textsf$\textbf{N Z Q R}}$$

$\mathbb N$

\textsf{\textbf N}

Sets in algebra are usually denoted with blackboard typeface. Bold sans-serif is also a possible, but a bit less convenient in $\LaTeX$.
$$\mathbb N$$ $\mathbb N$ The set of natural numbers, including 0, $$\{0,1,2,\dotsc\}$$.

Other notations include $$\N^0\ \N_0$$.

$$\mathbb N^*$$ $\mathbb N^*$ The set of positive natural numbers, $$\{1,2,\dotsc\}$$.

Other notations include $$\N^+\ \N_1\ \N_{>0}$$.

$$\mathbb Z$$ $\mathbb Z$ The set of integers, $\{\dotsc,-2,-1,0,1,2,\dotsc\}$ [2]
$$\mathbb Z_{\ge 0}$$

(or $$\mathbb Z_+$$)

$\mathbb Z_{\ge 0}$

(or $\mathbb Z_+$)

The set of non-negative integers, $$\{0,1,2,\dotsc\}$$ [2]
$$\mathbb Z_{> 0}$$

(or $$\mathbb Z^*_+$$)

$\mathbb Z_{> 0}$

(or $\mathbb Z_+^*$)

The set of strictly positive integers, i.e. $$\{1,2,\dotsc\}$$ [2]
$$\{1,2,\dotsc,n\}$$

(or $$\N_{n}^*$$ or $$\Z \left({n}\right)$$)

$\{1,2,\dotsc,n\}$ A finite set of integers. [3][2]
$$\Z_n$$ $\Z_n$ The set of integers modulo n, $$\{0,1,2,\dotsc,n-1\}$$ [3]
$$\Z_n^*$$ $\Z_n^*$

The multiplicative group of $$\Z_n$$, $$\{a \in \Z_n | \gcd(a,n) = 1\}$$
This is also known as the set of coprime integers to $$n$$, denoted as $$\Z'_n = \{ k \in \Z_n : a \perp n\}$$

[3][2]
$$n \mathbb Z$$ $n \mathbb Z$ The set of integer multiples $$n \mathbb Z$$ [2]
Tuples
  • a 2-tuple is an ordered pair (aka. couple in french, not be confused with pair where element order does not matter) (source [4]).
  • a 3-tuple is a triplet (source [4]).
Graphs (tree...)
  • Height of a node = distance to root node; height of the tree = maximum height.
  • degree of a node = number of children of a node; node with degree 0 = leaf node; node with no parent = root node.
Matrices
  • Vector or matrix transpose: Use ^\top $$\mathbf M^\top$$ (alt. ^\mathsf{T} $$\mathbf M^\mathsf{T}$$, or ^\intercal $$\mathbf M^\intercal$$) [7]
  • Vector or matrix conjugate: Use ^* $$\mathbf A^*$$
Sets
  • Isomorphism between 2 sets: A \cong B $$A \cong B$$, or A \simeq B$$A \simeq B$$.
Functions
  • Example of function definitions:
$$\begin{array}{llll}
f : & \Z_N \to \Z_N & \qquad f^{-1}: & \Z_N \to \Z_N\\
& x \mapsto x^e \bmod N & & x \mapsto x^d \bmod N
\end{array}$$

$$\begin{array}{llll} f : & \Z_N \to \Z_N & \qquad f^{-1}: & \Z_N \to \Z_N\\ & x \mapsto x^e \bmod N & & x \mapsto x^d \bmod N \end{array}$$

  • Inline function definition:
$$f : \{0,1\}^* \to \ZZ_{N}$$, $$x\mapsto b^x\bmod N$$

$$f$$ is defined as $$f : \{0,1\}^* \to \ZZ_{N}$$, $$x\mapsto b^x\bmod N$$

Logic
  • \iff and \implies (do not use with other arrows symbols like \Leftrightarrow))
$$A \iff B$$
$$P \implies Q$$

$$A \iff B$$

$$P \implies Q$$

References

  1. Frank Mittelbach,Michel Goossens: The LaTEX Companion — Second Edition. Addison-Wesley, 2004
  2. 2.0 2.1 2.2 2.3 2.4 2.5 ProofWiki, Symbols:Z — ProofWiki, http://www.proofwiki.org/wiki/Symbols:Z, 2013
  3. 3.0 3.1 3.2 Menezes, A., van Oorschot, P., Vanstone, S.: Handbook of Applied Cryptography, 1997
  4. 4.0 4.1 Wikipedia, https://en.wikipedia.org/wiki/Tuple