I use \texttt for some computer stuff (names of classes). But quite
often it overflow the page width.
Code I'm talking about is something like this:
Konfigurační soubor pro knihovnu Quartz. Quartz je mocný nástroj
umožňující plánované spuštění úloh, přesněji instanci tříd
implementujících třídu {\texttt{{org.quartz.Job}}}. Syntax je velmi
podobná souboru crontab unixového nástroje cron. Nastavena je četnost
časování. V tomto souboru jsou také nastaveny další údaje pro PSER:
verze SSL/TLS, formát keystore a algoritmy implementací rozhraní
{\texttt{{KeyManager}}} a {\texttt{{TrustManager}}} (předávané metodám
{\texttt{{getInstance()}}} továrních tříd
{\texttt{{KeyManagerFactory}}} a {\texttt{{TrustManagerFactory}}}).
From the part at the end
{\texttt{{KeyManagerFactory}}} a {\texttt{{TrustManagerFactory}}}).
I can see just "TrustMan" - the rest of the word is truncated.
I'd like to make latex to put the whole word on new line, which is
better (it'll be displayed whole at least).
Btw I use docbook to produce latex (http://db2latex.sourceforge.net/)
which makes thinks little bit difficult (have to adjust template).
Thanks for any tip.
Declare \raggedright or \sloppy
Thanks a lot for reply.
And would it help to force the text in \texttt to break to new line?
(go to new line)
I'd need something with functionality simillar to <br /> tak in xhtml.
I often use a special macro for this that allows hyphenation in tt
\def\somename#1{{\foreignlanguage{english}{\hyphenchar\font=`\-#1}}}
/daleif
Thanks a lot. I'll try it, this should help :-).
But in this way every chunk of text in \ttfamily will be hyphenated,
since changes of the \hyphenchar are global, like every change to font
parameters, such as \fontdimen's. Try the following file:
\documentclass{article}
\begin{document}
\ttfamily
\showhyphens{\ttfamily encoding}
{\hyphenchar\font=`\-
\showhyphens{\ttfamily encoding}}
\showhyphens{\ttfamily encoding}
\end{document}
Unfortunately, you can't simply switch it back in the macro, say with
\def\mytexttt#1{{\ttfamily
\hyphenchar\font=`\-#1%
\hyphenchar\font=-1 }}
since the relevant value of \hyphenchar for a font is the one current
at the time of \par: try
\hsize=2em \ttfamily\noindent
encoding \mytexttt{encoding} encoding\par
and you will see that no word is hyphenated.
One way out might be to use two "different" fonts; say that your
document uses T1 encoded fonts: then
\def\hyphtexttt#1{{\fontencoding{OT1}\ttfamily
\hyphenchar\font=`\-#1}}
does the trick, since you are changing the \hyphenchar for the
OT1-encoded typewriter font and words in \texttt{...} will not be
hyphenated. Do the other way around if the default encoding is OT1.
Ciao
Enrico
Thanks a lot for your advice.
I'm sorry although I wrote my bachelor thesis in LaTeX this is too
advanced for me :-(.
According your advices I tried this:
-----------------------
\documentclass{article}
\begin{document}
\def\hyphtexttt#1{{\fontencoding{T1}\ttfamily
\hyphenchar\font=`\-#1}}
% this produce the same like T1
%\def\hyphtexttt#1{{\fontencoding{OT1}\ttfamily
% \hyphenchar\font=`\-#1}}
\ttfamily
\showhyphens{\ttfamily encoding}
{\hyphenchar\font=`\-
\showhyphens{\ttfamily encoding}}
V tomto souboru jsou take nastaveny dalsi udaje pro PSER:
verze SSL/TLS, format keystore a algoritmy implementaci rozhrani
{\texttt{{KeyManager}}} a {\texttt{{TrustManager}}} (predavane metodam
{\texttt{{getInstance()}}} tovarnich trid
{\texttt{{sun.security.provider.JavaKeyStore}}} tovarnich trid
{\texttt{{KeyManagerFactory}}} a {\texttt{{TrustManagerFactory}}}).
\end{document}
-----------------------
which resulted in this:
V tomto souboru jsou take nastaveny dalsi udaje pro PSER: verze
SSL/TLS, format keystore a algoritmy implementaci rozhrani KeyMan-
ager a TrustManager (predavane metodam getInstance() tovarnich trid
sun.security.provider.JavaKeyStore tovarnich trid KeyManagerFactory
a TrustManagerFactory).
------------------
So it hyphen words in texttt (btw. not sure whether KeyMan-ager is
right hyphenation)
The problem is that it's all in texttt text.
What is wrong?
I was also thinking about what is typographically right.
I'm not sure what is better according to typographical convensions.
How to handle these long java words, such as
sun.security.pkcs12.PKCS12KeyStore
sun.security.provider.JavaKeyStore
Should I try to
* hyphen them like normal words
* or not to hyphen them at all, just part them, when there is a dot,
such as:
| word word sun.security.provider. |
|JavaKeyStore a word word another |
* just put whole word on new line, such as:
| word word a word word another |
| sun.security.provider.JavaKeyStore a word |
You have to change the \hypenchar\font when you are in the
intended font. The above changes the \hyphenchar for whatever
font is current. However, in the later command
\showhyphens{\ttfamily encoding}
the \ttfamily command turns off hyphenation again.
> V tomto souboru jsou take nastaveny dalsi udaje pro PSER:
> verze SSL/TLS, format keystore a algoritmy implementaci rozhrani
> {\texttt{{KeyManager}}} a {\texttt{{TrustManager}}} (predavane metodam
> {\texttt{{getInstance()}}} tovarnich trid
> {\texttt{{sun.security.provider.JavaKeyStore}}} tovarnich trid
> {\texttt{{KeyManagerFactory}}} a {\texttt{{TrustManagerFactory}}}).
You aren't using \hyphtextt anywhere in here. It is intended that you
use
it *in place of* \texttt to produce typewriter-like text which allows
hyphenation.
>
> \end{document}
> -----------------------
>
> which resulted in this:
> V tomto souboru jsou take nastaveny dalsi udaje pro PSER: verze
> SSL/TLS, format keystore a algoritmy implementaci rozhrani KeyMan-
> ager a TrustManager (predavane metodam getInstance() tovarnich trid
> sun.security.provider.JavaKeyStore tovarnich trid KeyManagerFactory
> a TrustManagerFactory).
> ------------------
> So it hyphen words in texttt (btw. not sure whether KeyMan-ager is
> right hyphenation)
> The problem is that it's all in texttt text.
This comes from invoking \ttfamily just before the first \showhyphens.
This is what was intended:
\documentclass{article}
% the \fontencoding command is probably not necessary
% note that the font is changed first, and then the \hyphenchar
\def\hyphtexttt#1{{\ttfamily \hyphenchar\font=`\-#1}}
\begin{document}
V tomto souboru jsou take nastaveny dalsi udaje pro PSER:
verze SSL/TLS, format keystore a algoritmy implementaci rozhrani
% Note that \hyphtexttt does its own grouping so all those extra
% (and confusing) braces are unnecessary.
\hyphtexttt{KeyManager}} a \hyphtexttt{TrustManager} (predavane
metodam
\hyphtexttt{getInstance()} tovarnich trid
\hyphtexttt{sun.security.provider.JavaKeyStore} tovarnich trid
\hyphtexttt{KeyManagerFactory} a \hyphtexttt{TrustManagerFactory}).
\end{document}
(Barring any typos on my part.)
Dan
Yes, it will allow TeX to break the line before big chunks that
otherwise would overflow. The former makes a ragged right-margin,
the latter ... but you would have seen already if you tried it.
> I'd need something with functionality simillar to <br /> tak in xhtml.
That's not what you asked for! And it is not the ideal solution
either!
Anyway, the equivalents to <br> are
\\ \newline and \linebreak
First two are ragged, last is flush.
Donald Arseneau as...@triumf.ca
The other way - i'm not able to define hyphtexttt command properly (as
I wrote in http://groups.google.com/group/comp.text.tex/msg/f814f373aca16e8c).
http://www.ctan.org/tex-archive/macros/latex/contrib/hyphenat/