# Text upside-down, characters rotated along baseline?

I'd like to achieve something like in the picture below:

Another example:

Note that the text is not simply rotated! I know it could be achieved by boxing each character separately, measuring the height and then raising by the missing amount to reach e.g. 1em... But I'm sure there is a better way around.

I'd like a macro that works for a whole line for instance (a whole paragraph would be even better! :) ).

Edit: Ascenders should protrude (as descenders) unless they have some special feature, like 'striketrough' in a 't'. Capitals should not protrude.

-
Interesting question! Is this just for the novelty value, or do you have an actual application for this? –  Jake Sep 19 '11 at 1:23
Something seems to be not quite right with your example picture: The ascender portion of the d becomes a descender after the rotation, but the t doesn't behave the same way (it should also protrude below the new baseline). How do you want the letters to behave? Should capitals protrude below the baseline? Should ascenders? –  Jake Sep 19 '11 at 1:38
@Jake: This is an actual setting for Facebook's display text and I was curious how this would look like done in LaTeX. :) I think the guys from Facebook just wanted to turn the text upside-down, but there might be some bug in the way it finally is rotated. –  Count Zero Sep 19 '11 at 1:53
For me the turned t does descend in Facebook. Probably depends on the font. –  Caramdir Sep 19 '11 at 4:10
I don't see any way to solve this without scanning the input character by character and doing the rotation (and shifting in some cases). Probably easy in LuaTeX. :) –  egreg Sep 19 '11 at 12:50

Thanks for all the answers! After doing some research myself and digging up some packages I never had used before, I also belive the input needs to be scanned charcter by character, as suggested by @egreg.

So here is a way of doing it in LaTeX:

\documentclass{minimal}

\usepackage{graphicx}
\usepackage{xstring}
\usepackage{forloop}

\begin{document}
\newcounter{idx}
\newcounter{posx}
\newcommand{\rotraise}[1]{%
\StrLen{#1}[\slen]
\forloop[-1]{idx}{\slen}{\value{idx}>0}{%
\StrChar{#1}{\value{idx}}[\crtLetter]%
\IfSubStr{tlQWERTZUIOPLKJHGFDSAYXCVBNM}{\crtLetter}
{\raisebox{\depth}{\rotatebox{180}{\crtLetter}}}
{\raisebox{1ex}{\rotatebox{180}{\crtLetter}}}}%
}
This is what I want to get.

\rotraise{This is what I want to get.}
\end{document}

Below you can admire the result. :)

-
Nice answer; I've taken the liberty of modifying it in order not to declare two new counters at each macro call. –  egreg Sep 19 '11 at 14:04
@egreg: Thanks for your addition, much appreciated! –  Count Zero Sep 19 '11 at 14:10

Facebook doesn't actually turn the letters around, it just (ab)uses various characters Unicode provides (e.g. IPA characters). With XeLaTeX or LuaLaTeX and a suitable font, you can do the same:

\documentclass{article}
\usepackage{fontspec}
\setmainfont{FreeSans}
\begin{document}
uʍop əpısdՈ
\end{document}

(Compile with xelatex or lualatex.)

The actual characters used here are:

u   latin small letter u
ʍ   latin small letter turned w
o   latin small letter o
p   latin small letter p
space
ə   latin small letter schwa
ı   latin small letter dotless i
s   latin small letter s
d   latin small letter d
Ո   armenian capital letter vo

The quality of the output is of course disputable.

-
Is there no way to do it in plain LaTeX? –  Count Zero Sep 19 '11 at 9:26
This is plain LaTeX, just rendered using XeLaTeX or LuaLaTeX. –  ℝaphink Sep 19 '11 at 15:51

Here are a couple of possibilities, using the facilities of the graphicx package:

\documentclass{article}
\usepackage{graphicx}

\parindent0pt

\begin{document}

Upside down\\
\rotatebox{180}{Upside down} Upside down \\
\rotatebox{180}{\reflectbox{Upside down}} Upside down and mirrored \\
\raisebox{\depth}{\rotatebox{180}{Upside down}} Upside down and raised to fit in line

\end{document}

Or you could possibly vary the {\depth} with a number.. say 0.5em to align the text with other non-rotated texts

-
+1 for simplest answer. –  SigmaX Feb 6 '13 at 22:32

I was a bit surprised to learn that this isn't catered for in TikZ's text decorations. However, a judicious insertion of a \rotatebox in to the code at the correct point (I hope) led to:

The code for that would be:

\documentclass{standalone}
%\url{http://tex.stackexchange.com/q/28861/86}

\usepackage{tikz}
\usetikzlibrary{decorations.transformedtext}

\begin{document}
\begin{tikzpicture}
\useasboundingbox (-1,1) -- (5,-1);
\path[decorate,decoration={transformed text along path,text={upside down}, text rotation=180}] (0,0) -- (5,0);
\end{tikzpicture}
\end{document}

if there was a PGF library pgflibrarydecorations.transformedtext.code.tex. The actual code for that is an extremely minor modification of pgflibrarydecorations.text.code.tex, but in order to make it an actual library it would need a little stress testing. For example, rotating the text only 90 degrees results in:

which is missing the space (maybe the box containing a space has width but not height?), and could do with a little more separation between the characters.

Incidentally, although this looks neat, it is working in exactly the manner said: walking along the text, measuring each character, and typsetting it in the correct place. It's just that this code (almost) already exists, and can be used to do:

which, I'm sure, is what Lewis Carroll would have written had he known about TeX and TikZ.

-
If you can also progressively reduce the font size it would be better. –  egreg Sep 20 '11 at 11:21
@Andrew Stacey: How can you work out the "walking along the text"? What TeX did you set up? –  NasuSama Sep 5 '13 at 1:03
@NasuSama I'm afraid I don't understand the question. As I said in my answer, this involves a small modification of one of the TikZ libraries. The "walking along the text" is done by the text decorations library, the modification is to allow for a transformation of said text. –  Loop Space Sep 5 '13 at 6:46