LaTeX forum ⇒ Text Formattingsuperscript

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

Postby Laurentius » Fri Dec 31, 2010 4:18 pm

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.

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am
Location: Amherst, MA

Postby frabjous » Fri Dec 31, 2010 6:53 pm

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:

  1. \documentclass{article}
  2. \usepackage{amsmath}
  3. \usepackage{accents}
  4.  
  5. \newcommand{\overaccent}[2]{\ensuremath{\accentset{\text{\tiny #1}}{\text{#2}}}}
  6.  
  7. \begin{document}
  8.  
  9. k\overaccent{e}{o}nnen
  10.  
  11. \end{document}


oe.png
oe.png (1.48 KiB) Viewed 1751 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.

Link:
BBcode:
HTML:
Hide post links
Show post links

Laurentius
Posts: 132
Joined: Wed Feb 11, 2009 11:38 pm

Postby Laurentius » Sat Jan 01, 2011 5:15 am

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

  1. \RequirePackage{fontspec} % can be made [quiet].
  2. \RequirePackage{xltxtra} % includes fontspec and xunicode
  3. \RequirePackage{graphicx}
  4. \RequirePackage{soul} % spaces out
  5. \RequirePackage[polutonikogreek,latin,french,danish,german,english]{babel}
  6. \RequirePackage{multicol}
  7. \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

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am
Location: Amherst, MA

Postby frabjous » Sat Jan 01, 2011 6:10 am

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:

  1. \documentclass{article}
  2. \usepackage{fontspec} % can be made [quiet].
  3. \usepackage{xltxtra} % includes fontspec and xunicode
  4. \usepackage{graphicx}
  5. \usepackage{soul} % spaces out
  6. \usepackage[polutonikogreek,latin,french,danish,german,english]{babel}
  7. \usepackage{multicol}
  8. \usepackage[commabeforerest,bibformat={compress,ibidem},oxford,ibidem=strict,opcit,titleformat={}]{jurabib}
  9.  
  10. \newlength{\accentheight}
  11. \newlength{\accentwidth}
  12.  
  13. \newcommand{\overaccent}[2]{%
  14. \settoheight{\accentheight}{#2}%
  15. \settowidth{\accentwidth}{#2}%
  16. \put(0,0){\makebox[\accentwidth]%
  17. {\raisebox{1.2\accentheight}{\tiny #1}}}%
  18. #2}
  19.  
  20. \begin{document}
  21.  
  22.  
  23. k\overaccent{e}{o}nnen
  24.  
  25. \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:
  1. \documentclass{article}
  2. \usepackage{fontspec} % can be made [quiet].
  3. \usepackage{xltxtra} % includes fontspec and xunicode
  4. \usepackage{graphicx}
  5. \usepackage{soul} % spaces out
  6. \usepackage[polutonikogreek,latin,french,danish,german,english]{babel}
  7. \usepackage{multicol}
  8. \usepackage[commabeforerest,bibformat={compress,ibidem},oxford,ibidem=strict,opcit,titleformat={}]{jurabib}
  9.  
  10. \newcommand{\overaccent}[2]{\shortstack{\tiny #1\\#2}}
  11.  
  12. \begin{document}
  13.  
  14.  
  15. k\overaccent{e}{o}nnen
  16.  
  17. \end{document}


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

  1. \documentclass{article}
  2. \usepackage{amsmath}
  3. \usepackage{fontspec} % can be made [quiet].
  4. \usepackage{xltxtra} % includes fontspec and xunicode
  5. \usepackage{graphicx}
  6. \usepackage{soul} % spaces out
  7. \usepackage[polutonikogreek,latin,french,danish,german,english]{babel}
  8. \usepackage{multicol}
  9. \usepackage[commabeforerest,bibformat={compress,ibidem},oxford,ibidem=strict,opcit,titleformat={}]{jurabib}
  10.  
  11. \newcommand{\overaccent}[2]{\ensuremath{\overset{\text{\tiny #1}}{\text{#2}}}}
  12.  
  13. \begin{document}
  14.  
  15. k\overaccent{e}{o}nnen
  16.  
  17. \end{document}


That definitely might require some vertical fine-tuning.

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

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


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

And probably there are better ways too!

Link:
BBcode:
HTML:
Hide post links
Show post links

Laurentius
Posts: 132
Joined: Wed Feb 11, 2009 11:38 pm

Postby Laurentius » Sat Jan 01, 2011 7:20 am

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

  1. \catcode`ö=\active
  2. \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.
Reason: added code markup

Link:
BBcode:
HTML:
Hide post links
Show post links

User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am
Location: Amherst, MA

Postby frabjous » Sat Jan 01, 2011 5:19 pm

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:

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

Link:
BBcode:
HTML:
Hide post links
Show post links

Laurentius
Posts: 132
Joined: Wed Feb 11, 2009 11:38 pm

Postby Laurentius » Sat Jan 01, 2011 5:40 pm

Brilliant! Thank you.

Link:
BBcode:
HTML:
Hide post links
Show post links

Laurentius
Posts: 132
Joined: Wed Feb 11, 2009 11:38 pm

Postby Laurentius » Mon Jan 03, 2011 10:03 pm

It messes up the hyphenation, though …

Link:
BBcode:
HTML:
Hide post links
Show post links

Laurentius
Posts: 132
Joined: Wed Feb 11, 2009 11:38 pm

Postby Laurentius » Mon Jan 21, 2013 5:30 am

Does anyone have a solution to the hyphenation problem?

Link:
BBcode:
HTML:
Hide post links
Show post links


Return to “Text Formatting”

Who is online

Users browsing this forum: No registered users and 3 guests