LaTeX Tips and Tricks — Useful hints for particle physicists

4e684667472d2253f41fc2d40032ef3f?s=47 AndiH
October 09, 2015

LaTeX Tips and Tricks — Useful hints for particle physicists

I write-up of all the LaTeX tools I find too-less known for particle physicists

4e684667472d2253f41fc2d40032ef3f?s=128

AndiH

October 09, 2015
Tweet

Transcript

  1. Mitglied der Helmholtz-Gemeinscha LaTeX Tips and Tricks Useful hints for

    particle physicists Andreas Herten, Forschungszentrum Jülich, 8 October 2015
  2. Mitglied der Helmholtz-Gemeinscha Outline Essential Packages Units with siunitx Particles

    with hepnames Other Useful Packages Core Tools BibLaTeX Glossary Typesetting with latexmk Et Cetera and Summary 2/29 Andreas Herten | IKP 1 Seminar | 8 October 2015
  3. Mitglied der Helmholtz-Gemeinscha E P 3/29 Andreas Herten | IKP

    1 Seminar | 8 October 2015
  4. Mitglied der Helmholtz-Gemeinscha Writing Units Writing units can be cumbersome,

    if one decides to follow rules Examples from the rulebook(s) ISO 80000-2; BIPM: International System of Units — Use thin space between value and unit (= multiplication). Exception: No space at plane angle units (◦, , ). If there is no thin space available, substitute with space. — Units are printed upright, variables in italics. Mathematical constants (e.g. π) upright, physical pseudo-constant values (e.g. c, NA ) in italics. It’s sin x and ex and dx/dt. — Units are mathematical entities, not abbreviations. No plurals! — Combination of value and unit is a product (because of entity). T = 273 K can also be written as T/K = 273. (Hence, labeling of axes is T/K, not T[K]!) → Hard to get right. Use a package, siunitx ! 4/29 Andreas Herten | IKP 1 Seminar | 8 October 2015
  5. Mitglied der Helmholtz-Gemeinscha siunitx — Features Takes care of all

    unit interaction for you! Usage with \usepackage[alsoload=hep]{siunitx} Features (Highlights): — Numbers: \num{10} instead of $10$: 10 Will set thousand-separator automatically, 10 000 or 10,000 (config). — Units: \SI{10}{\metre} = 10 m = \SI{10}{m} \SI{9.81}{\metre\per\second\squared} = 9.81 m/s2 \SI[per-mode=fraction]{.}{.} = 9.81 m s2 \SI{4}{\mega\eVperc\squared} = 4 MeV/c2 — Uncertainties: \SI{2 +- 0.1}{\eVperc} = (2.0 ± 0.1) eV/c — Ranges: \SIrange{1e1}{2e2}{\kilo\gram} = 1 × 101 kg to 2 × 102 kg — Lists: \SIlist{1;3;5}{\mol} = 1 mol, 3 mol, and 5 mol — Also: \ang{}, \si{}, \DeclareSIUnit\ikp{ikp}, \DeclareSIQualifier\centerofmass{CM} — Works in math environments $\num{}$ and outside 5/29 Andreas Herten | IKP 1 Seminar | 8 October 2015
  6. Mitglied der Helmholtz-Gemeinscha siunitx — Options Package can be setup

    with \sisetup{} My setup: \sisetup{ per-mode = symbol, separate-uncertainty = true, math-micro=\muup,text-micro=\ensuremath{\muup}, list-final-separator = {, and~}, group-separator = {,} } More at CTAN 6/29 Andreas Herten | IKP 1 Seminar | 8 October 2015
  7. Mitglied der Helmholtz-Gemeinscha Writing Particle Names Convention: Particle names are

    upright, independent of alphabet of which particle symbol is from; use italics for describing a generic class of particles (e.g. leptons). CERN’s e ort for standardization: Particle Entity Notation (PEN) scheme — Implement all PDG names — Machine-extractable — Maximum eight characters, but common particles shorter — First superscripts, then subscripts — No mass in name — Examples: Pe = e−, Pagne = νe , PgL = Λ, PsDp = D+ s See cookbook 7/29 Andreas Herten | IKP 1 Seminar | 8 October 2015
  8. Mitglied der Helmholtz-Gemeinscha Particle Names with hepnames There’s a package

    for that: hepnames Features: — PEN names pre-defined — More memorable names with sub-package hepnicenames — Properly typeset! — Context-sensitive adaption of typeset Structure: Using macros in hepparticles , the package o ers particles of o icial notation from hepppennames , or of easier notation from hepnicenames Load with \usepackage{hepnames} 8/29 Andreas Herten | IKP 1 Seminar | 8 October 2015
  9. Mitglied der Helmholtz-Gemeinscha Examples of hepnames Particles (hepnicenames): — \Pelectron

    = e− — \APmuon = µ+ — \PDsminus = D− s — \PHiggspm = H± — \PUpsilonTwoS = Υ(2S) Process: \HepProcess{\APproton\Pproton \to \PDplus\PDminus} = pp → D+D− Resonances (heppennames): — \PKsti = K∗(892) Implemented as \HepParticleResonance{\PKst}{892}{}{}. — \PDiz = D1(2420)0 Implemented as \HepParticleResonanceFull{D}{1}{}{2420}{}{0}. Can be easily extended, especially resonances. 9/29 Andreas Herten | IKP 1 Seminar | 8 October 2015
  10. Mitglied der Helmholtz-Gemeinscha O U P 10/29 Andreas Herten |

    IKP 1 Seminar | 8 October 2015
  11. Mitglied der Helmholtz-Gemeinscha Other Useful Packages I Modern code highlighting

    with minted (CTAN) — Uses external Pygments library — Inline: \mintinline{cpp}{int one = 1;} = int one = 1; — Block: \begin{minted}{cpp}int one = 1;\end{minted} = int one = 1; — Define own styles with \newminted and \newmintinline — Appendix: Notes on usage at IKP All color craziness with xcolor (CTAN) — Define colors in rgb, RGB, cmyk, hsb, HSB, gray, HTML space — Lots of predefined colors, e.g. »DarkOrchid3« (x11names option) — Mixing of colors, e.g. 40 % green, 60 % yellow = — Fun: color wavelength model, e.g. 485 nm is ≈ — Additional package xcolor-solarized which defines the 16 solarized colors base03 base02 base01 base00 base0 base1 base2 base3 yellow orange red magenta violet blue cyan green 11/29 Andreas Herten | IKP 1 Seminar | 8 October 2015
  12. Mitglied der Helmholtz-Gemeinscha Other Useful Packages II xspace for content-smart

    insertion of a space in your own commands (e.g. \newcommand{\something}{something\xspace} ) (CTAN) Also: \ensuremath{command} for using macro in every environment My panda package, which prints a beautiful PANDA and is context-aware (on Github) gitinfo2, enabling display of metadata of Git version control into your L A TEX documents. Useful to display versions of a document. (CTAN: v1, v2) feynmp & feynmp-auto for drawing Feynman Diagrams in the document (CTAN) γ, Z0 e− e+ e+, µ+ e−, µ+ i √ α i √ α 12/29 Andreas Herten | IKP 1 Seminar | 8 October 2015
  13. Mitglied der Helmholtz-Gemeinscha Other Useful Packages III booktabs creates beautiful,

    much more readable tables (CTAN) Without booktabs m X(m) X(m) 23 ϕ(m) / ◦ Random Formula 1 16.128 1.402 -146.6 F = m · a 2 3.442 0.299 133.2 σx σp ≥ 2 3 1.826 0.159 168.5 i ∂ ∂t Ψ(r, t) = HΨ(r, t) 4 0.993 0.086 25.6 ∇ × B = µ0 J + ε0 ∂E ∂t 5 1.29 0.112 -175.6 6 0.483 0.042 22.3 7 0.766 0.067 141.6 8 0.624 0.054 -35.7 13/29 Andreas Herten | IKP 1 Seminar | 8 October 2015
  14. Mitglied der Helmholtz-Gemeinscha Other Useful Packages III booktabs creates beautiful,

    much more readable tables (CTAN) With booktabs m X(m) X(m) 23 ϕ(m) / ◦ Random Formula 1 16.128 1.402 −146.6 F = m · a 2 3.442 0.299 133.2 σx σp ≥ 2 3 1.826 0.159 168.5 i ∂ ∂t Ψ(r, t) = HΨ(r, t) 4 0.993 0.086 25.6 ∇ × B = µ0 J + ε0 ∂E ∂t 5 1.29 0.112 −175.6 6 0.483 0.042 22.3 7 0.766 0.067 141.6 8 0.624 0.054 −35.7 See appendix for code snippet for this table 13/29 Andreas Herten | IKP 1 Seminar | 8 October 2015
  15. Mitglied der Helmholtz-Gemeinscha C T 14/29 Andreas Herten | IKP

    1 Seminar | 8 October 2015
  16. Mitglied der Helmholtz-Gemeinscha BibLaTeX, The New BibTeX Re-implementation of BibTeX

    bibliography management for more modern L A TEX days (CTAN) Completely backward compatible Uses same structure in .bib files ... ... but is much more versatile and customizable Select basic style at loading: \usepackage[style=numeric-comp]{biblatex} 15/29 Andreas Herten | IKP 1 Seminar | 8 October 2015
  17. Mitglied der Helmholtz-Gemeinscha BibLaTeX — Highlights and Features I Load

    .bib resources with \addbibresource{refs/physics.bib} Or use mine: \addbibresource[location=remote]{https://raw.githubusercontent .com/AndiH/PhD/master/Bibliography/physics.bib} (With BibTex it was \bibliography{refs.bib}.) Lots of easily accessible options, changed with \ExecuteBibliographyOptions{} My options: sorting=none Do not sort refs, but list them as they come maxnames=5,minnames=3 Truncate author list a er 5, but show min. 3 hyperref=true Create links inside the PDF backref=true Create backlinks in bibliography section backrefstyle=two Combine backlinks isbn=false Do not show ISBN and ISSN numbers autolang=hyphen Use proper hyphenation as defined by babel package 16/29 Andreas Herten | IKP 1 Seminar | 8 October 2015
  18. Mitglied der Helmholtz-Gemeinscha BibLaTeX — Highlights and Features II Not

    only public options, but also more under the hood Examples: — \DefineBibliographyStrings{english}{ techreport = {Tech. Rep.}, phdthesis = {PhD Thesis} } — \AtEveryBibitem{\clearlist{language}} — \renewcommand{\UrlFont}{\small\ttfamily} — \xpatchbibmacro{name:andothers}{\bibstring{andothers}}{ \bibstring[\emph]{andothers}}{}{} → — \DeclareFieldFormat[webpage,url]{usera}{Saved at: \url{#1}} — \renewcommand{\mkbibnamefirst}[1]{\textsc{#1}} Bottom line: If you ever wanted to change stu in your bibliography, you finally can do so now (modulo some googling) 17/29 Andreas Herten | IKP 1 Seminar | 8 October 2015
  19. Mitglied der Helmholtz-Gemeinscha BibLaTeX in my Thesis Bibliography [1] K.A.

    OLIVE et al.: Review of Particle Physics. In: Chin. Phys. C, 38:9 (090001) (2014). DOI: 10.1088/1674-1137/38/9/090001 (see pp. 4, 7–9, 14, 31–32, 141, 145, 179). [2] PETER W. HIGGS: Broken Symmetries and the Masses of Gauge Bosons. In: Phys. Rev. Lett., 13: (16 Oct. 1964), pp. 508–509. DOI: 10.1103/PhysRevLett.13.508 (see p. 5). [3] T. W. B. KIBBLE: Englert-Brout-Higgs-Guralnik-Hagen-Kibble mechanism. In: Schol- arpedia, 4:1 (2009). revision 91222, p. 6441. DOI: doi:10.4249/scholarpedia.6441 (see p. 5). [4] T. W. B. KIBBLE: Englert-Brout-Higgs-Guralnik-Hagen-Kibble mechanism (history). In: Scholarpedia, 4:1 (2009). revision 137393, p. 8741. DOI: doi:10.4249/scholarpedia. 8741 (see p. 5). [5] CMS COLLABORATION: Observation of a new boson at a mass of 125 GeV with the CMS experiment at the LHC. In: Physics Letters B, 716:1 (2012), pp. 30–61. URL: http://arxiv.org/abs/1207.7235 (see p. 5). [6] ATLAS COLLABORATION: Observation of a new particle in the search for the Stan- dard Model Higgs boson with the ATLAS detector at the LHC. In: Physics Letters B, 716:1 (2012), pp. 1–29. DOI: 10.1016/j.physletb.2012.08.020 (see p. 5). [7] The Nobel Prize in Physics 1969. URL: http://www.nobelprize.org/nobel_prizes/ physics/laureates/1969/ (see p. 6). [8] The Nobel Prize in Physics 2004. URL: http://www.nobelprize.org/nobel_prizes/ 18/29 Andreas Herten | IKP 1 Seminar | 8 October 2015
  20. Mitglied der Helmholtz-Gemeinscha Glossary A glossary summarizes — Acronyms —

    Terms (technical and physical phrases and concepts) — Symbols Great L A TEX implementation: package glossaries (CTAN) — Load with \usepackage[xindy]{glossaries} — Print with \printglossary — Also interesting: glossaries-prefix to allow for prefixes (»The GPU«) 19/29 Andreas Herten | IKP 1 Seminar | 8 October 2015
  21. Mitglied der Helmholtz-Gemeinscha Package glossaries Highlights I Acronyms — Define

    with \newacronym{cms}{CMS}{Compact Muon Solenoid} — Use with \gls{cms} or \Gls{cms} — Expands automatically at first usage, a er that just prints the abbreviation (link goes to glossary) — Accepts options, e.g. \newacronym[ sort={PANDA}, first={\glstext*{panda} experiment (\glsdesc*{panda})}, prefixfirst={the~}, prefix={} ] {panda}{\PANDA}{Antiproton Annihilation at Darmstadt} — Short version with \acrshort{cms}, long version \glsdesc{cms} Phrases 20/29 Andreas Herten | IKP 1 Seminar | 8 October 2015
  22. Mitglied der Helmholtz-Gemeinscha Package glossaries Highlights II Acronyms Phrases —

    Define with \newglossaryentry{gls:rfcavity}{ name={RF Cavity}, text={RF cavity}, plural={RF cavities}, description={Radio-frequency cavities are used ...} } — Usage: \gls{gls:rfcavity} → »RF cavity« Plural: \glspl{gls:rfcavity} → »RF cavities« Capitalization: \Gls{gls:rfcavity} → »RF cavities« and \GLS{gls:rfcavity} → »RF CAVITIES« Symbols 21/29 Andreas Herten | IKP 1 Seminar | 8 October 2015
  23. Mitglied der Helmholtz-Gemeinscha Package glossaries Highlights III Acronyms Phrases Symbols

    — Define with \newglossaryentry{pi}{ name={pi}, text={\ensuremath{\pi}}, first={\ensuremath{\pi} (lowercase pi)}, symbol={\ensuremath{\pi}}, description={Transcendental number}, parent=greekletter } — Personally never used 22/29 Andreas Herten | IKP 1 Seminar | 8 October 2015
  24. Mitglied der Helmholtz-Gemeinscha Package glossaries Etc Workflow — Create acronym

    entries (e.g. in glossaries.tex) — Reference entries throughout text by \gls{acro} — Add \makeglossaries to preamble (before definition of entries) — Add \printglossaries to document at correct position — Run makeglossaries from command line to sort entries Run L A TEXbefore and a er to first generate, then include glossary files; This can be automated (see next slides) Styling glossary — Select style of glossary with \setglossarystyle{name} — Examples: list, listgroup, long, tree, indexgroup, mcols (needs additional package, glossary-mcols) — Checkout samples coming with glossaries 23/29 Andreas Herten | IKP 1 Seminar | 8 October 2015
  25. Mitglied der Helmholtz-Gemeinscha Glossary in my Thesis Using mcolindex R3B

    Reactions with Relativistic Radioactive Beams Race Condition Race conditions can occur when the output of one computing process is input to another. Especially in parallel programming, race condi- tions can become critical and need to be considered carefully. Radiation Length A property of a specific material, denoted X 0 . The mean distance an electron travels through this matter, until the electron’s en- ergy is reduced to 1/e (by means of bremsstrahlung). RESR Recuperated Experimental Storage Ring RF Cavity Radiofrequency cavities are used to accelerated charged particles by means of applied electromagnetic fields. RICH Short for Ring-Imaging Cherenkov. A de- tector using rings of Cherenkov light for PID. ROOT A data analysis framework from CERN. SciTil Scintillating Tiles – usually referring to PANDA’s time of flight detector. laboration STL Standard Template Library STT Straw Tube Tracker Super-FRS Super Fragment Separator Target Spectrometer The part of the PANDA detector around the interaction re- gion, instrumenting nearly a 4⇡ solid angle. µTCA Micro Telecommunications Computing Architecture TF Triplet Finder Thread A computing process on a GPU. Thrust A template library providing functions for often-used GPU-computing tasks, resembling the C++ Standard Template Library (STL). Thrust adds a layer of abstraction on top of CUDA and sup- plies pre-programmed functions for many tasks, e.g. reduction and sort- ing. [151] TOF Time Of Flight ToPix The read-out ASIC for the pixel part of PANDA’s MVD. UNILAC Linear Accelerator for ions at GSI. USR Ultra Low Energy Storage Ring 24/29 Andreas Herten | IKP 1 Seminar | 8 October 2015
  26. Mitglied der Helmholtz-Gemeinscha Making PDFs with latexmk Like make for

    L A TEX Greatly automates typesetting to create PDFs (etc.) Runs iteratively until stable PDF is generated Can watch files and continuously regenerate PDFs Expandable by own commands → Full documentation at CTAN 25/29 Andreas Herten | IKP 1 Seminar | 8 October 2015
  27. Mitglied der Helmholtz-Gemeinscha Using latexmk — Flags Invoke with latexmk

    -pdf document.tex Automatically detects biblatex (/biber ) Useful flags -c Cleans up all files -pv Previews the PDF a er generating -pvc Preview continuously -f Force processing despite errors -shell-escape Allow calling shell programs (e.g. for minted) -lualatex or -xelatex Use the respectife program for processing file 26/29 Andreas Herten | IKP 1 Seminar | 8 October 2015
  28. Mitglied der Helmholtz-Gemeinscha Using latexmk — Makefile Since latexmk is

    like make, there are Makefile-equivalents: .latexmkrc! Steering file in the document’s directory (and/or in $HOME ) Useful options $pdf_mode = 1; PDFs as Output $recorder = 1; Use .fls file to optimize watched files $bibtex_use = 2; Run biber without testing for .bib file Glossary Generate glossaries automatically! A set of commands, included in appendix more Example rcfiles at CTAN 27/29 Andreas Herten | IKP 1 Seminar | 8 October 2015
  29. Mitglied der Helmholtz-Gemeinscha Et Cetera memoir Best document class (CTAN)

    Looks great Many features already implemented in class (like sub-figures, ToC extension, dra -mode) Easily customizable style microtype Excellent typesetting (but slow) Micro-manages characters, white-space, and words Look at documentation for an example (CTAN) xfrac For inline fractions, like 1⁄2 (CTAN) pdflscape Rotate PDF page for landscape pages (CTAN) multicol, multirow Multiple columns and rows for tables (CTAN col, row) todonotes Notes, markings, and other todo annotations (CTAN) 28/29 Andreas Herten | IKP 1 Seminar | 8 October 2015
  30. Mitglied der Helmholtz-Gemeinscha Summary Most important packages for us: siunitx

    and hepnames Use BibLaTex instead of BibTex glossaries for managing acronyms André and I created a template including most of the features Slides will be emailed! Rene installed most of package on institute’s computers Thank you! 29/29 Andreas Herten | IKP 1 Seminar | 8 October 2015
  31. Mitglied der Helmholtz-Gemeinscha A 30/29 Andreas Herten | IKP 1

    Seminar | 8 October 2015
  32. Mitglied der Helmholtz-Gemeinscha Using minted at IKP 1 Use pip

    to install highlighting tool Pygments into userspace pip install --user Pygments 2 Add according local binary location to $PATH export PATH=~/.local/bin:$PATH 3 Typset document with correct flags latexmk -pdf -shell-escape document.tex Try it out, e.g. with this example 31/29 Andreas Herten | IKP 1 Seminar | 8 October 2015
  33. Mitglied der Helmholtz-Gemeinscha Source Code for Feynman Diagram See Slide

    12 for the picture. \begin{fmffile}{simple_labels} \begin{fmfgraph*}(120,50) \fmfleft{i1,i2} \fmfright{o1,o2} \fmflabel{$\Pelectron$}{i1} \fmflabel{$\APelectron$}{i2} \fmflabel{$\APelectron,\APmuon$}{o1} \fmflabel{$\Pelectron,\APmuon$}{o2} \fmflabel{$i\sqrt{\alpha}$}{v1} \fmflabel{$i\sqrt{\alpha}$}{v2} \fmf{fermion}{i1,v1,i2} \fmf{fermion}{o1,v2,o2} \fmf{photon,label=$\Pgamma,,\PZ^0$}{v1,v2} \end{fmfgraph*} \end{fmffile} 32/29 Andreas Herten | IKP 1 Seminar | 8 October 2015
  34. Mitglied der Helmholtz-Gemeinscha LaTeX Code for booktabs Sample \begin{tabular}{SSSSc} \toprule

    {$m$} & {$X(m)$} & {$\frac{X(m)}{23}$} & {$\varphi(m)\ /\ ^{\circ}$} & Random Formula \\ → \midrule 1 & 16.128 & 1.402 & -146.6 & $F = m \cdot a$ \\ 2 & 3.442 & 0.299 & 133.2 & $\sigma_x \sigma_p \ge \frac{\hbar}{2}$ \\ → 3 & 1.826 & 0.159 & 168.5 & $i \hbar \frac{\partial}{\partial t}\Psi(\mathbf{r},t) = H \Psi(\mathbf{r},t)$ \\ → 4 & 0.993 & 0.086 & 25.6 & $\nabla \times \mathbf{B} = \mu_0\left(\mathbf{J} + \varepsilon_0 \frac{\partial \mathbf{E}} {\partial t} \right)$ \\[2mm] → → 5 & 1.29 & 0.112 & -175.6 \\ 6 & 0.483 & 0.042 & 22.3 \\ 7 & 0.766 & 0.067 & 141.6 \\ 8 & 0.624 & 0.054 & -35.7 \\ \bottomrule \end{tabular} 33/29 Andreas Herten | IKP 1 Seminar | 8 October 2015
  35. Mitglied der Helmholtz-Gemeinscha .latexmkrc for glossaries add_cus_dep(’glo’, ’gls’, 0, ’run_makeglossaries’);

    add_cus_dep(’acn’, ’acr’, 0, ’run_makeglossaries’); sub run_makeglossaries { if ( $silent ) { system "makeglossaries -q ’$_[0]’"; } else { system "makeglossaries ’$_[0]’"; }; } push @generated_exts, ’glo’, ’gls’, ’glg’, ’glsdefs’; push @generated_exts, ’acn’, ’acr’, ’alg’; $clean_ext .= ’ %R.ist %R.xdy’; 34/29 Andreas Herten | IKP 1 Seminar | 8 October 2015