14

If one wants to raise some text one uses something like

\raisebox{0.5 em}{some text}

However this doesn't respect line breaks and may cause some nasty overflows.

Is there a way to have \raisebox respect line breaks? Or an alternative that provides the same functionality?

Edit: Here's an example for clarification:

\documentclass{article}

\begin{document}

Lorem ipsum dolor sit amet,
\raisebox{0.5 em}{consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.}

\end{document}

I need the raised text to line break like it would if it wasn't raised.

Edit2: Apparently my clarification wasn't to helpful. I want to raise an entire sentence, if I use \raisebox the sentence will overflow to the right (as seen in the example).

If this was HTML I would use <sup>some text</sup> which is able to handle line breaks.

5
  • 1
    What do you need this for? It's not really possible with TeX do that (it is with LuaTeX).
    – egreg
    Mar 23, 2012 at 22:33
  • Doing this in TeX requires a special "raised" font. I seem to recall a paper on TUGboat that describes how to do something similar with LuaTeX, but I can't find it.
    – egreg
    Mar 24, 2012 at 10:59
  • Since various answers have been given, would you please state clearly in your question that the raised text should begin in mid paragraph? Also some background would be useful: what are you trying to achieve?
    – egreg
    Mar 24, 2012 at 11:31
  • OK. What's the purpose? Long superscripted text is unreadable and destroys the page uniformity.
    – egreg
    Mar 24, 2012 at 14:12
  • @egreg: It's supposed to mark a handwritten addition to a manuscript. For this purpose I find it to be typographically appropriate.
    – Emerson
    Mar 24, 2012 at 14:34

4 Answers 4

15

As @egreg said this is not fully automatically possible with TeX for a simple reason: TeX offers no way to automatically determine the hyhenation points in a word and use them other than in the default manner.

But if you are prepared to mark up hyphenations yourself there are ways to get the rest automatically done. Below is a trivial implementation:

\documentclass{article}

\setlength\textwidth{8cm}

\def\X#1{\raisebox{0.5em}{#1}}

\def\Y#1#2#3{\discretionary{\X{#1}}{\X{#2}}{\X{#3}}} 

\begin{document}

Lorem ipsum dolor sit amet, consectetur 
\Y{adipisic-}{ing}{adipisicing} \X{elit,} \X{sed} do eiusmod tempor incididunt ut
 labore et dolore magna aliqua.

\end{document}

This results in

enter image description here

which is what I think you are looking for as the output. Of course this is not the way you would want to code it. With some small coding improvements you could use a syntax like

Lorem ipsum dolor sit amet, consectetur 
\begin{raisedtext}{0.5em}
  adipisic\-ing elit, sed
\end{raisedtext}
do eiusmod tempor incididunt ut labore et dolore magna aliqua.

where

  • possible hyphenation points are maked up by \-
  • a - would automatically be allowed as hyphenation point

Basically you would need to parse the text until the end of the environment looking for - or \- or "spaces" and construct stuff like \Y and \X from above accordingly (not doing that tonight :-)

Upate: a simple parser

okay so here is a simple parser that takes care of \- and explicit -. Not really cleanly written, sorry for that.

\documentclass{article}

\setlength\textwidth{8cm}

