init-latex.el 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. ;;; LaTeX
  2. ;;; WARNING: This file is loaded from a hook.
  3. ;;; TODO: `beginning-of-defun'/`end-of-defun' should go to next section.
  4. ;;; We use the TeX setup.
  5. (require 'init-tex)
  6. (require 'latex-pretty-symbols nil t)
  7. ;;; Since current buffer is a LaTeX one, we can use `local-set-key'.
  8. (ambrevar/local-set-keys
  9. "C-c m" 'ambrevar/latex-article
  10. "C-c l" 'ambrevar/latex-lstinline
  11. "C-c o" 'ambrevar/latex-orgtbl)
  12. (dolist (fun '(turn-on-orgtbl ambrevar/turn-on-skeleton-markers))
  13. ;; Since this file is loaded from `latex-mode-hook', these functions will not
  14. ;; be applied to the current buffer. We do it manually.
  15. (funcall fun)
  16. (add-hook 'latex-mode-hook fun))
  17. ;;; latex-math-preview
  18. ;;; Needs dvipng.
  19. ;;; With TeXlive, the following packages are needed: psnfss, symbol, zapfding
  20. (when (and (executable-find "dvipng") (require 'latex-math-preview nil t))
  21. (local-set-key (kbd "C-c p") 'latex-math-preview-expression)
  22. (local-set-key (kbd "C-c j") 'latex-math-preview-insert-symbol)
  23. (local-set-key (kbd "C-c C-j") 'latex-math-preview-last-symbol-again)
  24. ;; Any color package should be filtered out as they will have unexpected impact on coloring.
  25. (add-to-list 'latex-math-preview-usepackage-filter-alist '("color")))
  26. ;;; For some unknown reasons, `skeleton-end-hook' is set to nil in tex-mode.
  27. ;; (dolist (fun '(latex-set-compiler turn-on-orgtbl ambrevar/turn-on-skeleton-markers))
  28. ;; ;; Since this file is loaded from `latex-mode-hook', these functions will not
  29. ;; ;; be applied to the current buffer. We do it manually.
  30. ;; (funcall fun)
  31. ;; (add-hook 'latex-mode-hook fun))
  32. (with-eval-after-load 'latex ; AUCTeX
  33. (advice-add 'LaTeX-insert-item :before (lambda () (end-of-line)))
  34. (with-eval-after-load 'font-latex
  35. (set-face-foreground 'font-latex-sectioning-5-face "white"))
  36. ;; TODO: Add "tabu" and "longtabu" to environment list.
  37. (require 'tex-fold)
  38. (add-hook 'LaTeX-mode-hook 'TeX-fold-mode)
  39. (add-hook 'find-file-hook 'TeX-fold-buffer t)))
  40. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  41. ;;; Skeletons
  42. ;;; TODO: implement orgtbl directly with latex tables and remove this skel.
  43. (define-skeleton ambrevar/latex-orgtbl
  44. "Insert orgtbl skel."
  45. "Table name: "
  46. > "\\begin{center}" \n
  47. "% BEGIN RECEIVE ORGTBL " str \n
  48. "% END RECEIVE ORGTBL " str \n
  49. "\\end{center}" > \n
  50. "\\begin{comment}" \n
  51. "#+ORGTBL: SEND " str " orgtbl-to-latex" \n
  52. "| " @ _ " |" \n
  53. "%$" \n
  54. "\\end{comment}" > \n @)
  55. (define-skeleton ambrevar/latex-lstinline
  56. "Insert inline listing." nil
  57. "\\lstinline @" @ _ "@" @)
  58. (define-skeleton ambrevar/latex-graphics
  59. "Insert centered picture."
  60. nil
  61. > "\\begin{center}" \n
  62. "\\includegraphics[width=" @ (skeleton-read "Width: " "\\linewidth") "]{" @ _ "}" \n
  63. "\\end{center}" > \n @)
  64. (define-skeleton ambrevar/latex-article
  65. "Insert article template."
  66. nil
  67. > "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  68. \\documentclass[10pt,a4paper]{article}
  69. \\usepackage[utf8]{inputenc}
  70. \\usepackage[T1]{fontenc}
  71. \\usepackage{lmodern}
  72. \\usepackage{marvosym}
  73. \\usepackage{textcomp}
  74. \\DeclareUnicodeCharacter{20AC}{\\EUR{}}
  75. \\DeclareUnicodeCharacter{2260}{\\neq}
  76. \\DeclareUnicodeCharacter{2264}{\\leq}
  77. \\DeclareUnicodeCharacter{2265}{\\geq}
  78. \\DeclareUnicodeCharacter{22C5}{\\cdot}
  79. \\DeclareUnicodeCharacter{A0}{~}
  80. \\DeclareUnicodeCharacter{B1}{\\pm}
  81. \\DeclareUnicodeCharacter{D7}{\\times}
  82. %%=============================================================================
  83. %% Packages
  84. \\usepackage{amsmath,amssymb,amsfonts}
  85. % \\usepackage{comment}
  86. \\usepackage{geometry}
  87. % \\usepackage{graphicx}
  88. % \\usepackage{lipsum}
  89. % \\usepackage{needspace}
  90. \\usepackage[svgnames]{xcolor}
  91. \\usepackage{xspace}
  92. %%=============================================================================
  93. %% Properties
  94. \\title{" @ (skeleton-read "Title: " "Title") "}
  95. \\author{" @ (skeleton-read "Author: " "P.~\\textsc{Neidhardt}") "}
  96. \\makeatletter
  97. \\let\\thetitle\\@title
  98. \\let\\theauthor\\@author
  99. \\let\\thedate\\@date
  100. \\makeatother" \n
  101. '(setq latex-setup-list '(ambrevar/latex-preamble-aliases ambrevar/latex-preamble-tables ambrevar/latex-preamble-listing))
  102. '(while (and latex-setup-list
  103. (= (read-key (concat "Insert " (symbol-name (car latex-setup-list)) "? (y)")) ?y))
  104. (newline-and-indent)
  105. (funcall (pop latex-setup-list))
  106. (newline-and-indent))
  107. \n
  108. "%%=============================================================================
  109. %% Babel (load near the end before 'hyperref')
  110. \\usepackage[english]{babel}
  111. %\\iflanguage{french}{
  112. %}{"
  113. "%% Narrow items" \n
  114. "%\\newlength{\\wideitemsep}" \n
  115. "%\\setlength{\\wideitemsep}{.5\\itemsep}" \n
  116. "%\\addtolength{\\wideitemsep}{-7pt}" \n
  117. "%\\let\\olditem\\item" \n
  118. "%\\renewcommand{\\item}{\\setlength{\\itemsep}{\\wideitemsep}\\olditem}"\n
  119. "%}" > \n
  120. "
  121. %%=============================================================================
  122. %% Formatting
  123. % \\usepackage{parskip}
  124. % \\setlength{\\parindent}{15pt}
  125. % \\setlength{\\parskip}{5pt plus 4pt}
  126. % \\renewcommand{\\thefigure}{\\arabic{section}.\\arabic{figure}}
  127. \\renewcommand{\\arraystretch}{1.4}
  128. % \\renewcommand{\\familydefault}{\\sfdefault}
  129. %% Header
  130. % \\usepackage{fancyhdr}
  131. % \\setlength{\\headheight}{15.2pt}
  132. % \\pagestyle{fancy}
  133. % \\lhead{\\thetitle}
  134. % \\rhead{\\theauthor}" > \n
  135. "
  136. %%==============================================================================
  137. %% Hyperref (load last)
  138. \\usepackage[]{hyperref}
  139. \\hypersetup{"
  140. "colorlinks=true," \n
  141. "citecolor=DarkRed," \n
  142. "linkcolor=DarkRed," \n
  143. "linktoc=page," \n
  144. "urlcolor=blue," \n
  145. "}" > \n
  146. "
  147. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  148. \\begin{document}
  149. \\maketitle
  150. \\vfill
  151. \\thispagestyle{empty}
  152. \\tableofcontents
  153. \\clearpage" \n
  154. > @ _ \n \n
  155. "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  156. \\end{document}
  157. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  158. " \n)
  159. (define-skeleton ambrevar/latex-preamble-aliases
  160. "Insert setup template."
  161. nil
  162. > "%%=============================================================================
  163. %% Aliases
  164. \\let\\latexbak\\LaTeX
  165. \\renewcommand{\\LaTeX}{\\textrm{\\latexbak}\\xspace}
  166. \\let\\texbak\\TeX
  167. \\renewcommand{\\TeX}{\\textrm{\\texbak}\\xspace}
  168. \\def\\unix{\\textsc{Unix}\\xspace}
  169. \\def\\ie{\\textsl{i.e.}\\xspace}
  170. \\def\\eg{\\textsl{e.g.}\\xspace}" \n)
  171. (define-skeleton ambrevar/latex-preamble-tables
  172. "Insert setup template."
  173. nil
  174. > "%%==============================================================================
  175. %% Tables
  176. \\usepackage{longtable}
  177. \\usepackage{tabu}" \n)
  178. (define-skeleton ambrevar/latex-preamble-graphics
  179. "Insert setup template."
  180. nil
  181. > "%%==============================================================================
  182. %% Graphics
  183. \\usepackage{tikz}
  184. \\newcommand{\\fancybox}[1]{" \n
  185. "\\begin{tikzpicture}" \n
  186. "\\node[draw,rounded corners]{#1};" \n
  187. "\\end{tikzpicture}" > \n
  188. "}" > \n)
  189. (define-skeleton ambrevar/latex-preamble-listing
  190. "Insert listing setup template."
  191. ;; WARNING: we need to put a '-' at the very end so that the cursor will end
  192. ;; there. Otherwise it will be placed at the beginning. This is due to some
  193. ;; unicode or escape characters in the literate array, which `skeleton-insert'
  194. ;; does not seem to parse correctly.
  195. nil
  196. > "%%=============================================================================
  197. %% Listings
  198. \\usepackage{listings}
  199. %% Source code.
  200. \\lstdefinestyle{custom}{" \n
  201. "% numbers=left," \n
  202. "belowcaptionskip=1\\baselineskip," \n
  203. "breaklines=true," \n
  204. "frame=L," \n
  205. "xleftmargin=\\parindent," \n
  206. "% framexleftmargin=\\parindent," \n
  207. "language=C," \n
  208. "showstringspaces=false," \n
  209. "basicstyle=\\footnotesize\\ttfamily," \n
  210. "keywordstyle=\\bfseries\\color{green!40!black}," \n
  211. "commentstyle=\\itshape\\color{purple!40!black}," \n
  212. "identifierstyle=\\color{blue}," \n
  213. "stringstyle=\\color{orange}," \n
  214. "numberstyle=\\ttfamily," \n
  215. "}" > \n
  216. "
  217. \\lstset{escapechar=,style=custom," \n
  218. "literate=" \n
  219. "{á}{{\\'a}}1 {é}{{\\'e}}1 {í}{{\\'i}}1 {ó}{{\\'o}}1 {ú}{{\\'u}}1" \n
  220. "{Á}{{\\'A}}1 {É}{{\\'E}}1 {Í}{{\\'I}}1 {Ó}{{\\'O}}1 {Ú}{{\\'U}}1" \n
  221. "{à}{{\\`a}}1 {è}{{\\'e}}1 {ì}{{\\`i}}1 {ò}{{\\`o}}1 {ù}{{\\`u}}1" \n
  222. "{À}{{\\`A}}1 {È}{{\\'E}}1 {Ì}{{\\`I}}1 {Ò}{{\\`O}}1 {Ù}{{\\`U}}1" \n
  223. "{ä}{{\\\"a}}1 {ë}{{\\\"e}}1 {ï}{{\\\"i}}1 {ö}{{\\\"o}}1 {ü}{{\\\"u}}1" \n
  224. "{Ä}{{\\\"A}}1 {Ë}{{\\\"E}}1 {Ï}{{\\\"I}}1 {Ö}{{\\\"O}}1 {Ü}{{\\\"U}}1" \n
  225. "{â}{{\\^a}}1 {ê}{{\\^e}}1 {î}{{\\^i}}1 {ô}{{\\^o}}1 {û}{{\\^u}}1" \n
  226. "{Â}{{\\^A}}1 {Ê}{{\\^E}}1 {Î}{{\\^I}}1 {Ô}{{\\^O}}1 {Û}{{\\^U}}1" \n
  227. "{œ}{{\\oe}}1 {Œ}{{\\OE}}1 {æ}{{\\ae}}1 {Æ}{{\\AE}}1 {ß}{{\\ss}}1" \n
  228. "{ç}{{\\c c}}1 {Ç}{{\\c C}}1 {ø}{{\\o}}1 {å}{{\\r a}}1 {Å}{{\\r A}}1" \n
  229. "{€}{{\\EUR}}1 {£}{{\\pounds}}1" \n
  230. "}" > \n
  231. "
  232. \\newcommand{\\includecode}[2][custom]{" \n
  233. "\\lstinputlisting[caption=#2, escapechar=, style=#1]{#2}}" \n
  234. "\\let\\verbatim\\relax%" \n
  235. "\\lstnewenvironment{verbatim}[1][]{\\lstset{style=custom}}{}%" > \n -)
  236. (provide 'init-latex)