I have recently switched all my doc writing to org-mode. The outlining framework works for my flow and the markdown syntax allows me to write in rich text.
The default export options are, however, horrible. The default Latex template especially. The first paragraph is not indented but the rest are, the preform text blocks are cutoff at the right margin, the font is ugly, etc.
I did find a free template that I liked, but it was an elisp file. It has no instructions to install. How do I use it for exporting my documents?
This is more a matter of LaTeX customization than org-mode. The basics of e.g., using the koma classes rather than the default LaTeX classes are described in Tom Dye's document: http://orgmode.org/worg/org-tutorials/org-latex-export.html#orgheadline4 (note that the document describes the old exporter - pre-8.0 - but this particular section applies to the new exporter as well).
Alternatively, you can keep the default classes but change all the things you don't like by introducing explicit LaTeX customization in your org document. E.g., changing the font is just a matter of adding something like this to your document:
#+LATEX_HEADER: \usepackage{times}
Changing the default paragraph style can be done with
#+LATEX_HEADER: \usepackage{indentfirst}
and so on. Note that you have to know something about what LaTeX packages are available, what they do and how to install them, but that is definitely not an org-mode question.
You can define some global LaTeX class settings like this:
(setq org-export-latex-classes
(quote
(("article" "\\documentclass[11pt]{scrartcl}
\\usepackage[utf8]{inputenc}
\\usepackage[T1]{fontenc}
\\usepackage{graphicx}
\\usepackage{longtable}
\\usepackage{listings}
\\usepackage[ngerman]{babel}
\\usepackage{float}
\\usepackage{soul}
\\usepackage{amssymb}
\\usepackage{hyperref}"
("\\section{%s}" . "\\section{%s}")
("\\subsection{%s}" . "\\subsection{%s}")
("\\subsubsection{%s}" . "\\subsubsection{%s}")
("\\paragraph{%s}" . "\\paragraph{%s}")
("\\subparagraph{%s}" . "\\subparagraph{%s}")))
))
See also: The Org-article LaTeX class
Related
I have an orgmode document with a latex codeblock:
So:
#+BEGIN_SRC latex
Hello
#+END_SRC
But when I generate a pdf, I get:
How can I remove this "Latex" description, and have only "So: Hello" shown?
Thank you!
From the comment, I don't think that org-latex-classes is quite correct. In
particular, the \usepackage* bit doesn't look correct.
The C-h v for that variable states
Alist of LaTeX classes and associated header and structure.
If #+LATEX_CLASS is set in the buffer, use its value and the
associated information. Here is the structure of each cell:
(class-name
header-string
(numbered-section . unnumbered-section)
...)
The header string
-----------------
The HEADER-STRING is the header that will be inserted into the
LaTeX file. It should contain the \documentclass macro, and
anything else that is needed for this setup. To this header, the
following commands will be added:
- Calls to \usepackage for all packages mentioned in the
variables ‘org-latex-default-packages-alist’ and
‘org-latex-packages-alist’. Thus, your header definitions
should avoid to also request these packages.
- Lines specified via "#+LATEX_HEADER:" and
"#+LATEX_HEADER_EXTRA:" keywords.
If you need more control about the sequence in which the header
is built up, or if you want to exclude one of these building
blocks for a particular class, you can use the following
macro-like placeholders.
[DEFAULT-PACKAGES] \usepackage statements for default packages
[NO-DEFAULT-PACKAGES] do not include any of the default packages
[PACKAGES] \usepackage statements for packages
[NO-PACKAGES] do not include the packages
[EXTRA] the stuff from #+LATEX_HEADER(_EXTRA)
[NO-EXTRA] do not include #+LATEX_HEADER(_EXTRA) stuff
So a header like
\documentclass{article}
[NO-DEFAULT-PACKAGES]
[EXTRA]
\providecommand{\alert}[1]{\textbf{#1}}
[PACKAGES]
will omit the default packages, and will include the
#+LATEX_HEADER and #+LATEX_HEADER_EXTRA lines, then have a call
to \providecommand, and then place \usepackage commands based
on the content of ‘org-latex-packages-alist’.
So I don't think you should have that \packages* line in there. Also, you are
better off either using the custom interface to set this variable or put it as a
setq in your init file. I don't think there is any reason to have to load it
inside an eval-after-load call.
Use the org variables mentioned in the docs above to add/remove packages. You
need to be careful with this as I've found this to be one area org-mode can be a
little fragile - there are some package dependencies which kick in differently
depending on whether your exporting a whole org file as latex, part of a
file/tree or a block.
What is the best way to define multiple different C-styles in emacs and easily? I have one project that requires the Google C/C++ style while everything else uses BSD. What I would like to have is a key combination to allow me to quickly change between the style provided by
https://google-styleguide.googlecode.com/svn/trunk/google-c-style.el
and the standard "bsd" emacs style.
Instead of a key combination, I would suggest using directory-local variables. This modified example from the documentation should work:
((c-mode . ((c-file-style . "BSD"))))
Put this into a file called .dir-locals.el in the root of your project, and adjust the value for c-file-style as necessary.
For example, standard libraries in C/C++ are used very often, and it's very inefficient to go to the web browser, search for the code example how to use a library component, copy the source code and modify to suit your need; a few month later, you need to use that library component again but forgot how to use it, and you have to repeat the whole process again!
This process is not very productive for me because after we learn something the first time, we do not need to fully study the same thing again; just part of it can help us recall how to use it. I want my written code or example code copied from the web site to be stored for later reference and modification.
Emacs macro is an option, but I think you have to type the whole source code to make a desired template. What if I found a well written code, and I want to store that code segment for future reference? Macro won't be productive because I have to type the whole thing.
Is there Emacs plugin for doing this?
I wouldn't recommend snippets for the task that you described.
Snippets are meant to be repeated often. You can't have a lot of them.
What you need is something that you use rarely, but can have a lot of.
I'm using org-mode for this task. With org-mode you can:
Organize your knowledge by language/library etc.
Include small code snippets directly via babel.
Attach any number of files to any heading.
This way you get the overview/description via the headings,
and the actual code via code blocks / attachments.
Another advantage is that you can easily grep your org-file / your attachments.
Other advantages are timestamps, TODOs and all kinds of export that org-mode provides.
UPD
Just to give you a sample of what it can do (open in in emacs, otherwise it looks ugly):
https://gist.github.com/abo-abo/6040382/raw/1be55e30a9ed8d81cc1b2b752b7d498d05e72978/hyper.org
There is quite a list on the EmacsWiki: Templates.
Personally I know TempoMode and Yasnippets. I prefer Yasnippets. The snippets are very easy to write and have support for variable fields which you enter on snippet insertion.
This should provide a command inserting the last item of current kill-ring.
(defun my-code ()
(interactive "*")
(insert "(defun ")
(save-excursion (insert (concat "()
(interactive \"*\")
(insert \"" (car kill-ring) "\"))"))))
Remains to specify the name of the command when done - and installing it.
In the past I have used Else-Mode to do just that sort of thing, especially when the project I was working on had a very rigid and long, required function header comments.
You can look to SRecode from CEDET package. Besides standard templates, like yasnippet, etc., it also provides support for content-aware templating, like some templates could be expanded only inside the classes, some only as top-level declaration, etc.
When I do C-c C-e l to export an Org file to LaTeX it produces a document with a particular preamble. Instead of this particular preamble I would like it to use a preamble of my choice. Say that I want it to use the following preamble:
% Don't forget to qpdf --linearize the final copy
\RequirePackage[l2tabu,orthodox]{nag}% Old habits die hard. All the same, there are commands, classes and packages which are outdated and superseded. nag provides routines to warn the user about the use of those.
\immediate\write18{sh ./vc}
\input{vc}% Version control macros (for \VCDateISO in \date) http://www.ctan.org/pkg/vc
\documentclass[a4paper,12pt]{article}% pt? doublepage?
%\usepackage{geometry}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lmodern}% Latin Modern (derivate of Knuth's CM)
\usepackage{fixltx2e}% \textsubscript and bugfixes for LaTeX
\usepackage{microtype}
\usepackage[strict=true]{csquotes}% Context-sensistive quotes. \enquote "" \enquote* ''. Use the integrated commands \textcquote and \blockcquote rather than biblatex internal commands to get contex sensistive quotes for them too. s/babel/autostyle in new version.
\usepackage[bookmarks,pdfborder={0 0 0}]{hyperref}% links and pdfinfo. MUST BE LOADED LAST!
\hypersetup{% Setup for hyperref
pdftitle = {[Title from #+TITLE]},
pdfauthor = {[Author from #+AUTHOR]}
}
I know that you can manipulate which packages are used on a per file basis as described in the manual but I want this preamble to be used for all files unless ) specify otherwise. The preamble I want to use includes the following:
deactivated packages (such as geometry above)
packages loaded by RequirePackage
input macros
\immediate\write18 macros
comments after usepackage macros
a hypersetup macro that recognizes #+TITLE and #+AUTHOR from Org-mode files
Deactivated packages (such as geometry above)
Org-mode recognizes LaTeX syntax inside LaTeX code-blocks, as well as when including LaTeX files in the content. (See Quoting LaTeX code.)
Packages loaded by RequirePackage
As above.
Input macros
As above.
\immediate\write18 macros
I believe this should also be as above, however there is an alternate method of dealing with this. If you create a source code block of type sh with the command within it, Org will evaluate it on export and produce the desired behaviour. You have to enable sh as a babel language type for it to work however.
(require 'ob-shell)
You can also include sh as one of the languages loaded by babel by adding it to org-babel-load-languages
(acons 'sh 't org-babel-load-languages)
Then use a code block similar to the following to run your ./vc
#+name: Test
#+begin_src sh :results output silent :exports results
./vc
#+end_src
As long as this comes before your \input{vc} line it should run the code and then include it. Simply follow the code-block with
#+LATEX: \input{vc}
And your content should be included.
Comments after usepackage macros
If the code is within a LaTeX block it should recognize it as LaTeX.
A hypersetup macro that recognizes #+TITLE and #+AUTHOR from Org-mode files.
This will have to be included within each document rather than separate. The following will provide what you desire for your macros. It will not be within the preamble, however it will end up at the top of the document and the export does behave as expected (however it will not behave as expected if added through #+INCLUDE: from org.
#+begin_latex
\hypersetup{% Setup for hyperref
pdftitle = {{{{TITLE}}}}, %Org macro to take from #+TITLE
pdfauthor = {{{{AUTHOR}}}} %Org macro to take from #+AUTHOR
}
#+end_latex
Creating your own Latex export class
If you follow the instructions in the worg tutorials (See Org Latex Export) you can create your own export-class. If you want to have full control over the packages in the preamble you would simply need to:
(add-to-list 'org-export-latex-classes
'("<CLASS NAME>"
"\\documentclass{article}
[NO-DEFAULT-PACKAGES]
[NO-PACKAGES]"
<insert desired sectioning configuration>))
You can also add in your desired packages between the \\documentclass and [NO-DEFAULT-PACKAGES] lines. The alternative would be to add them to the file itself using:
#+LATEX_CLASS: <CLASS NAME>
#+LATEX_HEADER: \usepackage{package}
...
As a third option, you can simply create a custom .sty file with the desired packages etc and include it as a single #+LATEX_HEADER:.
This doesn't answer your question, but it does allow you to do what you want.
(defun headless-latex ()
"exports to a .tex file without any preamble"
(interactive)
(org-export-as-latex 3 nil nil nil t nil)
)
This function exports the content of your ORG-mode file without any preamble. You can then \input it into a file with your desired preamble. Further reading.
I use a different method to get things done :
Define a class (I call it per-file-class for some strange reason. You can call it something else). Put this code in your .emacs :
;; per-file-class with minimal packages
(unless (find "per-file-class" org-export-latex-classes :key 'car
:test 'equal)
(add-to-list 'org-export-latex-classes
'("per-file-class"
"\\documentclass{article}
[NO-DEFAULT-PACKAGES]
[EXTRA]"
("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}")
("\\paragraph{%s}" . "\\paragraph*{%s}")
("\\subparagraph{%s}" . "\\subparagraph*{%s}"))))
Use this class in your org file :
#+LaTeX_CLASS: per-file-class
#+LaTeX_CLASS_OPTIONS: [10pt, a4paper]
I'm not allowed to comment (bad reputation or something ;-)) so I will post an answer. A previous answer had a very nice snippet of code for a headless export function. That code needs updating for later versions of org:
(defun headless-latex ()
"exports to a .tex file without any preamble"
(interactive)
(org-latex-export-as-latex nil nil nil t nil)
)
I want to fully-justify latex code on EMACS so that my latex code will look better. For example, I remember my advisor sending me latex in fully justified way like this:
In ~\cite{Hummel2004}, authors described an approach for harvesting
software components from the Web. The basic idea is to use the Web as
the underlying repository, and to utilize standard search engines,
such as Google, as the means of discovering appropriate software
assets. Other researchers have crawled through Internet publicly
available CVS repositories to build their own source code search
engines (e.g., SPARS-J)~\cite{Matsushita2005}.
I suppose that his column-width is set to 70 columns.
Could someone give me a hint?
The standard fill.el package includes the command justify-current-line which is part of what you need. From the function help:
Do some kind of justification on this line.
Normally does full justification: adds spaces to the line to make it end at
the column given by `current-fill-column'.
Optional first argument how specifies alternate type of justification:
it can be `left', `right', `full', `center', or `none'.
If how is t, will justify however the `current-justification' function says to
And other posters have already given you the magicall invokation:
M-x set-justification
As a philosophical side note, the point of fixed-wdith text justification is to fake real typography on a inflexible output device. So applying it to LaTeX source seems a little odd to me. Moreover, I have been using the "one sentence to a line" approach to LaTeX documents for some months now, and find that it really does improves both the editability and the source-control behavior of LaTeX, so I would recommend against doing this.
If you select the region, and then press Ctrl-u M-x fill-region you get "full justification".
M-x set-justification-full
Use Refill mode afterwards to not have to run the command again after typing.
To get line wrap in the file itself (as opposed to something like longlines-mode that does not alter the structure of the file), I use auto-fill-mode, which automatically applies M-q (fill-paragraph) to each paragraph. For example, I use auto-fill-mode in mail-mode. You could do something similar with your LaTeX mode with a hook like this:
(add-hook 'TeX-mode-hook 'turn-on-auto-fill)
Assuming your TeX mode's hook is TeX-mode-hook.