dotfiles

My personal shell configs and stuff
git clone git://git.alex.balgavy.eu/dotfiles.git
Log | Files | Refs | Submodules | README | LICENSE

tex.snippets (7116B)


      1 # vim: foldmethod=marker foldlevel=0 expandtab softtabstop=2 shiftwidth=2:
      2 # Define math context {{{
      3 global !p
      4 texMathZones = ['texMathZone'+x for x in ['A', 'AS', 'B', 'BS', 'C',
      5 'CS', 'D', 'DS', 'E', 'ES', 'F', 'FS', 'G', 'GS', 'H', 'HS', 'I', 'IS',
      6 'J', 'JS', 'K', 'KS', 'L', 'LS', 'DS', 'V', 'W', 'X', 'Y', 'Z']]
      7 
      8 texIgnoreMathZones = ['texMathText']
      9 
     10 texMathZoneIds = vim.eval('map('+str(texMathZones)+", 'hlID(v:val)')")
     11 texIgnoreMathZoneIds = vim.eval('map('+str(texIgnoreMathZones)+", 'hlID(v:val)')")
     12 
     13 ignore = texIgnoreMathZoneIds[0]
     14 
     15 def math():
     16     synstackids = vim.eval("synstack(line('.'), col('.') - (col('.')>=2 ? 1 : 0))")
     17     try:
     18         first = next(
     19             i for i in reversed(synstackids)
     20             if i in texIgnoreMathZoneIds or i in texMathZoneIds
     21         )
     22         return first != ignore
     23     except StopIteration:
     24         return False
     25 endglobal
     26 # }}}
     27 
     28 # Skeletons {{{1
     29 snippet skel "Assignment skeleton" b
     30 \documentclass[12pt,a4paper,oneside,fleqn,notitlepage]{article}
     31 \usepackage{amsmath}
     32 \usepackage{amssymb}
     33 \usepackage[left=1in, right=1in, top=1in, bottom=1in]{geometry}
     34 
     35 \usepackage{fancyhdr}
     36 \setlength{\headheight}{15.2pt}
     37 \pagestyle{fancyplain}
     38 \lhead{\today}
     39 \rhead{${1:class name}}
     40 
     41 \title{${2:assignment}}
     42 \author{Alexander Balgavy}
     43 \date{}
     44 
     45 \begin{document}
     46   \maketitle
     47   $0
     48 \end{document}
     49 endsnippet
     50 
     51 snippet skel "Academic paper" b
     52 \documentclass[10pt,notitlepage]{article}
     53 \usepackage[a4paper, top=0.6in, left=0.6in, right=0.6in, bottom=0.6in]{geometry}
     54 \usepackage[utf8]{inputenc}
     55 \usepackage[english]{babel}
     56 \usepackage{hyperref}
     57 \usepackage{csquotes}
     58 \usepackage[style=ieee]{biblatex}
     59 \usepackage{amsmath}
     60 \usepackage{amssymb}
     61 \usepackage{graphicx}
     62 \usepackage{caption}
     63 \usepackage{subcaption}
     64 
     65 \graphicspath{{${1:image directory}}}
     66 \addbibresource{references.bib}
     67 
     68 \title{
     69   {${2:title}}\\
     70   {\large ${3:institution}}
     71 }
     72 \author{
     73   ${4:author}
     74   \and ${5:second author}
     75 }
     76 \date{\today}
     77 
     78 \begin{document}
     79   \maketitle
     80 
     81   \begin{abstract}
     82     This is an abstract.
     83   \end{abstract}
     84 
     85   \input{introduction}
     86   \input{background}
     87   \input{method}
     88   \input{results}
     89   \input{discussion}
     90   \input{conclusion}
     91 
     92   \printbibliography
     93 
     94   \input{appendix}
     95 \end{document}
     96 endsnippet
     97 
     98 snippet front "Front matter" b
     99 \title{$1}
    100 \author{$2}
    101 endsnippet
    102 # }}}1
    103 
    104 # Environments {{{
    105 snippet ul "unordered list" b
    106 \begin{itemize}
    107   \item $1
    108   $2
    109 \end{itemize}
    110 endsnippet
    111 
    112 snippet ol "ordered list" b
    113 \begin{enumerate}
    114   \item $1
    115   $2
    116 \end{enumerate}
    117 endsnippet
    118 
    119 snippet - "item in list" b
    120 \item $1
    121 $2
    122 endsnippet
    123 
    124 snippet beg "begin{} / end{}" b
    125 \begin{$1}
    126   $0
    127 \end{$1}
    128 endsnippet
    129 
    130 snippet ;1 "section{}" b
    131 \section{$1}
    132 $0
    133 endsnippet
    134 
    135 snippet ;2 "subsection{}" b
    136 \subsection{$1}
    137 $0
    138 endsnippet
    139 
    140 snippet ;3 "subsubsection{}" b
    141 \subsubsection{$1}
    142 $0
    143 endsnippet
    144 
    145 snippet mk "Inline math" w
    146 $${1}$`!p
    147 if t[2] and t[2][0] not in [',', '.', '?', '-', ' ']:
    148     snip.rv = ' '
    149 else:
    150     snip.rv = ''
    151 `$2
    152 endsnippet
    153 
    154 snippet dm "Displayed math" w
    155 \[
    156 $1
    157 \] $0
    158 endsnippet
    159 
    160 snippet table "Table" w
    161 \begin{table}[h]
    162   \centering
    163   \vspace{1em}
    164   \renewcommand{\arraystretch}{1.5}
    165   \begin{tabular}{| l | c | r |}
    166     \hline
    167     \textbf{${1:heading}} & \textbf{${2:heading}} & \textbf{${3:heading}} \\\\ \hline
    168     ${4:cell} & ${5:cell} & ${6:cell} \\\\ \hline
    169     $0 \\\\ \hline
    170   \end{tabular}
    171   \renewcommand{\arraystretch}{1}
    172   \vspace{1em}
    173   \caption{table}
    174   \label{tab:whataver}
    175 \end{table}
    176 endsnippet
    177 
    178 snippet fig "Figure" b
    179 \begin{figure}[h]
    180   \centering
    181   \includegraphics[width=\textwidth]{${1:/path/to/file}}
    182   \caption{${2:caption}}
    183   \label{fig:${3:internal reference}}
    184 \end{figure}
    185 endsnippet
    186 
    187 snippet fig "Subfigures" b
    188 \begin{figure}
    189      \centering
    190      \begin{subfigure}[b]{0.3\textwidth}
    191          \centering
    192          \includegraphics[width=\textwidth]{${1:/path/to/first.jpg}}
    193          \caption{${2:caption}}
    194          \label{fig:${3:internal label}}
    195      \end{subfigure}
    196      \hfill
    197      \begin{subfigure}[b]{0.3\textwidth}
    198          \centering
    199          \includegraphics[width=\textwidth]{${4:/path/to/second}}
    200          \caption{${5:caption}}
    201          \label{fig:${6:internal label}}
    202      \end{subfigure}
    203      \hfill
    204      \begin{subfigure}[b]{0.3\textwidth}
    205          \centering
    206          \includegraphics[width=\textwidth]{${7:/path/to/third}}
    207          \caption{${8:caption}}
    208          \label{fig:${9:internal label}}
    209      \end{subfigure}
    210         \caption{${10:overall caption}}
    211         \label{fig:${11:overall internal label}}
    212 \end{figure}
    213 endsnippet
    214 # }}}
    215 
    216 # Word processing {{{
    217 snippet i "italic text" w
    218 \textit{$1}
    219 endsnippet
    220 
    221 snippet b "bold text" w
    222 \textbf{$1}
    223 endsnippet
    224 
    225 snippet sc "small caps" w
    226 \textsc{$1}
    227 endsnippet
    228 
    229 snippet pre "preformatted text" w
    230 \texttt{$1}
    231 endsnippet
    232 
    233 snippet " "quote" wA
    234 \`\`$1''$0
    235 endsnippet
    236 
    237 snippet ' "single quote" wA
    238 \`$1'$0
    239 endsnippet
    240 
    241 snippet par "Paragraph heading" b
    242 \paragraph{$1}$0
    243 endsnippet
    244 
    245 snippet c "Cite" w
    246 \cite{$1}$0
    247 endsnippet
    248 
    249 snippet tc "Cite (text)" w
    250 \textcite{$1}$0
    251 endsnippet
    252 
    253 snippet ca "Cite with author" w
    254 \citeauthor{$1} \cite{$1}$0
    255 endsnippet
    256 
    257 # }}}
    258 
    259 # Math {{{
    260 context "math()"
    261 snippet '([A-Za-z])(\d)' "auto subscript" wrA
    262 `!p snip.rv = match.group(1)`_`!p snip.rv = match.group(2)`
    263 endsnippet
    264 
    265 context "math()"
    266 snippet '([A-Za-z])_(\d\d)' "auto subscript2" wrA
    267 `!p snip.rv = match.group(1)`_{`!p snip.rv = match.group(2)`}
    268 endsnippet
    269 
    270 context "math()"
    271 priority 10
    272 snippet "bar" "bar" ri
    273 \overline{$1}$0
    274 endsnippet
    275 
    276 context "math()"
    277 priority 100
    278 snippet "([a-zA-Z])-bar" "bar" riA
    279 \overline{`!p snip.rv=match.group(1)`}
    280 endsnippet
    281 
    282 context "math()"
    283 priority 10
    284 snippet "hat" "hat" ri
    285 \hat{$1}$0
    286 endsnippet
    287 
    288 context "math()"
    289 priority 100
    290 snippet "([a-zA-Z])-hat" "hat" riA
    291 \hat{`!p snip.rv=match.group(1)`}
    292 endsnippet
    293 
    294 context "math()"
    295 snippet _{ "underbrace"
    296 \underbrace{${1:expression}}_\text{${2:annotation}}
    297 endsnippet
    298 
    299 context "math()"
    300 snippet ^{ "overbrace"
    301 \overbrace{${1:expression}}^\text{${2:annotation}}
    302 endsnippet
    303 
    304 context "math()"
    305 snippet // "Fraction" iA
    306 \\frac{$1}{$2}$0
    307 endsnippet
    308 
    309 context "math()"
    310 snippet '((\d+)|(\d*)(\\)?([A-Za-z]+)((\^|_)(\{\d+\}|\d))*)/' "Fraction" wrA
    311 \\frac{`!p snip.rv = match.group(1)`}{$1}$0
    312 endsnippet
    313 
    314 priority 1000
    315 context "math()"
    316 snippet '^.*\)/' "() Fraction" wrA
    317 `!p
    318 stripped = match.string[:-1]
    319 depth = 0
    320 i = len(stripped) - 1
    321 while True:
    322     if stripped[i] == ')': depth += 1
    323     if stripped[i] == '(': depth -= 1
    324     if depth == 0: break;
    325     i -= 1
    326 snip.rv = stripped[0:i] + "\\frac{" + stripped[i+1:-1] + "}"
    327 `{$1}$0
    328 endsnippet
    329 
    330 context "math()"
    331 snippet * "×" wA
    332 \times$0
    333 endsnippet
    334 
    335 context "math()"
    336 snippet \given "P(A | B)" wA
    337 \given{$1}{$2}$0
    338 endsnippet
    339 # }}}
    340 
    341 # Custom commands {{{
    342 snippet cmd "\given{A}{B} - (A|B)" b
    343 % \given{A}{B} ("A given B") %
    344 \makeatletter
    345 \newcommand{\@givenstar}[2]{\left(#1\;\middle|\;#2\right)}
    346 \newcommand{\@givennostar}[3][]{#1(#2\;#1|\;#3#1)}
    347 \newcommand{\given}{\@ifstar\@givenstar\@givennostar}
    348 \makeatother
    349 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    350 endsnippet
    351 snippet cmd "subsection a), b), c)" b
    352 % lettered subsections %
    353 \renewcommand\thesubsection{\thesection.\alph{subsection}}
    354 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    355 endsnippet
    356 # }}}