emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Dan Davison <davison@stats.ox.ac.uk>
To: "Sébastien Vauban"
	<public-wxhgmqzgwmuf-geNee64TY+gS+FvcfC7Uqw@plane.gmane.org>
Cc: public-emacs-orgmode-mXXj517/zsQ@plane.gmane.org
Subject: Re: How to get pretty printed source code in PDFLaTeX
Date: Fri, 06 Aug 2010 09:39:42 -0400	[thread overview]
Message-ID: <87vd7nn9lt.fsf@stats.ox.ac.uk> (raw)
In-Reply-To: <87k4o4893x.fsf_-_@mundaneum.com> ("Sébastien Vauban"'s message of "Fri, 06 Aug 2010 09:59:30 +0200")



Sébastien Vauban <wxhgmqzgwmuf-geNee64TY+gS+FvcfC7Uqw@public.gmane.org>
writes:

> Hi Dan and Sebastian,
>
> Sebastian Rose wrote:
>> Dan Davison <davison-+7o2aNKnwVPQzY9nttDBhA@public.gmane.org> writes:
>>> Can you point me to an example that shows how to make source code in latex
>>> look (almost) as nice as html?
>>
>> That is supposed to work with the `listings' package. I havent tried that
>> yet.
>>
>> I still use my old LaTeX headers and write verbatim LaTeX code.  I'd
>> like to switch though, since it's a lot to type.
>>
>> Here is an example:
>>
>>       \begin{codeblock}
>>       \keyword{public function}~\func{\_\_construct}~(\increaseindent[15]\doindent
>>       \variable{\$instance}~=~\konstante{MAP\_STANDARD\_JS\_INSTANCE},\doindent
>>       \variable{\$z}~=~\konstante{MAP\_STANDARD\_ZOOM},\doindent
>>       \variable{\$centerX}~=~-1,\doindent
>>       \variable{\$centerY}~=~-1,\doindent
>>       \variable{\$highlights}~=~\keyword{true},\doindent
>>       \variable{\$spots}~=~\keyword{false}\doindent
>>       )\resetindent
>>       \end{codeblock}
>>
>> Looks horrible, does it?
>
> If I understand you right, here's such an example you're after:
>
> #+TITLE:     Using the listings package
> #+AUTHOR:    Seb Vauban
> #+DATE:      2010-08-06
> #+LANGUAGE:  en_US
>
> * Code
>
> This must be nice to see in LaTeX.
>
> #+SRCNAME: srcModifyDB1.sql
> #+BEGIN_SRC sql :tangle srcModifyDB.sql
>     -- add column `DossierSentToSecteur' (if column does not exist yet)
>     IF NOT EXISTS (SELECT *
>                    FROM INFORMATION_SCHEMA.COLUMNS
>                    WHERE TABLE_NAME = 'dossier'
>                    AND COLUMN_NAME = 'DossierSentToSecteur')
>     BEGIN
>         ALTER TABLE dossier
>         ADD DossierSentToSecteur smalldatetime NULL
>     END
>     GO
> #+END_SRC
>
> Right?
>
> * Much better code
>
> For that, you need to customize =listings=:
>
> #+begin_LaTeX
> % typeset source code listings
> \usepackage{listings} % must be loaded after `babel'
> \lstloadlanguages{C}
> \definecolor{sva@lstbackground}{HTML}{FFFFCC} % light yellow
> \definecolor{sva@lstkeyword}{HTML}{0000FF} % blue
> \definecolor{sva@lstidentifier}{HTML}{000000} % black
> \definecolor{sva@lstcomment}{HTML}{FF0000} % red
> \definecolor{sva@lststring}{HTML}{008000} % dark green
> \lstset{%
>     basicstyle=\ttfamily\scriptsize, % the font that is used for the code
>     tabsize=4, % sets default tabsize to 4 spaces
>     numbers=left, % where to put the line numbers
>     numberstyle=\tiny, % line number font size
>     stepnumber=0, % step between two line numbers
>     breaklines=false, %!! don't break long lines of code
>     showtabs=false, % show tabs within strings adding particular underscores
>     showspaces=false, % show spaces adding particular underscores
>     showstringspaces=false, % underline spaces within strings
>     keywordstyle=\color{sva@lstkeyword},
>     identifierstyle=\color{sva@lstidentifier},
>     stringstyle=\color{sva@lststring},
>     commentstyle=\color{sva@lstcomment},
>     backgroundcolor=\color{sva@lstbackground}, % sets the background color
>     captionpos=b, % sets the caption position to `bottom'
>     extendedchars=false %!?? workaround for when the listed file is in UTF-8
> }
> #+end_LaTeX
>
> #+SRCNAME: srcModifyDB2.sql
> #+BEGIN_SRC sql :tangle srcModifyDB.sql
>     -- add column `DossierSentToSecteur' (if column does not exist yet)
>     IF NOT EXISTS (SELECT *
>                    FROM INFORMATION_SCHEMA.COLUMNS
>                    WHERE TABLE_NAME = 'dossier'
>                    AND COLUMN_NAME = 'DossierSentToSecteur')
>     BEGIN
>         ALTER TABLE dossier
>         ADD DossierSentToSecteur smalldatetime NULL
>     END
>     GO
> #+END_SRC
>
> with the following in my `.emacs' file:
>
>       (setq org-export-latex-default-packages-alist
>             '(("AUTO" "inputenc" t)
>               ("T1" "fontenc" t)
>               ("" "fixltx2e" nil)
>               ("" "graphicx" t)
>               ("" "longtable" nil)
>               ("" "float" nil)
>               ("" "wrapfig" nil)
>               ("" "soul" t)
>               ("" "t1enc" t)
>               ("" "textcomp" t)
>               ("" "marvosym" t)
>               ("" "wasysym" t)
>               ("" "latexsym" t)
>               ("" "amssymb" t)
>               ("" "hyperref" nil)
>               "\\tolerance=1000"))
>
>       ;; tell org to use listings (instead of verbatim) for source code
>       (setq org-export-latex-listings t)
>
>       ;; if you want fontified source code, then you must include the
>       ;; `listings' package
>       (add-to-list 'org-export-latex-packages-alist '("" "listings"))
>
>       ;; if you want colored source code, then you need to include the
>       ;; `xcolor' package
>       (add-to-list 'org-export-latex-packages-alist '("" "xcolor"))
>
> I've put the PDF (for easy access) onto my Web site:
>
> http://www.mygooglest.com/sva/ECM-Listings.pdf

