Difference between revisions of "Verbatim with line breaks"

From Wiki
Jump to navigation Jump to search
(fix self-link)
m
 
(9 intermediate revisions by 6 users not shown)
Line 1: Line 1:
< [[From LaTeX to ConTeXt]]
+
===In ConTeXt===
  
===In LaTeX===
+
<context source="yes">
<texcode>
+
\enableregime[utf] % needed in MkII
\documentclass[frenchb]{article}% in french texts, : ; ? and ! are active
+
\setuppapersize[A5]
\usepackage[latin9]{inputenc}
 
\usepackage{listings,babel}
 
\lstset{breaklines=true,basicstyle=\ttfamily}
 
\begin{document}
 
\hsize8cm\noindent\lstinline{hööah:aloh/aa?lha llol!loh%lloh#allhal\lohhll;ohohal~loll ohalölo}
 
\end{document}
 
</texcode>
 
  
===In ConTeXt===
 
 
<texcode>
 
\mainlanguage[fr]
 
\framed
 
  [width=8cm,
 
    align=flushleft,
 
    strut=no]{% no empty line at the beginning
 
\starttyping[lines=hyphenated]
 
hööah:aloh/aa?lha llol!loh%lloh#allhal\lohhll;ohohal~loll ohalölo
 
\stoptyping
 
}
 
</texcode>
 
  
<context>
 
\mainlanguage[fr]
 
 
\framed
 
\framed
 
   [width=8cm,
 
   [width=8cm,
Line 37: Line 15:
 
}
 
}
 
</context>
 
</context>
 
To the one who wrote this question: the ConTeXt example above shows how to hyphenate verbatim text (you can't really notice that from the example), but not how to hyphenate French verbatim with active characters. You have to ask on the mailing list for that if you are still interested.
 
  
 
==Breaking lines on the right border==
 
==Breaking lines on the right border==
Line 44: Line 20:
 
Inspired by the (bad line breaking) example above, Taco wrote the following macro, which breaks a line as soon as it doesn't fit to the box any more.
 
Inspired by the (bad line breaking) example above, Taco wrote the following macro, which breaks a line as soon as it doesn't fit to the box any more.
  
The second box may serve as an example of what to do when you become desperate about your German grammar and hyphenation rules. The explanation follows [[#Why German is a relatively easy language|below]]
+
The second box may serve as an example of what to do when you become desperate about your German grammar and hyphenation rules.
  
<context>
+
<context source=yes>
%
 
 
% BREAK is a special pretty handler that auto-wraps lines
 
% BREAK is a special pretty handler that auto-wraps lines
 
% to fit the current hsize.
 
% to fit the current hsize.
Line 83: Line 58:
 
\installprettytype [BREAK] [BREAK]
 
\installprettytype [BREAK] [BREAK]
  
 +
\enableregime[utf] % needed in MkII
 +
\setuppapersize[A5]
  
 
\starttext
 
\starttext
 +
 
\framed
 
\framed
 
   [width=8cm,
 
   [width=8cm,
Line 94: Line 72:
 
\stoptyping
 
\stoptyping
 
}
 
}
 +
 
\framed
 
\framed
 
   [width=4cm,
 
   [width=4cm,
Line 103: Line 82:
 
\stoptyping
 
\stoptyping
 
}
 
}
 +
 
\stoptext
 
\stoptext
 
</context>
 
</context>
  
<texcode>
+
(The word "Hottentottenstottertrottelmutterlattengitterkotterbeutelratenattentater" has an amusing story attached, which can be found in [http://www.editorscanberra.org/May03.htm the May 2003 issue of the Canberra Society of Editors Newsletter].
%
 
% BREAK is a special pretty handler that auto-wraps lines
 
% to fit the current hsize.
 
 
 
\gdef\BREAKsetspecials%
 
  {\dorecurse{256}{\setpretty\numexpr \recurselevel-1\relax=10 }}
 
 
 
\gdef\BREAKsethandlers%
 
  {\installprettyhandler 10 \BREAKtypeone  }
 
 
 
\newcount\BREAKcharcounter
 
\newcount\BREAKmaxcharcount
 
 
 
\def\BREAKtypeone#1%
 
  {\advance\BREAKcharcounter 1
 
  \ifnum\BREAKcharcounter > \BREAKmaxcharcount
 
      \hfil\break
 
      \BREAKcharcounter=1
 
  \fi
 
  \getpretty{#1}}
 
 
 
\def\BREAKsetcounters%
 
  {\setbox\scratchbox=\hbox{0}%
 
  \BREAKmaxcharcount=\hsize
 
  \divide\BREAKmaxcharcount \wd\scratchbox
 
  \def\flushrestofverbatimline{\BREAKcharcounter=0 }%
 
  \BREAKcharcounter=0 }
 
 
 
\gdef\setupprettyBREAKtype%
 
  {\def\prettyidentifier{BREAK}%
 
  \BREAKsetcounters
 
  \BREAKsethandlers
 
  \BREAKsetspecials}
 
 
 
\installprettytype [BREAK] [BREAK]
 
 
 
 
 
\starttext
 
\framed
 
  [width=8cm,
 
    align=flushleft,
 
    strut=no]{%
 
\setuptyping[option=BREAK]
 
\starttyping
 
Hottentottenstottertrottelmutterlattengitterkotterbeutelratenattentater
 
\stoptyping
 
}
 
\stoptext
 
</texcode>
 
 
 
 
 
(This has nothing to do with ConTeXt, its just the explanation of the example above.)
 
 
 
===Why German is a relatively easy language===
 
<i>by Gila Scheffler</i>
 
 
 
German is a relatively easy language. If you know Latin you're used to
 
declensions and can learn German without great difficulty. That's what German
 
teachers tell you at the first lesson. Then you start studying the der, die, das,
 
den ... and they tell you that everything follows a logical order. So it's easy. And
 
to prove it, let's look at an example more closely: you sign up for first-year
 
German and go out and buy the textbook. It's a beautiful, expensive, hardbound
 
book, published in Dortmund, which talks about the customs of the <i>Hottentots</i>
 
(Hottentotten in German).
 
 
 
The book tells us that when opossums (<i>Beutelratten</i>) are captured, they are
 
placed in cages (<i>Kasten</i>) with bars made of wood slats (<i>Lattengitter</i>) to keep
 
them from escaping. These cages are called <i>Lattengitterkasten</i> in German, and
 
when there are opossums inside them they are known as
 
<i>Beutelrattenlattengitterkasten</i>.
 
 
 
One day, the Hottentot police arrested a would-be murderer (<i>Attentäter</i>), who
 
allegedly tried to kill a Hottentot mother (<i>Mutter</i>). Her son is a good-for-nothing
 
stutterer (<i>Stottertrottel</i>), so his mother is, therefore, a
 
<i>Hottentottenstottertrottelmutter</i> and her would-be murderer is a
 
<i>Hottentottenstottertrottelmutterattentäter</i>. Easy, right? So the police captured
 
the suspect and put him, temporarily, in an opossum cage
 
(<i>Beutelrattenlattengitterkasten</i>) for safekeeping until they could take him to jail.
 
But the prisoner escaped!
 
 
 
A search ensued and a Hottentot warrior cried out, ‘I have captured the murder
 
suspect (den <i>Attentäter</i>)!’
 
 
 
‘Yes? Which one?’ asked the chieftain.
 
 
 
‘The <i>Beutelrattenlattengitterkastenattentäter</i>!’ replied the warrior.
 
 
 
‘What? The murder suspect who was in the opossum cage?’ asked the
 
Hottentot chieftain.
 
 
 
‘That's right,’ said the warrior, ‘the <i>Hottentottenstottertrottelmutterattentäter</i>.
 
  
By now you know enough German to understand that he's talking about the
+
Another mechanism has been suggested on [[Wrapping]].
would-be murderer of the mother of the good-for-nothing Hottentot stutterer,
 
right?
 
  
‘Oh, I see,’ says the Hottentot chieftain, ‘why didn't you say so right away? You
+
== See also ==
could have begun by saying that you had captured the
+
{{Hyphenation see also}}
<i>Hottentottenstottertrottelmutterbeutelrattenlattengitterkastenattentäter</i>!’
 
  
As you can see, German is a very easy language. All you have to do is pay a
+
[[Category:Basics]]
little attention.
 

Latest revision as of 15:58, 8 June 2020

In ConTeXt

\enableregime[utf] % needed in MkII
\setuppapersize[A5]


\framed
   [width=8cm,
    align=flushleft,
    strut=no]{% no empty line at the beginning
\starttyping[lines=hyphenated]
hööah:aloh/aa?lha llol!loh%lloh#allhal\lohhll;ohohal~loll ohalölo
\stoptyping
}

Breaking lines on the right border

Inspired by the (bad line breaking) example above, Taco wrote the following macro, which breaks a line as soon as it doesn't fit to the box any more.

The second box may serve as an example of what to do when you become desperate about your German grammar and hyphenation rules.

% BREAK is a special pretty handler that auto-wraps lines
% to fit the current hsize.

\gdef\BREAKsetspecials%
  {\dorecurse{256}{\setpretty\numexpr \recurselevel-1\relax=10 }}

\gdef\BREAKsethandlers%
  {\installprettyhandler 10 \BREAKtypeone  }

\newcount\BREAKcharcounter
\newcount\BREAKmaxcharcount

\def\BREAKtypeone#1%
  {\advance\BREAKcharcounter 1
   \ifnum\BREAKcharcounter > \BREAKmaxcharcount
      \hfil\break
      \BREAKcharcounter=1
   \fi
   \getpretty{#1}}

\def\BREAKsetcounters%
  {\setbox\scratchbox=\hbox{0}%
   \BREAKmaxcharcount=\hsize
   \divide\BREAKmaxcharcount \wd\scratchbox
   \def\flushrestofverbatimline{\BREAKcharcounter=0 }%
   \BREAKcharcounter=0 }

\gdef\setupprettyBREAKtype%
  {\def\prettyidentifier{BREAK}%
   \BREAKsetcounters
   \BREAKsethandlers
   \BREAKsetspecials}

\installprettytype [BREAK] [BREAK]

\enableregime[utf] % needed in MkII
\setuppapersize[A5]

\starttext

\framed
   [width=8cm,
    align=flushleft,
    strut=no]{%
\setuptyping[option=BREAK]
\starttyping
hööah:aloh/aa?lha llol!loh%lloh#allhal\lohhll;ohohal~loll ohalölo
\stoptyping
}

\framed
   [width=4cm,
    align=flushleft,
    strut=no]{%
\setuptyping[option=BREAK]
\starttyping
Hottentottenstottertrottelmutterbeutelrattenlattengitterkastenattentäter
\stoptyping
}

\stoptext

(The word "Hottentottenstottertrottelmutterlattengitterkotterbeutelratenattentater" has an amusing story attached, which can be found in the May 2003 issue of the Canberra Society of Editors Newsletter.

Another mechanism has been suggested on Wrapping.

See also