Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am rendering LaTeX templates with Django template tags in them and for testing when I put a very long string of text, no matter if I used \raggedright, or \sloppy, the text always seems to run into the right margin. Example of the code below:

{
\raggedright
{{other_dress_code_title_1}}

{{other_dress_code_description_1}}
}

or

\begin{document}
{    
\sloppy
.............

I have tried. Help is desperately needed to prevent this all of the time.

share|improve this question
1  
Can you give a sample of the output and an actual source file (not a template)? –  Matthew Leingang Feb 7 '12 at 0:58
    
Welcome to TeX.sx! Your question was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other, otherwise you won't be able to comment on or accept answers or edit your question. –  Werner Feb 7 '12 at 3:31
add comment

migrated from stackoverflow.com Feb 7 '12 at 0:53

This question came from our site for professional and enthusiast programmers.

1 Answer

The reason for the lack of wrapping could be because your descriptors (or tags) are long words that do not fit any of the hyphenation requirements for the language you're using. To be more specific, the word other_dress_code_description_1 does not exist in the English language according to (La)TeX.

I'm not entirely sure about the context, but you could use the url package to typeset your tags. It has a built-in hyphenation and/or breaking feature that allows breaking of long URLs at various characters, including ., @, \, /, !, _, |, ;, >, ], ), ,, ?, ', +, =, and #. So, my short-term solution would be to set the tags as an URL.

In the MWE below, the URL font has been chosen as \rmdefault\bfseries, although you can modify this to your liking. Also, just for the sake of illustration, the showframe package was loaded with a \textwidth set to 250pt. Remove this in your final document, since it was merely for illustration of the line-breaking.

enter image description here

\documentclass{article}
\usepackage{showframe}% http://ctan.org/pkg/showframe
\setlength{\textwidth}{250pt}% Just for this example
\usepackage{url}% http://ctan.org/pkg/url
\begin{document}
\def\UrlFont{\rmfamily\bfseries}% Regular font for URLs is bold/roman
\raggedright
\url{other_dress_code_title_which_is_very_long_1}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
Donec euismod sem a arcu adipiscing ac tempor metus blandit. 
Integer id tempor magna. Nam eu blandit leo. Duis venenatis 
metus metus, vel facilisis nisl. Phasellus ut urna mi, at 
mattis augue. Nulla eleifend iaculis nisi, non condimentum 
risus iaculis id. Donec tempus nisi at urna viverra varius.

\url{other_dress_code_description_which_is_also_very_long_and_should_span_more_than_one_line_1}

Lorem ipsum dolor sit amet, consectetur adipiscing elit. 
Donec euismod sem a arcu adipiscing ac tempor metus blandit. 
Integer id tempor magna. Nam eu blandit leo. Duis venenatis 
metus metus, vel facilisis nisl. Phasellus ut urna mi, at 
mattis augue. Nulla eleifend iaculis nisi, non condimentum 
risus iaculis id. Donec tempus nisi at urna viverra varius.

\end{document}

I've kept your choice of \raggedright, since it provides a much cleaner breaking point with some of the tag names. This "solution" may not be perfect, since it hasn't been extensively tested. However, it may be sufficient for your use since there is no other information to go by.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.