Permalink
Cannot retrieve contributors at this time
Fetching contributors…
| # -*- mode: emacs-lisp -*- | |
| # key: template | |
| # name: Template (my skeleton for various LaTeX documents) | |
| # type: command | |
| # -- | |
| ;; Snippet format: <https://capitaomorte.github.io/yasnippet/snippet-development.html>. | |
| ;; Useful LaTeX links: | |
| ;; * Nice font combinations: <http://tex.stackexchange.com/questions/9533/what-best-combination-of-fonts-for-serif-sans-and-mono-do-you-recommend>. | |
| ;; * Some style tips: <http://tex.stackexchange.com/questions/82376/why-are-these-commands-considered-as-bad-practice>. | |
| (require 'cl-lib) ; Used: cl-flet. | |
| (let* ((yas-good-grace nil) ; Don't catch errors. | |
| (engine (completing-read "TeX engine: " | |
| '("XeTeX" "pdfTeX") | |
| nil nil nil nil "XeTeX")) | |
| (document-class (completing-read "Document class: " | |
| '("scrartcl" "article" "amsart" "letter") | |
| nil nil nil nil "article")) | |
| (engine-auctex (pcase engine | |
| ("XeTeX" "xetex") | |
| ("pdfTeX" "default"))) | |
| (document-body "`yas-selected-text`$0")) | |
| (cl-flet* ((smart-comment (line) | |
| (if (or (string-prefix-p "%" line) | |
| (string-empty-p line)) | |
| line | |
| (concat "%" line))) | |
| (join-lines (function lines) | |
| (let ((non-nil-lines (delq nil lines))) | |
| (when non-nil-lines | |
| (mapconcat function non-nil-lines "\n")))) | |
| (latex-block (transformation &rest lines) | |
| (pcase transformation | |
| (`ignore nil) | |
| (`smart-comment (join-lines #'smart-comment lines)) | |
| (`comment (join-lines (lambda (line) (concat "%" line)) lines)) | |
| (`verbatim (join-lines #'identity lines))))) | |
| (yas-expand-snippet | |
| (latex-block | |
| 'verbatim | |
| ;; Warnings. | |
| "\\RequirePackage[l2tabu, orthodox]{nag} % Style warnings in .log file (grep for \"nag\")." | |
| "" | |
| ;; Document type, margins, etc. | |
| (pcase document-class | |
| ("scrartcl" | |
| "\\documentclass[12pt, a4paper, parskip=full]{scrartcl} % Margins: DIV=<number> (larger means more content; default for 12pt is 12). Periods after section numbers: numbers=endperiod.") | |
| ((or "article" "amsart" "letter") | |
| (concat "\\documentclass[12pt]{" document-class "}")) | |
| (_ | |
| (concat "\\documentclass{" document-class "}"))) | |
| (when (not (string-prefix-p "scr" document-class)) | |
| (latex-block 'verbatim | |
| "\\usepackage[a4paper]{geometry} % Setting margins: \"top=5cm\" (later options have more priority)." | |
| "\\usepackage{parskip} % Space instead of indent between paragraphs.")) | |
| "\\usepackage{microtype} % Better typography." ; No longer needs to be loaded after fonts and babel (unless using "babel=true"). See <http://tex.stackexchange.com/questions/162137/loading-microtype-before-or-after-the-font>. | |
| "\\usepackage{enumitem} % Add features to \\`itemize' and \\`enumerate'." | |
| "" | |
| "% Alternative fonts." | |
| (latex-block 'smart-comment | |
| "\\usepackage{fontspec}" | |
| "\\setmainfont{Linux Libertine O} % Alternatives: Computer Modern (the default), TeX Gyre Pagella (with TeX Gyre Pagella Math), Cambria (with Cambria Math)." | |
| "\\setsansfont{Carlito} % Free replacement for Calibri. Alternatives: Linux Biolinum O, Open Sans (the default for scrartcl)." | |
| "\\setmonofont{Consolas} % Alternatives: DejaVu Sans Mono, Inconsolata." | |
| "\\setsansfont{Gillius ADF} % Free replacement for Gill Sans. Alternatives: Sans Guilt MB, Sans Guilt DB, Cabin, Lato." | |
| "") | |
| "% Suppress page numbers if there's only one page." | |
| "\\usepackage{zref-totpages}" | |
| "\\AtBeginDocument{\\ifnum\\ztotpages=1{\\pagenumbering{gobble}}\\fi}" | |
| "" | |
| "% Language." | |
| (if (equal engine "XeTeX") | |
| (latex-block 'verbatim | |
| "\\usepackage{polyglossia}" ; Just to be safe, load it near the beginning of the preamble (see <http://tex.stackexchange.com/questions/150788/should-babel-package-call-be-placed-at-the-end-of-the-preamble>). | |
| "\\setmainlanguage{${polish}}" | |
| "%\\setotherlanguage{${english}}") | |
| (latex-block 'verbatim "\\usepackage[${polish}, ${english}]{babel}")) | |
| (when (equal engine "pdfTeX") | |
| (latex-block 'verbatim | |
| "\\usepackage[utf8]{inputenc}" | |
| "\\usepackage[T1]{fontenc}")) | |
| "" | |
| "% Quotes (language-aware)." | |
| (latex-block 'verbatim | |
| "\\usepackage[autostyle]{csquotes} % Example: \\enquote{text}" | |
| "\\DeclareQuoteStyle{polish}{\\quotedblbase}{\\textquotedblright}[0.05em]{\\textquoteleft}{\\textquoteright}" | |
| "") | |
| "% Math." | |
| (latex-block 'verbatim | |
| "\\usepackage[all]{onlyamsmath} % Add improved math macros, disable standard ones." | |
| "\\usepackage{amsfonts} % E.g. \\`mathbb'.") | |
| "% Make \\`mathbb' work for numbers." | |
| (latex-block 'verbatim | |
| "\\usepackage{dsfont} % Blackboard bold that includes numbers. Requires \\`texlive-fonts-extra'." | |
| "\\usepackage{xstring} % For \\`IfInteger'." | |
| "\\let\\oldmathbb\\mathbb" | |
| "\\renewcommand{\\mathbb}[1]{\\IfInteger{#1}{\\mathds{#1}}{\\oldmathbb{#1}}}") | |
| "% Use bold instead of arrows for vectors." | |
| (latex-block 'smart-comment | |
| "\\let\\oldvec\\vec" | |
| "\\renewcommand{\\vec}[1]{\\boldsymbol{\\mathbf{#1}}}") | |
| "" | |
| "% Tables." | |
| ;; Overview of table packages: <http://tex.stackexchange.com/questions/12672/which-tabular-packages-do-which-tasks-and-which-packages-conflict>. | |
| (latex-block 'verbatim | |
| "\\usepackage{tabu} % Featureful replacement for \\`tabular'." | |
| "\\usepackage{booktabs} % Elegant tables (use \\\\{top,mid,bottom}rule instead of \\hline; no \\vline)." ; `booktabs' examples: <http://www.howtotex.com/packages/improve-your-tables-with-booktabs/>. | |
| "") | |
| "% Graphics." | |
| (latex-block 'verbatim | |
| "\\usepackage{graphicx} % See <https://www.sharelatex.com/learn/Inserting_Images>. Example: \\begin{figure}[h] \\centering \\includegraphics[width=0.5\\textwidth]{spiral} \\caption{Spiral.} \\label{fig:spiral} \\end{figure}" | |
| "\\usepackage{float} % For the \\`H' positioning specifier." | |
| "\\usepackage{grffile} % Correctly handle complex file names." | |
| "\\graphicspath{{images/}}" | |
| "\\newcommand{\\credit}[1]{\\par\\tiny\\textit{#1}}" | |
| "") | |
| "% Drawings." | |
| (latex-block 'verbatim | |
| "\\usepackage{tikz}" | |
| "\\usetikzlibrary{babel} % Fixes conflict with onlyamsmath (see <http://tex.stackexchange.com/questions/31860/conflict-onlyamsmath-and-tikz>)." | |
| "") | |
| "% Bibliography." | |
| (latex-block 'smart-comment | |
| "\\usepackage[backend=biber]{biblatex}" | |
| "\\addbibresource{`(when (buffer-file-name) (file-name-sans-extension (file-name-nondirectory (buffer-file-name))))`.bib}" | |
| "") | |
| "% Comments." | |
| (latex-block 'verbatim | |
| "\\usepackage[normalem]{ulem} % \\`normalem' -- don't change \\emph." | |
| "\\usepackage{color}" | |
| "\\makeatletter" | |
| "\\newcommand\\coloruwave[1][red]{\\bgroup\\markoverwith{\\lower3.5\\p@\\hbox{\\sixly\\textcolor{#1}{\\char58}}}\\ULon}" | |
| "\\font\\sixly=lasy6" | |
| "\\makeatother" | |
| "\\newcommand{\\fixme}[1]{\\coloruwave[red]{#1}}" | |
| "\\newcommand{\\comment}[1]{\\coloruwave[red]{[#1]}}" | |
| "\\usepackage{ifthen}" | |
| "\\newcommand{\\todo}[1]{\\comment{TODO\\ifthenelse{\\equal{#1}{}}{}{: }#1}}" | |
| "% Block comments (also for calling attention to document areas)." | |
| "\\usepackage{mdframed}" | |
| "\\newenvironment{blockComment}" | |
| "{\\begin{mdframed}[topline=false, leftline=true, bottomline=false, rightline=false, linecolor=red]}" | |
| "{\\end{mdframed}}" | |
| "%\\renewenvironment{blockComment}[1]{}{} % Temporarily disable." | |
| "") | |
| ;; Title, author, etc. | |
| (pcase document-class | |
| ("letter" (latex-block 'verbatim | |
| "\\signature{${`(user-full-name)`}}" | |
| "\\address{${}}")) | |
| (_ (latex-block 'verbatim | |
| "\\title{${Document title}}" | |
| "\\author{${`(user-full-name)`}}" | |
| "%\\date{}"))) | |
| "" | |
| ;; Document body. | |
| "\\begin{document}" | |
| (pcase document-class | |
| ("letter" (latex-block 'verbatim | |
| "\\begin{letter}{${Destination address}}" | |
| "\\opening{${Dear Sir or Madam,}}" | |
| "" | |
| document-body | |
| "" | |
| "\\closing{Yours Respectfully,}" | |
| "\\end{letter}")) | |
| (_ (latex-block 'verbatim | |
| "\\maketitle" | |
| "" | |
| document-body | |
| "" | |
| (latex-block 'smart-comment | |
| "% Bibliography." | |
| "\\nocite{*} % Show all sources (even uncited ones)." | |
| "\\printbibliography")))) | |
| "\\end{document}" | |
| "" | |
| ;; AUCTeX data. | |
| (when engine-auctex | |
| (latex-block 'verbatim | |
| "% Local Variables:" | |
| (concat "% TeX-engine: " engine-auctex) | |
| "% ispell-local-dictionary: \"polish\"" | |
| "% End:" | |
| "")))))) |