3

I'm currently writing a small mathematical paper and have lots of unicode in my source-code - e.g.:

function y(
    𝐰::Vector{<:Number},
    Φ::(T where T <: Function),
    𝐱::Vector{<:Number})::(T where T <: Number)
    Σ(1, size(𝐰)[1], j->𝐰[j] * Φ(j, 𝐱))
end

The problem I'm now having is that I (for example) can't get it to render the 𝐰(U+1D430) and 𝐱. I get the following in my build-log:

Missing character: There is no 𝐰 in font Droid Sans Mono/OT:mapping=tex-text;!
Missing character: There is no 𝐱 in font Droid Sans Mono/OT:mapping=tex-text;!
Missing character: There is no 𝐱 in font Droid Sans Mono/OT:mapping=tex-text;!

and no matter what font I use it's this way. I'm 100% certain that my font (usually Fira Code) does support the character because it's also what I run in my source-code editor and there the characters show up just fine. I also made sure to test all the fallback fonts(hence the error message shows Droid Sans Mono) - but to no avail.

Does anyone have an idea on what else I could try to fix this?

EDIT: minimal working example

\documentclass{article}

\usepackage{minted}
\usepackage{fontspec}

\setmonofont[Mapping=tex-text, Scale=0.90,]{Fira Code}
%\setmonofont[Mapping=tex-text, Scale=0.90,]{Droid Sans Mono}

\begin{document}
  \begin{minted}{Julia}
      """Linear Regression
      # Args:
          𝐰: Parameters
          Φ(j, 𝐱): Basis function of type (Int, Vector{T}) -> T
          𝐱: Input vector
      """
      function y(
        𝐰::Vector{<:Number},
        Φ::(T where T <: Function),
        𝐱::Vector{<:Number})::(T where T <: Number)
          Σ(1, size(𝐰)[1], j->𝐰[j] * Φ(j, 𝐱))
      end
  \end{minted}
\end{document}

Fauty Output

  • 1
    Welcome to TeX SE. Could you provide a minimal working example showing the problem? It'll be easier to help you. – Alain Remillard Dec 18 '19 at 21:27
  • @AlainRemillard Thanks - totally forgot about the example - I just edited it in – SV-97 Dec 18 '19 at 21:47
  • I don't think that fira code has the chars. If I try {\ttfamily 𝐰 𝐱 𝐱 } I get clear missing char messages in the log. Your editor it probably using a fall back here. – Ulrike Fischer Dec 18 '19 at 23:24
2

I guess your aim is to print boldface w and x.

\documentclass{article}

\usepackage{minted}
\usepackage{fontspec}
\usepackage{newunicodechar}

\setmonofont{FiraMono}[
  Extension=.otf,
  UprightFont=*-Regular,
  BoldFont=*-Bold,
  Scale=0.9,
]

\newunicodechar{𝐰}{\textbf{w}}
\newunicodechar{𝐱}{\textbf{x}}

\begin{document}

\begin{minted}{Julia}
"""Linear Regression
# Args:
    𝐰: Parameters
    Φ(j, 𝐱): Basis function of type (Int, Vector{T}) -> T
    𝐱: Input vector
"""
function y(
  𝐰::Vector{<:Number},
  Φ::(T where T <: Function),
  𝐱::Vector{<:Number})::(T where T <: Number)
    Σ(1, size(𝐰)[1], j->𝐰[j] * Φ(j, 𝐱))
end
\end{minted}

\end{document}

enter image description here

  • works like a charm - thanks :D I had looked for something like that but couldn't find it – SV-97 Dec 19 '19 at 13:23
  • Optimal solution for a presentation. The resulting PDF produces a bold w (U+0077) rather than 𝐰 (U+1D430 mathematical small w), so semantic meaning of the symbol is lost in copy-paste. Mapping, or monospacing a math font in text mode, might provide ways to keep the meaning, if desired. – Cicada Dec 20 '19 at 12:48
  • @Cicada Do you know about a monospaced Unicode math font? – egreg Dec 20 '19 at 14:31
  • @egreg, I haven't come across any yet, but I'll have a look. There is also a workaround that might work, perhaps: typeset every glyph 1em wide. – Cicada Dec 21 '19 at 7:35
1

As per the comments.

A general text font is unlikely to be going to cover the 996 symbols of the Mathematical Alphanumeric Symbols code block in Unicode, let alone all the operators etc. A math font with Basic Latin glyphs, with everything in text mode (i.e., direct Unicode input) looks like it could work, if you make it the main font. All glyphs will print 'as-is', i.e., like ordinary glyphs, even though some are bold or not, some are italic or upright, some are sans or serif, etc. Asana Math and Latin Modern Math are two fonts like that. There are probably more. The reason is that the MAS defines 13 Latin alphabets, 5 and a bit Greek ones, and 5 types of Digits. The MAS is independent of the Basic Latin block, where the 'text' A-Z, a-z letters are.

