Export comments as comments - emacs

In Org-mode you can make comments and from Org-mode you can export to LaTeX but Org-mode comments are not exported to LaTeX comments. How can Org-mode be made to export Org-mode comments as LaTeX comments?
Here is an example. The following
* Test
Text before comment
# Comment
Text after comment
Text before comment
#+BEGIN_COMMENT
Comment
#+END_COMMENT
Text after comment
exports to
\section{Test}
\label{sec-1}
Text before comment
Text after comment
Text before comment
Text after comment
But I want the Org-mode comments to be exported as LaTeX comments. Thus, I want the following LaTeX output:
\section{Test}
\label{sec-1}
Text before comment
% Comment
Text after comment
Text before comment
\begin{comment}
Comment
\end{comment}
Text after comment
I am running Org-mode 7.6 in Emacs 23.3.1.

Under the current exporter the only method I can think of that would allow you to export comments would be backend-specific. You could use something along the lines of:
#+latex: comment
or
#+begin_latex
\begin{comment}
comment
\end{comment}
#+end_latex
However both are contrived and you would need to do the equivalent for HTML etc if you intend to export to more than one format.
There is a new exporter in development however where this should not be overly difficult to implement (comments are already identified as blocks in the parser so it would simply need a method to convert them on export).
I'm forwarding this request to the mailing list to see if this can be included.
Edit: Thread located here.
Edit: Response from the maintainer of Org-Mode
the current exporters don't allow this, but the new export engine by
Nicolas makes it possible.
The plan is to merge the new export engine into Org's core before
version 8.0, so please stay tuned.

In addition to Jonathan Leech-Pepin's answer, there is a hackish way of doing it for a given exporter backend. Comments are handled in the org-export-handle-comments function, which is called by org-export-preprocess-string in org-exp.el. Each exporter backend is different, but let us consider the LaTeX backend.
If you look in the org-export-as-latex function in org-latex.el, you can find calls to org-export-preprocess-string. One of the things passed to the org-export-preprocess-string function is a parameter list, in particular it contains a :comments parameter, which in the LaTeX case is set to nil. This parameter tells the org-mode exporter what to do with comments - for the details look at the call to and implementation of org-export-handle-comments in org-exp.el. Essentially, the :comments parameter can be a format string showing how to handle the comments; if it is nil, this means no format handling so nothing is printed. If, in the org-export-as-latex function, you replace :comments nil with :comments "%% %s", then this will insert a "%" in front of whatever the comment text is upon export. So in your case
this is text before a comment
# this is a comment
this is text after a comment
would be exported as
this is text before a comment
% this is a comment
this is text after a comment
This isn't the most convenient way of doing things, and I'm not sure of a way to specify the :comments parameter on a per-file basis. Maybe something in the thread Jonathan set up will shed some light on this subject.
Note that you may need to remove the byte-compiled org-latex.elc file in order to see your changes in org-latex.el propagate through to the export.

Related

Howto include file content in a Scribble document

I am using Scribble to write assignments and would like to have the ability to include common text snippets somewhere in the document. For example:
#lang scribble/manual
#section{Some section}
#include-file["common-pretext.scrbl"] #; my imaginary command
Some additional text after the pretext
#section{Next section}
More text...
I would like #include-file to include the contents of common-pretext.scrbl just as if I had copy/pasted its contents at the specified position. That is, I would like its contents to be part of Some section and also properly handle Scribble commands occurring in common-pretext.scrbl.
I know that Scribble has #include-section, which is similar to what I want. However, #include-section always starts a new section and text following it until the next section is silently dropped (I am not sure why this happens, but presumably because of how the document is constructed). I also tried Racket's #include, but then the contents are not shown at all. Lastly, I tried building a macro that does what I want, but failed to make it work (if a macro is the way to go, then I am happy to share my attempts so far).
Is there such a command already and if not how can I build one?
This question is pretty old, but if you are still looking, this package does what you want:
https://docs.racket-lang.org/scribble-include-text/index.html

Orgmode, How can I remove codeblock descriptions?

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.

How to install Emacs Org-mode LaTeX export template?

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

What is the reason behind not having a simpler multi-line comment in Perl?

I know different methods of introducing multi-line comments in Perl. But I want to know why it doesn't have something simpler multi-line comment feature such /* comment */, which would make it much easier.
I currently follow http://www.perlmonks.org/?node_id=560985 to achieve multi-line comments. Are there any plans to include this feature in Perl anytime soon?
C-style comments come with a variety of difficult problems, including the inability to comment-out comments. Additionally, convenient syntax for one-line encourages concise writing, which makes your code easier to read. The absence of 10-line "Author: ... Input: ... Output: ... Favorite Color: ..." blocks that you see from time to time in C and C++ is another benefit.
Multi-line comments encourage long writing that is better expressed more concisely or as documentation, so this is what Perl encourages with its # and =pod operators (respectively).
Finally, if you are having trouble with Perl's style of commenting, you should configure your editor to edit programs, not text. In Emacs, if you start writing something like # this is a comment that is getting longer and longer and longer and oh my goodness we are out of space on this line what to do now and type M-q, Emacs will automatically insert the # at the beginning of each line that it creates.
If you just want to comment-out a block of code, then you need look no further than M-x comment-region and M-x uncomment-region, which will comment out the region in pretty-much any language; including Perl.
Don't stress about the syntax of comments; that's the computer's job!
There was a discussion regarding this on the perl6-language#perl.org mailing list. Although in the end the discussion was inconclusive, the summary posted here makes for interesting reading.
As with any multiline comment structure, there will be a "open" and a "close" comment condition, and that leads to problems with nested comments.
for example, C uses /* as the open and */ as the close. How does a multiline comment system handle comments within comments? C will fail if you try to comment a block that is already commented.
Note that line-based comments (e.g. c++ // comments) do not suffer this problem.
Simplicity is in the eye of the beholder. That said, there are already a number of ways to do multi-line comments. First, void string literals:
q{This text won't do anything.
Neither will this.};
This has the unfortunate side effect of triggering a warning:
Useless use of a constant in void context at - line 4.
Another option is using a heredoc in void context - for some reason this doesn't cause a warning:
<<ENDCOMMENT;
Foo comment bar.
ENDCOMMENT
As you can see, the problem isn't the lack of syntax as such (python doc comments look vaugely similar to the q{} method in fact) - it's more just that the community of perl programmers has settled on line comments using # and POD. Using a different method at this point will just confuse people who have to read your code later.

How do I fully-justify latex code on EMACS

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.