I m writing one article in which i need to write a paragraph full of medical terms. How can i wrap a text in a line without using line break (or hyphen)?
Regards
line-breaking
I m writing one article in which i need to write a paragraph full of medical terms. How can i wrap a text in a line without using line break (or hyphen)?
Regards
You could also do it manually, by inserting a \BreakableChar
at the appropriate points:
Thisisaverylongtexttosimulateerror “firstterm*[title/abstract] AND
(secondterm*\BreakableChar{}[title/abstract] OR thirdterm*[title/abstract])”
One small complication here is that I have defined \BreakableChar
with an optional parameter, and since your subsequent text begins with a [
, it necessitated the use of {}
.
You could adapt the solution from Automatic line breaking of long lines of text
too automatically insert a breakable char at the points where you want it. To use this just pass the entire string to \AddBreakableChars{}
:
Thisisaverylongtexttosimulateerror “firstterm*[title/abstract] AND
\AddBreakableChars{(secondterm*[title/abstract]} OR thirdterm*[title/abstract])”
The current definition of it will insert a \BreakableChar
following any *
or \
. This can be extended to apply to additional characters as well. I have also shown in commented code what to do for cases where there is a character where you want to break and do want to insert a hyphen.
Here is the original text followed by the text where the term is given to the automated, \AddBreakableChars{}
macro, and the one with a \BreakableChar
manually inserted at the appropriate point:
\documentclass{article}
\usepackage{showframe}
\usepackage{hyphenat}
\usepackage{xstring}
\usepackage{forloop}
\newsavebox\MyBreakChar%
\sbox\MyBreakChar{}% char to display the break after non char
\newsavebox\MySpaceBreakChar%
\sbox\MySpaceBreakChar{\hyp}% char to display the break after space
\makeatletter%
\newcommand*{\BreakableChar}[1][\MyBreakChar]{%
\leavevmode%
\prw@zbreak%
\discretionary{\usebox#1}{}{}%
\prw@zbreak%
}%
\makeatother
\newcounter{index}%
\newcommand{\AddBreakableChars}[1]{%
\StrLen{#1 }[\stringLength]%
\forloop[1]{index}{1}{\value{index}<\stringLength}{%
\StrChar{#1}{\value{index}}[\currentLetter]%
\IfStrEqCase{\currentLetter}{%
% All the characters where you don't want hypen
{*}{\currentLetter\BreakableChar[\MyBreakChar]}%
{/}{\currentLetter\BreakableChar[\MyBreakChar]}%
% All the charactes where a break should have a hypen
%{ }{\currentLetter\BreakableChar[\MySpaceBreakChar]}%
}[\currentLetter]%
}%
}%
\begin{document}
\noindent\textbf{Original Text}:
\par\noindent
Thisisaverylongtexttosimulateerror “firstterm*[title/abstract] AND
(secondterm*[title/abstract] OR thirdterm*[title/abstract])”
\medskip
\noindent\textbf{Use automated} \verb|\AddBreakableChars|:
\par\noindent
Thisisaverylongtexttosimulateerror “firstterm*[title/abstract] AND
\AddBreakableChars{(secondterm*[title/abstract]} OR thirdterm*[title/abstract])”
\medskip
\noindent\textbf{Use manual} \verb|\BreakableChar|:
\par\noindent
Thisisaverylongtexttosimulateerror “firstterm*[title/abstract] AND
(secondterm*\BreakableChar{}[title/abstract] OR thirdterm*[title/abstract])”
\end{document}
One way to do this is to use \nohypens
from the hyphenat
package. Here is a comparison without (on the left) and with \nohypens
(on the right):
If you wish to disable hyphenation for the entire document (not that I am recommending that), you can use
\usepackage[none]{hyphenat}
\documentclass{article}
\usepackage{hyphenat}
\newcommand{\Text}{%
This is my first text for wrapping word
in a file. This text need to be
adjusted and acted based on the table
which need to be modified and tested
basedonthethedata which is given here.
}%
\begin{document}
\begin{minipage}{0.4\linewidth}
\Text
\end{minipage}%
\hspace*{2ex}
\begin{minipage}{0.4\linewidth}
\nohyphens{\Text}
\end{minipage}%
\end{document}
If you have really long words, you need to specify where the breaks can occur in the word. Below, I have used a solution from How to break long word containing symbols but with no hyphen? to automatically add a possible break after every letter (the macro is not complete, but the code just needs to be duplicated for each letter/character after which you want to allow a break).
\documentclass{article}
\usepackage{hyphenat}
\usepackage{xstring}
\usepackage{forloop}
% https://tex.stackexchange.com/questions/53965/how-to-break-long-word-containing-symbols-but-with-no-hyphen
\newsavebox\MyBreakChar%
\sbox\MyBreakChar{}% char to display the break after non char
\newsavebox\MySpaceBreakChar%
\sbox\MySpaceBreakChar{\hyp}% char to display the break after space
\makeatletter%
\newcommand*{\BreakableChar}[1][\MyBreakChar]{%
\leavevmode%
\prw@zbreak%
\discretionary{\usebox#1}{}{}%
\prw@zbreak%
}%
\makeatother
\newcounter{index}%
\newcommand{\AddBreakableChars}[1]{%
\StrLen{#1 }[\stringLength]%
\forloop[1]{index}{1}{\value{index}<\stringLength}{%
\StrChar{#1}{\value{index}}[\currentLetter]%
\IfStrEqCase{\currentLetter}{%
% All the characters where you don't want hypen
{a}{\currentLetter\BreakableChar[\MyBreakChar]}%
{b}{\currentLetter\BreakableChar[\MyBreakChar]}%
{c}{\currentLetter\BreakableChar[\MyBreakChar]}%
{d}{\currentLetter\BreakableChar[\MyBreakChar]}%
{e}{\currentLetter\BreakableChar[\MyBreakChar]}%
{f}{\currentLetter\BreakableChar[\MyBreakChar]}%
% list other letters here.
{z}{\currentLetter\BreakableChar[\MyBreakChar]}%
% All the charactes where a break should have a hypen
%{ }{\currentLetter\BreakableChar[\MySpaceBreakChar]}%
}[\currentLetter]%
}%
}%
\newcommand{\Text}{\setlength\emergencystretch{.5\textwidth}%
This is my first text for wrapping word
in a file. This text need to be
adjusted and acted based on the table
\AddBreakableChars{Ultramicroscopicvolcanoconiosis},
\AddBreakableChars{Pneumonoultramicroscopicsilicovolcanoconiosis}
which need to be modified and tested
basedonthethedata which is given here.\par
}%
\begin{document}
\begin{minipage}{0.4\linewidth}
\Text
\end{minipage}%
\hspace*{2ex}
\begin{minipage}{0.4\linewidth}
\nohyphens{\Text}
\end{minipage}%
\end{document}
Best Answer
You can break a word with no hyphen at the end of the line (see the other answers), but then it doesn't look like a broken word. It might be a good idea to use some other symbol there instead of the hyphen, for instance
$\bm\cdot$
(with\usepackage{bm}
). This can be done by defining:I strongly recommend using the package
microtype
too, which helps a lot here. I added a small negative\mkern
after the dot, to make it protrude a bit to the right margin.