symbols as text

I don't have shell-escape, so minted is inactive and I made manual line feeds.

MWE

\documentclass{article}

%\usepackage{minted}
\usepackage{fontspec}

\setmainfont[Mapping=tex-text, Scale=0.90,]{Latin Modern Math}
\begin{document}
%  \begin{minted}{Julia}
      """Linear Regression \\
      \# Args:\\
𝐰: Parameters\\
Φ(j, 𝐱): Basis function of type (Int, Vector{T}) $\to$ T\\
𝐱: Input vector\\
      """\\
      function y(\\
        𝐰::Vector{<:Number},\\
        Φ::(T where T <: Function),\\
        𝐱::Vector{<:Number})::(T where T <: Number)\\
          Σ(1, size(𝐰)[1], j->𝐰[j] * Φ(j, 𝐱))\\
      end\\
%  \end{minted}
\end{document}

If minted is the driver of the question, we will need to find a mono math font with basic Latin (alternatively, can minted accept $...$ math mode?).

=====

Edited to add:

egreg's \newunicodechar is quite powerful. In effect, it maps A to B: 𝐴↦𝐵, where 𝐴 is a glyph/character and 𝐵 is arbitrary code.

This in turn allows math mode material (like $\to$, attached to an arbitrary glyph) to be inserted into the minted output. $..$ material directly inside minted prints verbatim, otherwise.

As well as non-ASCII mathematical symbols and operators.

arrow and symbols

MWE

\documentclass[12pt]{article}

\usepackage{minted}
\usepackage{xcolor}
\usepackage{fontspec}
\usepackage{newunicodechar}

\setmonofont{Fira Mono}[
  Scale=0.9,
]

\newfontface\fmxm{XITS Math}[Colour=blue]

\newunicodechar{𝐰}{{\fmxm 𝐰}}
\newunicodechar{𝐱}{{\fmxm 𝐱}}
\newunicodechar{𝝫}{{\fmxm 𝝫}}
\newunicodechar{𝝨}{{\fmxm 𝝨}}
\newunicodechar{𝗷}{{\fmxm 𝗷}}
\newunicodechar{∗}{{\fmxm ∗}}

\newunicodechar{𔑱}{{\fmxm $\to$}}


\begin{document}

\begin{minted}{Julia}
"""Linear Regression
# Args:
    𝐰 : Parameters
    𝝫(𝗷, 𝐱): Basis function of type (Int, Vector{T}) 𔑱 T
    𝐱: Input vector
"""
function y(
  𝐰::Vector{<:Number},
  𝝫::(T where T <: Function),
  𝐱::Vector{<:Number})::(T where T <: Number)
    𝝨(1, size(𝐰)[1], 𝗷𔑱𝐰[𝗷] ∗ 𝝫(𝗷, 𝐱))
end
\end{minted}

\end{document}

A random Anatolian hieroglyph, 𔑱, is being used to carry the $\to$ into the output.

=====

Edit 2

Using code from here (How to change math font to monospace, only inside \texttt), and using newunicodechar as a key-value mechanism, gives:

ttmath

MWE

\documentclass{article}
\usepackage{newunicodechar}
\usepackage{minted}
\usepackage{amsmath}
\newcommand{\ttmath}{%
  \everymath{%
    {\scriptstyle\mathtt{}}%
    {\scriptscriptstyle\mathtt{}}%
    \mathtt{\xdef\tmp{\fam\the\fam\relax}\aftergroup\tmp}}}
\newcommand{\val}[1]{\bgroup\ttmath\texttt{#1}\egroup}

\newunicodechar{𔑪}{\ensuremath{x^2 + y^2 = z^2}; \val{1\ensuremath{\ensuremath{\cdot}10\ensuremath{^{-6}}}} (\ensuremath{a_0}, \ensuremath{m_{\text{e}}})}
\newunicodechar{𔑫}{$\alpha \to \beta$}
\newunicodechar{𔒽}{\ensuremath{abc + d\cdot f(x) = g_i}}
\newunicodechar{𔓣}{$\Phi = \phi(x,n)$;}

\begin{document}

\begin{minted}{Julia}
𔑪 : number
# xyz
function 𔑫
 𔓣
𔒽
𔒽
 𔒽
  𔒽
\end{minted}
\end{document}

Almost there.

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.