## LaTeX forum ⇒ Text Formatting ⇒ superscript

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Laurentius
Posts: 132
Joined: Wed Feb 11, 2009 11:38 pm

### superscript

Is there a simple way to create a superscript above a normal letter? F. ex., the ¨ in the German ü is a superscribed e. If one wanted to substitute for this corrupt ¨ the original e, how might one proceed?
Last edited by Laurentius on Mon Jan 03, 2011 10:02 pm, edited 2 times in total.

frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am
Location: Amherst, MA
You could use the accents package. It is designed for math mode, but if you escape back to textmode with amsmath's \text command, you can make it work pretty well in text mode. I played around with some ways of doing this using only text mode commands, but wasn't able to do any better, and this seems to work just fine.

A quick example of how you might proceed:

\documentclass{article}\usepackage{amsmath}\usepackage{accents} \newcommand{\overaccent}[2]{\ensuremath{\accentset{\text{\tiny #1}}{\text{#2}}}} \begin{document} k\overaccent{e}{o}nnen \end{document}

oe.png (1.48 KiB) Viewed 1949 times

If you really want it the size of a regular superscript, you could use \scriptsize instead of \tiny, but I think it looks better with \tiny.

Laurentius
Posts: 132
Joined: Wed Feb 11, 2009 11:38 pm
Thanks! I can't use the accents package, though, it seems to conflict with some other package I am using, one of these,

\RequirePackage{fontspec} % can be made [quiet].\RequirePackage{xltxtra} % includes fontspec and xunicode\RequirePackage{graphicx}\RequirePackage{soul} % spaces out\RequirePackage[polutonikogreek,latin,french,danish,german,english]{babel}\RequirePackage{multicol}\RequirePackage[commabeforerest,bibformat={compress,ibidem},oxford,ibidem=strict,opcit,titleformat={}]{jurabib}

Did you manage to do it perfectly in text mode? I guess one would have to get the width of the o and the space between and kern-(space+width/2) and raisebox, but I don't know how to get the width.
Last edited by Stefan Kottwitz on Mon Jan 21, 2013 9:45 am, edited 1 time in total.
Reason: code marked

frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am
Location: Amherst, MA
A couple things about your sample -- you shouldn't use \RequirePackage in your document. That's for use inside packages that require other packages. Use \usepackage instead. Also if you're using fontspec and xltxtra, you're using XeLaTeX to compile, in which case you probably shouldn't use babel, but polyglossia, to set up language-specific hyphenation, etc., if at all possible.

It's possible that with some juggling of the order of the packages, you could make the accents package compatible. But it's not worth it. There are many ways to achieve what you want.

You mentioned getting the width of the "o". You can get the width of something with the \settowidth command. (There's also the \widthof command from the calc package, but I prefer \settowidth since it doesn't require any packages.) Actually, combing this with \settoheight gives you a nice albeit complicated way to handle this, something like:

\documentclass{article}\usepackage{fontspec} % can be made [quiet].\usepackage{xltxtra} % includes fontspec and xunicode\usepackage{graphicx}\usepackage{soul} % spaces out\usepackage[polutonikogreek,latin,french,danish,german,english]{babel}\usepackage{multicol}\usepackage[commabeforerest,bibformat={compress,ibidem},oxford,ibidem=strict,opcit,titleformat={}]{jurabib} \newlength{\accentheight}\newlength{\accentwidth} \newcommand{\overaccent}[2]{%       \settoheight{\accentheight}{#2}%       \settowidth{\accentwidth}{#2}%       \put(0,0){\makebox[\accentwidth]%           {\raisebox{1.2\accentheight}{\tiny #1}}}%           #2} \begin{document}  k\overaccent{e}{o}nnen \end{document}

You may want to tweak the multiplier before the use of \accentheight for the raisebox to your liking.

But I considered a bunch of other options, all of which work OK; my main reason for preferring that option was these others seem to require more manual tweaking of the vertical placement. Here are three other options. Take your pick.

Using \shortstack:
\documentclass{article}\usepackage{fontspec} % can be made [quiet].\usepackage{xltxtra} % includes fontspec and xunicode\usepackage{graphicx}\usepackage{soul} % spaces out\usepackage[polutonikogreek,latin,french,danish,german,english]{babel}\usepackage{multicol}\usepackage[commabeforerest,bibformat={compress,ibidem},oxford,ibidem=strict,opcit,titleformat={}]{jurabib} \newcommand{\overaccent}[2]{\shortstack{\tiny #1\\#2}} \begin{document}  k\overaccent{e}{o}nnen \end{document}

Here's a method using amsmath's \overset command, fairly similar to my first suggestion:

\documentclass{article}\usepackage{amsmath}\usepackage{fontspec} % can be made [quiet].\usepackage{xltxtra} % includes fontspec and xunicode\usepackage{graphicx}\usepackage{soul} % spaces out\usepackage[polutonikogreek,latin,french,danish,german,english]{babel}\usepackage{multicol}\usepackage[commabeforerest,bibformat={compress,ibidem},oxford,ibidem=strict,opcit,titleformat={}]{jurabib} \newcommand{\overaccent}[2]{\ensuremath{\overset{\text{\tiny #1}}{\text{#2}}}} \begin{document} k\overaccent{e}{o}nnen \end{document}

That definitely might require some vertical fine-tuning.

Finally, you could use a smashed tabular environment with b-placement:

\documentclass{article}\usepackage{amsmath}\usepackage{fontspec} % can be made [quiet].\usepackage{xltxtra} % includes fontspec and xunicode\usepackage{graphicx}\usepackage{soul} % spaces out\usepackage[polutonikogreek,latin,french,danish,german,english]{babel}\usepackage{multicol}\usepackage[commabeforerest,bibformat={compress,ibidem},oxford,ibidem=strict,opcit,titleformat={}]{jurabib} \newcommand{\overaccent}[2]{\smash{\begin{tabular}[b]{@{}c@{}} \tiny #1 \\[-1.5ex] #2 \end{tabular}}} \begin{document} k\overaccent{e}{o}nnen \end{document}

Again, more vertical fine tuning may be necessary. Just modify the negative space with the \\.

And probably there are better ways too!

Laurentius
Posts: 132
Joined: Wed Feb 11, 2009 11:38 pm
Thanks alot! Your first solution works very well for me. One tiny problem left: I used

\catcodeö=\active\defö{\overaccent{e}{o}}

but now words beginning with an ö swallows the preceding space. I assume there is a simple, one command solution to this?
Last edited by cgnieder on Mon Jan 21, 2013 1:55 pm, edited 1 time in total.

frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am
Location: Amherst, MA
The problem isn't with your active character definition -- you get the same misbehavior with my definition even if you don't use the active character. I should have tested it more thoroughly. Sorry.

Another makebox in the definition seems to help:

\newcommand{\overaccent}[2]{%       \xspace\settoheight{\accentheight}{#2}%       \settowidth{\accentwidth}{#2}%       \makebox{\put(0,0){\makebox[\accentwidth]%           {\raisebox{1.2\accentheight}{\tiny #1}}}%           #2}}`

Laurentius
Posts: 132
Joined: Wed Feb 11, 2009 11:38 pm
Brilliant! Thank you.

Laurentius
Posts: 132
Joined: Wed Feb 11, 2009 11:38 pm
It messes up the hyphenation, though …

Laurentius
Posts: 132
Joined: Wed Feb 11, 2009 11:38 pm
Does anyone have a solution to the hyphenation problem?