Featured Book

LaTeX Beginners Guide

Who is online

In total there are 4 users online :: 0 registered, 0 hidden and 4 guests (based on users active over the past 5 minutes)
Most users ever online was 1327 on Tue Nov 05, 2013 7:11 pm

Users browsing this forum: No registered users and 4 guests

Partner Sites

TeXwelt - Fragen und Antworten goLaTeX
TeXblog
TeXnicCenter
TeXample

superscript

Add tags Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)

superscript

Postby Laurentius on Fri Dec 31st, 2010

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 3rd, 2011, edited 2 times in total.
Laurentius
 
Posts: 106
Joined: Wed Feb 11th, 2009

Re: superscript

Postby frabjous on Fri Dec 31st, 2010

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:

Code: Select all  •  Open in writeLaTeX
\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
oe.png (1.48 KiB) Viewed 1232 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.
User avatar
frabjous
 
Posts: 2065
Joined: Fri Mar 6th, 2009
Location: Amherst, MA

Re: superscript

Postby Laurentius on Sat Jan 1st, 2011

Thanks! I can't use the accents package, though, it seems to conflict with some other package I am using, one of these,

Code: Select all  •  Open in writeLaTeX
\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_K on Mon Jan 21st, 2013, edited 1 time in total.
Reason: code marked
Laurentius
 
Posts: 106
Joined: Wed Feb 11th, 2009

Re: superscript

Postby frabjous on Sat Jan 1st, 2011

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:

Code: Select all  •  Open in writeLaTeX
\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:
Code: Select all  •  Open in writeLaTeX
\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:

Code: Select all  •  Open in writeLaTeX
\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:

Code: Select all  •  Open in writeLaTeX
\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!
User avatar
frabjous
 
Posts: 2065
Joined: Fri Mar 6th, 2009
Location: Amherst, MA

Re: superscript

Postby Laurentius on Sat Jan 1st, 2011

Thanks alot! Your first solution works very well for me. One tiny problem left: I used

Code: Select all  •  Open in writeLaTeX
\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 21st, 2013, edited 1 time in total.
Reason: added code markup
Laurentius
 
Posts: 106
Joined: Wed Feb 11th, 2009

Re: superscript

Postby frabjous on Sat Jan 1st, 2011

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:

Code: Select all  •  Open in writeLaTeX
\newcommand{\overaccent}[2]{%
      \xspace\settoheight{\accentheight}{#2}%
      \settowidth{\accentwidth}{#2}%
      \makebox{\put(0,0){\makebox[\accentwidth]%
          {\raisebox{1.2\accentheight}{\tiny #1}}}%
          #2}}
User avatar
frabjous
 
Posts: 2065
Joined: Fri Mar 6th, 2009
Location: Amherst, MA

Re: superscript

Postby Laurentius on Sat Jan 1st, 2011

Brilliant! Thank you.
Laurentius
 
Posts: 106
Joined: Wed Feb 11th, 2009

Re: superscript

Postby Laurentius on Mon Jan 3rd, 2011

It messes up the hyphenation, though …
Laurentius
 
Posts: 106
Joined: Wed Feb 11th, 2009

Re: superscript

Postby Laurentius on Mon Jan 21st, 2013

Does anyone have a solution to the hyphenation problem?
Laurentius
 
Posts: 106
Joined: Wed Feb 11th, 2009


Return to Text Formatting

Who is online

Users browsing this forum: No registered users and 4 guests