* Request for suggestions including source code
@ 2011-05-04 20:53 Robert Goldman
2011-05-04 21:13 ` Thomas S. Dye
0 siblings, 1 reply; 11+ messages in thread
From: Robert Goldman @ 2011-05-04 20:53 UTC (permalink / raw
To: Org Mode
I have a document that has big chunks of included source code.
Unfortunately, when this is typeset in LaTeX, it typically blows past
the right margin. I find it quite difficult to determine how many
characters I get in a monospace line in LaTeX, and it seems like LaTeX
won't give me enough to fit in plausible blocks of source code.
Does anyone have a solution to this? Any way to tell org-mode to shrink
the fontsize when exporting code examples to LaTeX? More condensed font
to use for typewriter when exporting to LaTeX? Other tricks of the trade?
Seems like many would have encountered this problem.
Many thanks,
r
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Request for suggestions including source code
2011-05-04 20:53 Request for suggestions including source code Robert Goldman
@ 2011-05-04 21:13 ` Thomas S. Dye
2011-05-04 21:44 ` Nick Dokos
2011-05-04 21:59 ` Robert Goldman
0 siblings, 2 replies; 11+ messages in thread
From: Thomas S. Dye @ 2011-05-04 21:13 UTC (permalink / raw
To: rpgoldman; +Cc: Org Mode
[-- Attachment #1: Type: text/plain, Size: 1074 bytes --]
Aloha Robert,
Have a look at the listings and minted packages. You can specify font
size on a per-document or per-language basis. I believe listings has
an option to wrap long lines (don't remember this for minted, though).
The instructions here might be helpful:
http://orgmode.org/worg/org-tutorials/org-latex-export.html#sec-12_2
hth,
Tom
On May 4, 2011, at 10:53 AM, Robert Goldman wrote:
> I have a document that has big chunks of included source code.
> Unfortunately, when this is typeset in LaTeX, it typically blows past
> the right margin. I find it quite difficult to determine how many
> characters I get in a monospace line in LaTeX, and it seems like LaTeX
> won't give me enough to fit in plausible blocks of source code.
>
> Does anyone have a solution to this? Any way to tell org-mode to
> shrink
> the fontsize when exporting code examples to LaTeX? More condensed
> font
> to use for typewriter when exporting to LaTeX? Other tricks of the
> trade?
>
> Seems like many would have encountered this problem.
>
> Many thanks,
> r
>
>
[-- Attachment #2: Type: text/html, Size: 1549 bytes --]
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Request for suggestions including source code
2011-05-04 21:13 ` Thomas S. Dye
@ 2011-05-04 21:44 ` Nick Dokos
2011-05-04 22:01 ` Robert Goldman
2011-05-04 21:59 ` Robert Goldman
1 sibling, 1 reply; 11+ messages in thread
From: Nick Dokos @ 2011-05-04 21:44 UTC (permalink / raw
To: Thomas S. Dye; +Cc: nicholas.dokos, Org Mode, rpgoldman
Thomas S. Dye <tsd@tsdye.com> wrote:
> Aloha Robert,
>
> Have a look at the listings and minted packages. You can specify font size on a per-document or per-language basis. I believe listings has an option to wrap long lines (don't remember this for minted, though).
>
> The instructions here might be helpful:
>
> http://orgmode.org/worg/org-tutorials/org-latex-export.html#sec-12_2
>
> hth,
> Tom
>
> On May 4, 2011, at 10:53 AM, Robert Goldman wrote:
>
> I have a document that has big chunks of included source code.
> Unfortunately, when this is typeset in LaTeX, it typically blows past
> the right margin. I find it quite difficult to determine how many
> characters I get in a monospace line in LaTeX, and it seems like LaTeX
> won't give me enough to fit in plausible blocks of source code.
>
> Does anyone have a solution to this? Any way to tell org-mode to shrink
> the fontsize when exporting code examples to LaTeX? More condensed font
> to use for typewriter when exporting to LaTeX? Other tricks of the trade?
>
> Seems like many would have encountered this problem.
>
> Many thanks,
> r
>
>
Tom provides the practical answers, I go for the frivolous ones :-) : the following
latex program will give you the text width of the page:
--8<---------------cut here---------------start------------->8---
\documentclass{article}
\begin{document}
\the\textwidth
\end{document}
%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:
--8<---------------cut here---------------end--------------->8---
I get 345.0pt (but you can use geometry.sty to change it).
Let's say we want to use cmtt10 (at its design size of 10pt, i.e. not scaled up
or down). The character sizes of this font can be obtained from the TFM file. An
easy way to get them in human-readable form is to use tftopl:
tftopl /usr/share/texmf-texlive/fonts/tfm/public/cm/cmtt10.tfm | grep CHARWD
will give you the character widths as fractions of the design size. Since this
is a fixed-width font, all widths are the same:
(CHARWD R 0.524996)
So the width of each character in points is:
0.524996 * design size = 5.24996pt
and you can accommodate
floor(345.0 / 5.24996) = 65
characters per line.
So there you have it: a frivolous exercise, almost completely OT for the
list and an almost useless answer[fn:1].
Nick
Footnotes:
[fn:1] I know: I have no life -- but I rather enjoyed it...
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Request for suggestions including source code
2011-05-04 21:13 ` Thomas S. Dye
2011-05-04 21:44 ` Nick Dokos
@ 2011-05-04 21:59 ` Robert Goldman
2011-05-04 22:23 ` Thomas S. Dye
1 sibling, 1 reply; 11+ messages in thread
From: Robert Goldman @ 2011-05-04 21:59 UTC (permalink / raw
To: Thomas S. Dye; +Cc: Org Mode
On 5/4/11 May 4 -4:13 PM, Thomas S. Dye wrote:
> Aloha Robert,
>
> Have a look at the listings and minted packages. You can specify font
> size on a per-document or per-language basis. I believe listings has an
> option to wrap long lines (don't remember this for minted, though).
>
> The instructions here might be helpful:
>
> http://orgmode.org/worg/org-tutorials/org-latex-export.html#sec-12_2
Hm. I'm still grappling with this. I am including many of these
examples by using a source snippet (in sh) that goes out and pulls the
example out of a source code file.
Even after adding
#+LaTeX_HEADER \usepackage{listings}
and
#+src: setup-listings
to the top of my file, and setting
org-export-latex-listings to 'listings
the :results of the source blocks, which look like, e.g., the following:
#+begin_src sh :exports results :results output
sourceSample.perl single code/ontology/top.prxo 'Class Pattern'
#+end_src
come out wrapped in
\begin{verbatim}
...
\end{verbatim}
Maybe I'm not doing enough. I'm a bit confused by the listings example
in the tutorial because it has the configuration examples be in their
own source block, and adds all of the options for specially typesetting
particular programming languages. It's not altogether clear to me which
bits of that are critical to getting the listings stuff to work at all,
and which are only specially tailoring its function.
Is it necessary to specify what programming language is used in order to
typeset using listings? I am using a domain specific language for which
there is no obvious listings setting and, anyway, what I am trying to
typeset is the /results/ of the source blocks, which are in a different
programming language from the /source/ of the source blocks.
I suspect I am just looking for a simpler solution, e.g., one which
would make org-mode give me the source blocks in
{\small
\begin{verbatim}
...
\end{verbatim}
}
instead of
\begin{verbatim}
...
\end{verbatim}
or something like that.
best,
r
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Request for suggestions including source code
2011-05-04 21:44 ` Nick Dokos
@ 2011-05-04 22:01 ` Robert Goldman
2011-05-04 23:10 ` Nick Dokos
0 siblings, 1 reply; 11+ messages in thread
From: Robert Goldman @ 2011-05-04 22:01 UTC (permalink / raw
To: nicholas.dokos; +Cc: Org Mode
On 5/4/11 May 4 -4:44 PM, Nick Dokos wrote:
> Tom provides the practical answers, I go for the frivolous ones :-) : the following
> latex program will give you the text width of the page:
>
> --8<---------------cut here---------------start------------->8---
> \documentclass{article}
>
> \begin{document}
> \the\textwidth
> \end{document}
>
> %%% Local Variables:
> %%% mode: latex
> %%% TeX-master: t
> %%% End:
> --8<---------------cut here---------------end--------------->8---
>
> I get 345.0pt (but you can use geometry.sty to change it).
>
> Let's say we want to use cmtt10 (at its design size of 10pt, i.e. not scaled up
> or down). The character sizes of this font can be obtained from the TFM file. An
> easy way to get them in human-readable form is to use tftopl:
>
> tftopl /usr/share/texmf-texlive/fonts/tfm/public/cm/cmtt10.tfm | grep CHARWD
>
> will give you the character widths as fractions of the design size. Since this
> is a fixed-width font, all widths are the same:
>
> (CHARWD R 0.524996)
>
> So the width of each character in points is:
>
> 0.524996 * design size = 5.24996pt
>
> and you can accommodate
>
> floor(345.0 / 5.24996) = 65
>
> characters per line.
>
> So there you have it: a frivolous exercise, almost completely OT for the
> list and an almost useless answer[fn:1].
This actually was pretty helpful. The problem is, of course, that I
can't rewrite all of my source code to be in 65-width lines, nor can I
convince my colleagues to do so.
So what I need now is some way to fix the verbatim environments that are
produced by org-mode to use a smaller font. I.e., instead of trying to
fix the source code to match char-width, fix the char-width to match the
source code. Any idea how to do that?
thanks,
r
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Request for suggestions including source code
2011-05-04 21:59 ` Robert Goldman
@ 2011-05-04 22:23 ` Thomas S. Dye
2011-05-04 22:29 ` Robert Goldman
0 siblings, 1 reply; 11+ messages in thread
From: Thomas S. Dye @ 2011-05-04 22:23 UTC (permalink / raw
To: rpgoldman; +Cc: Org Mode
On May 4, 2011, at 11:59 AM, Robert Goldman wrote:
> On 5/4/11 May 4 -4:13 PM, Thomas S. Dye wrote:
>> Aloha Robert,
>>
>> Have a look at the listings and minted packages. You can specify
>> font
>> size on a per-document or per-language basis. I believe listings
>> has an
>> option to wrap long lines (don't remember this for minted, though).
>>
>> The instructions here might be helpful:
>>
>> http://orgmode.org/worg/org-tutorials/org-latex-export.html#sec-12_2
>
> Hm. I'm still grappling with this. I am including many of these
> examples by using a source snippet (in sh) that goes out and pulls the
> example out of a source code file.
>
> Even after adding
>
> #+LaTeX_HEADER \usepackage{listings}
>
> and
>
> #+src: setup-listings
>
Sorry for the confusion. In the example, the line
#+source: setup-listings
names the source code block that follows. I don't think it will do
anything by itself in your document.
That code block named setup-listings contains an example of a listings
setup that maps Org-mode's output for Emacs Lisp code blocks to
something listings recognizes. It can be executed in Org-mode, using
Babel, to setup the listings export. After this is done, then the
example should export correctly.
I'm not sure what is going wrong on your end. Perhaps org-export-
latex-custom-lang-environments needs to be configured for the language
you're using?
hth,
Tom
> to the top of my file, and setting
>
> org-export-latex-listings to 'listings
>
> the :results of the source blocks, which look like, e.g., the
> following:
>
> #+begin_src sh :exports results :results output
> sourceSample.perl single code/ontology/top.prxo 'Class Pattern'
> #+end_src
>
> come out wrapped in
>
> \begin{verbatim}
> ...
> \end{verbatim}
>
> Maybe I'm not doing enough. I'm a bit confused by the listings
> example
> in the tutorial because it has the configuration examples be in their
> own source block, and adds all of the options for specially
> typesetting
> particular programming languages. It's not altogether clear to me
> which
> bits of that are critical to getting the listings stuff to work at
> all,
> and which are only specially tailoring its function.
>
> Is it necessary to specify what programming language is used in
> order to
> typeset using listings? I am using a domain specific language for
> which
> there is no obvious listings setting and, anyway, what I am trying to
> typeset is the /results/ of the source blocks, which are in a
> different
> programming language from the /source/ of the source blocks.
>
> I suspect I am just looking for a simpler solution, e.g., one which
> would make org-mode give me the source blocks in
>
> {\small
> \begin{verbatim}
> ...
> \end{verbatim}
> }
>
> instead of
>
> \begin{verbatim}
> ...
> \end{verbatim}
>
> or something like that.
>
> best,
> r
>
>
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Request for suggestions including source code
2011-05-04 22:23 ` Thomas S. Dye
@ 2011-05-04 22:29 ` Robert Goldman
2011-05-04 22:49 ` brian powell
2011-05-05 17:07 ` Eric Schulte
0 siblings, 2 replies; 11+ messages in thread
From: Robert Goldman @ 2011-05-04 22:29 UTC (permalink / raw
To: Thomas S. Dye; +Cc: Org Mode
On 5/4/11 May 4 -5:23 PM, Thomas S. Dye wrote:
>
> On May 4, 2011, at 11:59 AM, Robert Goldman wrote:
>
>> On 5/4/11 May 4 -4:13 PM, Thomas S. Dye wrote:
>>> Aloha Robert,
>>>
>>> Have a look at the listings and minted packages. You can specify font
>>> size on a per-document or per-language basis. I believe listings has an
>>> option to wrap long lines (don't remember this for minted, though).
>>>
>>> The instructions here might be helpful:
>>>
>>> http://orgmode.org/worg/org-tutorials/org-latex-export.html#sec-12_2
>>
>> Hm. I'm still grappling with this. I am including many of these
>> examples by using a source snippet (in sh) that goes out and pulls the
>> example out of a source code file.
>>
>> Even after adding
>>
>> #+LaTeX_HEADER \usepackage{listings}
>>
>> and
>>
>> #+src: setup-listings
>>
>
> Sorry for the confusion. In the example, the line
>
> #+source: setup-listings
>
> names the source code block that follows. I don't think it will do
> anything by itself in your document.
>
> That code block named setup-listings contains an example of a listings
> setup that maps Org-mode's output for Emacs Lisp code blocks to
> something listings recognizes. It can be executed in Org-mode, using
> Babel, to setup the listings export. After this is done, then the
> example should export correctly.
>
> I'm not sure what is going wrong on your end. Perhaps
> org-export-latex-custom-lang-environments needs to be configured for the
> language you're using?
Is there any chance that this won't work because I have a source snippet
in one language (sh) that returns as results a source snippet in a
/different/ language (a lisp-like domain-specific language)? I don't
off-hand see how I can come up with a single label for the source block
that takes this into account....
This may be a weird enough case that I should be aiming at a solution
that is much simpler: e.g., just figuring out how to change all of my
verbatim environments to use a smaller font or changing the export
behavior so that /all/ verbatim blocks turn into listings blocks.
Best,
r
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Request for suggestions including source code
2011-05-04 22:29 ` Robert Goldman
@ 2011-05-04 22:49 ` brian powell
2011-05-05 17:07 ` Eric Schulte
1 sibling, 0 replies; 11+ messages in thread
From: brian powell @ 2011-05-04 22:49 UTC (permalink / raw
To: rpgoldman; +Cc: Org Mode
* Literate Programming and CWEB/NOWEB work great.
** Could use \scriptsize and/or \tiny and set the margins to 0--this
is what I do:
\documentclass[10pt]{report}
\pagestyle{empty}
\usepackage{anysize}
\marginsize{0cm}{0cm}{0cm}{0cm}
\begin{document}
\tiny
\begin{verbatim}
BlahSourceCode
\end{verbatim}
\scriptsize
\begin{verbatim}
BlahSourceCode
\end{verbatim}
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Request for suggestions including source code
2011-05-04 22:01 ` Robert Goldman
@ 2011-05-04 23:10 ` Nick Dokos
2011-05-05 0:11 ` Robert Goldman
0 siblings, 1 reply; 11+ messages in thread
From: Nick Dokos @ 2011-05-04 23:10 UTC (permalink / raw
To: rpgoldman; +Cc: nicholas.dokos, Org Mode
Robert Goldman <rpgoldman@sift.info> wrote:
> On 5/4/11 May 4 -4:44 PM, Nick Dokos wrote:
>
> > So there you have it: a frivolous exercise, almost completely OT for the
> > list and an almost useless answer[fn:1].
>
> This actually was pretty helpful. The problem is, of course, that I
> can't rewrite all of my source code to be in 65-width lines, nor can I
> convince my colleagues to do so.
>
Precisely: that's why it was useless :-) I took a quick look at
Stevens's "Advanced Programming in the UNIX environment" (which I think
of as well-typeset) and I find that most of the time, he adheres to the
65-char limit - there are some comments that go up to 72 or so and stick
out a bit into the right margin. But I'm pretty sure he planned it to
the 65-char limit.
> So what I need now is some way to fix the verbatim environments that are
> produced by org-mode to use a smaller font. I.e., instead of trying to
> fix the source code to match char-width, fix the char-width to match the
> source code. Any idea how to do that?
>
Here is one possibility: create a verbfont.sty file like this:
--8<---------------cut here---------------start------------->8---
\makeatletter
\def\verbatim@font{\normalfont\scriptsize\ttfamily}
\makeatother
--8<---------------cut here---------------end--------------->8---
and add this to your org file:
--8<---------------cut here---------------start------------->8---
#+LATEX_HEADER: \usepackage{verbfont}
--8<---------------cut here---------------end--------------->8---
Instead of \scriptsize, you can use any of the ones defined in
size1X.clo (for some X). If you use \tiny, you should package a
magnifier with the book...
Nick
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Request for suggestions including source code
2011-05-04 23:10 ` Nick Dokos
@ 2011-05-05 0:11 ` Robert Goldman
0 siblings, 0 replies; 11+ messages in thread
From: Robert Goldman @ 2011-05-05 0:11 UTC (permalink / raw
To: nicholas.dokos; +Cc: Org Mode
On 5/4/11 May 4 -6:10 PM, Nick Dokos wrote:
> Robert Goldman <rpgoldman@sift.info> wrote:
>
>> On 5/4/11 May 4 -4:44 PM, Nick Dokos wrote:
....
>> So what I need now is some way to fix the verbatim environments that are
>> produced by org-mode to use a smaller font. I.e., instead of trying to
>> fix the source code to match char-width, fix the char-width to match the
>> source code. Any idea how to do that?
>>
>
> Here is one possibility: create a verbfont.sty file like this:
>
> --8<---------------cut here---------------start------------->8---
> \makeatletter
> \def\verbatim@font{\normalfont\scriptsize\ttfamily}
> \makeatother
> --8<---------------cut here---------------end--------------->8---
>
> and add this to your org file:
>
> --8<---------------cut here---------------start------------->8---
> #+LATEX_HEADER: \usepackage{verbfont}
> --8<---------------cut here---------------end--------------->8---
>
> Instead of \scriptsize, you can use any of the ones defined in
> size1X.clo (for some X). If you use \tiny, you should package a
> magnifier with the book...
Thank you! That was just /exactly/ what I needed. The listings
approach seems neat for other cases, but mine is a simpler solution and
this nails it.
Best,
R
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: Request for suggestions including source code
2011-05-04 22:29 ` Robert Goldman
2011-05-04 22:49 ` brian powell
@ 2011-05-05 17:07 ` Eric Schulte
1 sibling, 0 replies; 11+ messages in thread
From: Eric Schulte @ 2011-05-05 17:07 UTC (permalink / raw
To: rpgoldman; +Cc: Org Mode
Robert Goldman <rpgoldman@sift.info> writes:
> On 5/4/11 May 4 -5:23 PM, Thomas S. Dye wrote:
>>
>> On May 4, 2011, at 11:59 AM, Robert Goldman wrote:
>>
>>> On 5/4/11 May 4 -4:13 PM, Thomas S. Dye wrote:
>>>> Aloha Robert,
>>>>
>>>> Have a look at the listings and minted packages. You can specify font
>>>> size on a per-document or per-language basis. I believe listings has an
>>>> option to wrap long lines (don't remember this for minted, though).
>>>>
>>>> The instructions here might be helpful:
>>>>
>>>> http://orgmode.org/worg/org-tutorials/org-latex-export.html#sec-12_2
>>>
>>> Hm. I'm still grappling with this. I am including many of these
>>> examples by using a source snippet (in sh) that goes out and pulls the
>>> example out of a source code file.
>>>
>>> Even after adding
>>>
>>> #+LaTeX_HEADER \usepackage{listings}
>>>
>>> and
>>>
>>> #+src: setup-listings
>>>
>>
>> Sorry for the confusion. In the example, the line
>>
>> #+source: setup-listings
>>
>> names the source code block that follows. I don't think it will do
>> anything by itself in your document.
>>
>> That code block named setup-listings contains an example of a listings
>> setup that maps Org-mode's output for Emacs Lisp code blocks to
>> something listings recognizes. It can be executed in Org-mode, using
>> Babel, to setup the listings export. After this is done, then the
>> example should export correctly.
>>
>> I'm not sure what is going wrong on your end. Perhaps
>> org-export-latex-custom-lang-environments needs to be configured for the
>> language you're using?
>
> Is there any chance that this won't work because I have a source snippet
> in one language (sh) that returns as results a source snippet in a
> /different/ language (a lisp-like domain-specific language)? I don't
> off-hand see how I can come up with a single label for the source block
> that takes this into account....
>
> This may be a weird enough case that I should be aiming at a solution
> that is much simpler: e.g., just figuring out how to change all of my
> verbatim environments to use a smaller font or changing the export
> behavior so that /all/ verbatim blocks turn into listings blocks.
>
You could customize the value of the `org-export-latex-verbatim-wrap'
variable to include a line of latex to shrink the font size. For
example
#+begin_src emacs-lisp :results silent
(setq org-export-latex-verbatim-wrap
'("{\\scriptsize\n\\begin{verbatim}\n" . "\\end{verbatim}\n}\n"))
#+end_src
Best -- Eric
>
> Best,
> r
>
>
--
Eric Schulte
http://cs.unm.edu/~eschulte/
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2011-05-05 20:54 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-04 20:53 Request for suggestions including source code Robert Goldman
2011-05-04 21:13 ` Thomas S. Dye
2011-05-04 21:44 ` Nick Dokos
2011-05-04 22:01 ` Robert Goldman
2011-05-04 23:10 ` Nick Dokos
2011-05-05 0:11 ` Robert Goldman
2011-05-04 21:59 ` Robert Goldman
2011-05-04 22:23 ` Thomas S. Dye
2011-05-04 22:29 ` Robert Goldman
2011-05-04 22:49 ` brian powell
2011-05-05 17:07 ` Eric Schulte
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.