Text Formatting ⇒ superscript
-
- 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.
NEW: TikZ book now 40% off at Amazon.com for a short time.

superscript
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:
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.
A quick example of how you might proceed:
Code: Select all
\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}
-
- Posts: 132
- Joined: Wed Feb 11, 2009 11:38 pm
superscript
Thanks! I can't use the accents package, though, it seems to conflict with some other package I am using, one of these,
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.
Code: Select all
\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}
Last edited by Stefan Kottwitz on Mon Jan 21, 2013 9:45 am, edited 1 time in total.
superscript
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:
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:
Here's a method using amsmath's \overset command, fairly similar to my first suggestion:
That definitely might require some vertical fine-tuning.
Finally, you could use a smashed tabular environment with b-placement:
Again, more vertical fine tuning may be necessary. Just modify the negative space with the \\.
And probably there are better ways too!
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:
Code: Select all
\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}
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:
Code: Select all
\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}
Code: Select all
\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}
Finally, you could use a smashed tabular environment with b-placement:
Code: Select all
\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}
And probably there are better ways too!
-
- Posts: 132
- Joined: Wed Feb 11, 2009 11:38 pm
superscript
Thanks alot! Your first solution works very well for me. One tiny problem left: I used
but now words beginning with an ö swallows the preceding space. I assume there is a simple, one command solution to this?
Code: Select all
\catcode`ö=\active
\defö{\overaccent{e}{o}}
Last edited by cgnieder on Mon Jan 21, 2013 1:55 pm, edited 1 time in total.
superscript
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:
Another makebox in the definition seems to help:
Code: Select all
\newcommand{\overaccent}[2]{%
\xspace\settoheight{\accentheight}{#2}%
\settowidth{\accentwidth}{#2}%
\makebox{\put(0,0){\makebox[\accentwidth]%
{\raisebox{1.2\accentheight}{\tiny #1}}}%
#2}}
-
- Posts: 132
- Joined: Wed Feb 11, 2009 11:38 pm
Re: superscript
It messes up the hyphenation, though …
-
- Posts: 132
- Joined: Wed Feb 11, 2009 11:38 pm
Re: superscript
Does anyone have a solution to the hyphenation problem?