% we need space, -, and newline active and set to some commands
{\obeyspaces
\catcode`\^^M\active%
\catcode`\-\active%
\gdef\setraisedtextactivedef#1#2{\let =#1\let^^M=#1\let-=#2}}

\newbox\raisedtextbox

% main action is to collect material into a box
\def\collectraisedtext{\setbox\raisedtextbox\hbox\bgroup\raisedtextstyle
\gobbleactivespaces}

% and if we want we can use a special style
\def\raisedtextstyle{\small\itshape}

% at a space end collection, typeset and restart
\def\raisedtextspace{\egroup
       \X{\box\raisedtextbox}%
      \space
      \collectraisedtext
}                              

% at \- end colloection, typeset, add discretionary and restart
\def\raisedtextbreak{\egroup\X{\box\raisedtextbox}\discretionary{\X-}{}{}\collectraisedtext}
% at - (explicit hyphen) more or less the same
\def\raisedtexthyphen{\egroup\X{\box\raisedtextbox}\discretionary{\X-}{}{\X-}\collectraisedtext}

% several active spaces (or newlines) would do harm ...
\def\gobbleactivespaces{\futurelet\next\gobbleactivespacesX}
\def\gobbleactivespacesX{%
            \ifx\next\raisedtextspace
               \expandafter\gobbleactivespacesXX
           \fi
}
\def\gobbleactivespacesXX#1{\gobbleactivespaces}

% putting all together
\newenvironment{raisedtext}[1][0.5ex]
  {%
    \def\X##1{\raisebox{#1}{##1}}%
    \obeyspaces
    \catcode`\^^M\active
    \catcode`\-\active
    \setraisedtextactivedef\raisedtextspace\raisedtexthyphen
    \let\-\raisedtextbreak
    \collectraisedtext
}{%
% at end environment, end collection and typeset (if not empty). 
% Otherwise remove space already inserted before that collection
       \egroup
       \ifdim\wd\raisedtextbox>0pt  % weak prove that this is not empty
         \X{\box\raisedtextbox}%
       \else
         \unskip
       \fi
}

\begin{document}

Lorem ipsum dolor sit amet, consectetur 
\begin{raisedtext}
      adipisic-ing       elit,      sed
\end{raisedtext}
 do eiusmod tempor incididunt ut
 \begin{raisedtext}[1.5ex] la-bore-et do-lore
\end{raisedtext}  magna aliqua.

\end{document}

doing that gives us (with a style definition of \small\itshape)

enter image description here

2
  • Indeed, this is what I was looking for! It'd be great if you could write such an environment.
    – Emerson
    Mar 25, 2012 at 12:35
  • 1
    added a definition for this. Could certainly be done in a cleaner fashion but ... Mar 25, 2012 at 20:55
5

You need to use a box which allows the building of paragraphs first, like \parbox or the minipage environment. Both require the to be used line width as an argument, which might be an issue. There is also the varwidth environment based on minipage by the varwidth package, which takes the width argument only as maximal width.

You can try:

\usepackage{varwidth}
% ..
\raisebox{<amount>}{\begin{varwidth}{<max width>} multi \\ line \\ text\end{varwidth}}

An alternative is my adjustbox package, which provides raise, minipage and varwidth keys. It's basically the same as above but with a nicer interface:

\usepackage{adjustbox}
% ..
\adjustbox{varwidth=<max width>,raise=<amount>}{ multi \\ line \\ text }
% or:
\adjustbox{varwidth=<max width>,raise=<amount>}\bgroup multi \\ line \\ text \egroup
% or:
\begin{adjustbox}{varwidth=<max width>,raise=<amount>}
     multi \\ line \\ text
\end{adjustbox}

Note that \parbox, minipage and varwidth have optional arguments which determine the baseline of the produced box. These influence the placement of the text relative to other text outside the box but still on the same line.

3
  • I'm not sure that this answers the question (but it is admittedly not very clear).
    – egreg
    Mar 23, 2012 at 23:01
  • @egreg: That's the way I understand the question. Mar 23, 2012 at 23:04
  • Thanks, but that isn't what I was looking for.
    – Emerson
    Mar 24, 2012 at 10:53
3

You can simply raise a block of text by writing:

\vspace*{<-dimension>}

Adjust the (-5pt) in the MWE example to see how it works.

\documentclass[11pt]{article}
\usepackage{lipsum}
\parskip10pt
\parindent0pt
\begin{document}
First paragraph
\hrule

\vspace*{-5pt} 
\lipsum[1]
\end{document}
1

Like a \raise (in horizontal mode) with a \vbox? (plain-tex)

\hsize=24pc % just to make it break into lines

Lorem ipsum dolor sit amet,

\noindent\raise.5em\vbox{\noindent
  consectetur adipisicing elit, sed do
  eiusmod tempor incididunt ut labore et dolore magna aliqua.}

Lorem ipsum dolor sit amet.
\bye

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .