2

I have a font with real OT-superscripts which I can use easily with the realscripts-package. But I also need a superscript decimal dot which doesn't exist, thus realscripts falls back to the regular form. This is the expected behaviour but I'd like to automatically substitute the \fakesuperscript{.} whereever \textsuperscript{.} occurs.

I tried a crude hack where I declare an arbitrary unicode char to be "period.superscript" and try to let Lua add it to the font-features. Both parts work on their own but not in combination; I suspect that the lua instruction is processed before the \newunicodechar, isn't it?

Is there a way to make my hack work by somehow changing the order of the processes?

Or is there any other way to make \fakesuperscripts be used as stand-ins for missing real superscripts? It doesn't matter for me whether all are replaced or whether I'd have to define them one by one. Either solution would be fine.

\documentclass{article}


\usepackage[no-math]{fontspec}
\setmainfont{Linux Libertine O}


\usepackage{realscripts}

\usepackage{newunicodechar}
\newunicodechar{}{\fakesuperscript{.}}

\directlua{
  fonts.handlers.otf.addfeature{
    name = "sups",
    type = "substitution",
    data = {
      period = "",
      ["period.onum"] = "",
      Q = "Ɋ",
      ["Q.onum"] = "Ɋ",
    },
  }
}


\begin{document}

I can use the defined char directly: o\textsuperscript{1}\textsuperscript{5}o

But not, as I hoped, via the superscript-command: o\textsuperscript{1.5}o

The \textsuperscript{Question} whether the Lua part works is obviously answerd by yes.

\end{document}
4

\newunicodechar{}{\fakesuperscript{.}} defines a command (an active char). This command is processed before any font related stuff is done. In period = "", the is not a command, it is a glyph. It will not expand to \fakesuperscript.

Imho the easiest would be to replace problematic symbols (this could also be done with lua, I'm using expl3-regex here):

\documentclass{article}

\usepackage[no-math]{fontspec}
\setmainfont{Linux Libertine O}

\usepackage{realscripts}

\ExplSyntaxOn
\NewDocumentCommand\mysuperscript{m}
{
  \tl_set:Nn\l_tmpa_tl{#1}
  \regex_replace_all:nnN {\.}{\c{fakesuperscript}\cB\{\.\cE\}}\l_tmpa_tl
  \regex_replace_all:nnN {\Q}{\c{fakesuperscript}\cB\{\Q\cE\}}\l_tmpa_tl
  \textsuperscript{\l_tmpa_tl}
}

\ExplSyntaxOff
\begin{document}

o\mysuperscript{1.5}
o\mysuperscript{Question}
\end{document}

enter image description here

  • Is the "1" really bold and the "5" lightface, or do I need new glasses? – barbara beeton Jun 13 at 14:43
  • @barbarabeeton it looks a bit like this, but it is not a problem of my code, with \textsuperscript you get the same, it must be the font. – Ulrike Fischer Jun 13 at 14:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.