[Tex/LaTex] Ångström sign not outputting correctly with libertine OT1 font

font-encodingslibertineligaturessiunitx

I have this document:

\documentclass{article}
\usepackage[OT1]{fontenc}
\usepackage{libertine}
%\UndeclareTextCommand{\l}{OT1}
%\DeclareTextSymbolDefault{\l}{T1}

%\UndeclareTextCommand{\AA}{OT1}
%\DeclareTextSymbolDefault{\AA}{T1}

%\let\oldAA\AA
%\renewcommand{\AA}{\begingroup\fontencoding{T1}\selectfont\oldAA\endgroup}

\usepackage{amsmath}
\usepackage{siunitx}

%\DeclareSIUnit{\angstrom}{\AA}

\begin{document}

This is Quantifiably Efficiently Ligatured Text.

\AA

\si{\angstrom}

\l

\capitalring{A}

\end{document}

As you can see, the ł character is misprinted. I got that sorted out in this question, which is the first two commented lines, taking that specific symbol from the T1 encoding. I'm having similar issues with the Å symbol through the siunitx package. This checks for the default encoding and selects either \AA or \capitalring{A}:

\str_if_eq:VnT \encodingdefault { OT1 }
  {
    \__siunitx_option_unchanged:Nnn \l__siunitx_angstrom_math_tl
      { \text { \AA } }
      { \text { \capitalring { A } } }
    \__siunitx_option_unchanged:Nnn \l__siunitx_angstrom_text_tl
      { \AA }
      { \capitalring { A } }
  }

Hence, the MWE above checking these commands. Problem is, I can't get the symbol to show properly through siunitx. The second pair of commented lines follows the fix I got from the ł issue. But that just freezes the LaTeX compiler. The third pair of commented lines fix the \AA command, but I can't seem to make siunitx use it (final commented line).

Is there any way for the siunitx package to use the T1 encoded \AA (which is exacltly what I need)?
Note that I need OT1 encoding for cool ligatures (especially the Qu) displayed in the first sentence,a nd they disappear if I don't use OT1.

Best Answer

The command \AA is not encoding specific and this is the reason for the error: its definition is \r{A}. Unfortunately, the ring accent macro in OT1 encoding doesn't work well with the Libertine font, so you can adopt an ad hoc definition:

\documentclass{article}
\usepackage[T1,OT1]{fontenc}
\usepackage{libertine}

\usepackage{amsmath}
\usepackage{siunitx}

\DeclareSIUnit{\angstrom}{\mbox{\normalfont\AA}}

\UndeclareTextCommand{\l}{OT1}
\DeclareTextSymbolDefault{\l}{T1}

\makeatletter
\DeclareRobustCommand{\AA}{%
  \leavevmode
  \vbox{\ialign{##\cr
    \hidewidth\char'27 \hidewidth\cr
    \noalign{\nointerlineskip\kern-1.4ex}
    A\cr
  }}%
}
\makeatother


\begin{document}

This is Quantifiably Efficiently Ligatured Text.

\si{\angstrom}

\l

\end{document}

I'm afraid that \AA will not work in other font shapes (italic, especially). If you just use it for the angstrom unit (which you shouldn't, by the way), it's good.

enter image description here

Related Question