Org Mode
1. Use svg image for html and pdf for LaTeX
Add this line in the org file to create a macro. Then use it as follows (don't add the extension at the end):
{{{img(path/to/image)}}}
2. Source block without babel backend
When using source blocks that don't have a babel backend add the parameter :exports code
to prevent org-mode from complaining about the backend being not found. Because even though the :eval no-export is present, org babel still tries to parse the params and do some stuff with the source block.
So instead of
#+begin_src json { "name" : "Bibek Panthi", "species" : "Homo sapiens" } #+end_src
do
#+begin_src json :exports code { "name" : "Bibek Panthi", "species" : "Homo sapiens" } #+end_src
3. Literate DevOps
https://howardism.org/Technical/Emacs/literate-devops.html
You can run org babel sh source blocks on remote systems using :dir parameter.
Consider the following:
#+begin_src sh :dir /etc :results raw :wrap verbatim head passwd #+end_src
This is same as:
#+begin_src sh :results raw :wrap verbatim head /etc/passwd #+end_src
The :dir parameter accepts anything that emacs accepts for opening files, including paths opened by tramp. For example, if you have a server server.com and you open some file by M-x find-file /ssh:server.com:/home/bpanthi977/test.org. Then in similar way, you can specify :dir parameter to work on a remote directory:
#+begin_src sh :dir /ssh:server.com:/etc :wrap verbatim :results raw head passwd #+end_src #+begin_verbatim root:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin sync:x:5:0:sync:/sbin:/bin/sync shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown halt:x:7:0:halt:/sbin:/sbin/halt mail:x:8:12:mail:/var/spool/mail:/sbin/nologin operator:x:11:0:operator:/root:/sbin/nologin #+end_verbatim
4. Show headings in beamer
Add the following to the top of org file:
#+begin_export latex
\\AtBeginSection[]{
\\begin{frame}
\\vfill
\\centering
\\begin{beamercolorbox}[sep=8pt,center,shadow=true,rounded=true]{title}
\\usebeamerfont{title}\\insertsectionhead\\par%
\\end{beamercolorbox}
\\vfill
\\end{frame}
}
#+end_export
5. Add section break after each section
#+begin_export latex
\let\oldsection\section
\renewcommand\section{\clearpage\oldsection}
\clearpage
#+end_export
6. No section numbering in latex export
#+BEGIN_EXPORT latex
\let\oldsection\section
\renewcommand\section{\clearpage\oldsection*}
\clearpage
#+END_EXPORT
7. Colorful Listings
#+begin_export latex
\usepackage{listings}
\usepackage{color}
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}
\lstdefinestyle{mystyle}{
backgroundcolor=\color{backcolour},
commentstyle=\color{codegreen},
keywordstyle=\color{magenta},
numberstyle=\tiny\color{codegray},
stringstyle=\color{codepurple},
basicstyle=\ttfamily\footnotesize,
breakatwhitespace=false,
breaklines=true,
captionpos=b,
keepspaces=true,
numbers=left,
numbersep=5pt,
showspaces=false,
showstringspaces=false,
showtabs=false,
tabsize=2,
upquote=true
}
\lstset{style=mystyle}
#+end_export
9. Show image in org buffer but not in exports
For this you can wrap the image link/attachment inside a drawer. And then configure emacs to not export that drawer.
For example:
:noexport: attachment:image.png :end:
It can be configured globally by setting the value of
org-export-with-drawers. It is a list of drawers to be exported or
if the list starts with not, it the list of drawers to not export.
(setq org-export-with-drawers '(not "noexport" "logbook"))
The default value of org-export-with-drawers is (not "LOGBOOK")
that's why in above examples we keep that value too and also specify
noexport drawers to be not exported.
Alternatively, you can specify d:nil to prevent explorting any
drawers.