Wow, that's really nice. Thanks for sharing that. I think we should aim
to get to a point where org-mode can produce such nicely formatted
source code out-of-the-box. Maybe we could even make latex inherit the
colours and fonts that emacs is currently using for source code mark up?
I was going to suggest doing this with listings but then came across
minted, and I wonder whether that's even more suitable? (See the other
post I just made.)

Dan

>
> Best regards,
>   Seb

  reply	other threads:[~2010-08-06 14:16 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-04 17:00 Change resolution of LaTeX formulas in HTML output? amscopub-mail
2010-08-04 22:32 ` Bastien
2010-08-05 19:11   ` Dan Davison
2010-08-06  9:12     ` Bastien
2010-08-06 10:46   ` Carsten Dominik
2010-08-06 17:21     ` Bastien
2010-08-05 19:14 ` Dan Davison
2010-08-05 20:34   ` Sebastian Rose
2010-08-05 21:36     ` Dan Davison
2010-08-05 22:14       ` Sebastian Rose
2010-08-06  7:59         ` How to get pretty printed source code in PDFLaTeX Sébastien Vauban
2010-08-06 13:39           ` Dan Davison [this message]
2010-08-09 20:30             ` Sébastien Vauban
2010-08-09 22:29               ` Dan Davison
2010-08-10 16:38                 ` Thomas S. Dye
2010-08-10 17:37                   ` Dan Davison
2010-08-10 19:08                     ` Thomas S. Dye

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87vd7nn9lt.fsf@stats.ox.ac.uk \
    --to=davison@stats.ox.ac.uk \
    --cc=public-emacs-orgmode-mXXj517/zsQ@plane.gmane.org \
    --cc=public-wxhgmqzgwmuf-geNee64TY+gS+FvcfC7Uqw@plane.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).