Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want XeLaTeX/minted to display all my mathematical characters from my .java source file.

More detailed: I file my programming homework in PDF documents in my university. I have been using LaTeX and listings to import my source code. I do a lot of mathematical programming and use a lot of mathematical symbols in my comments. As listings doesn't support utf-8 characters I have slowly been switching to minted + XeLaTeX. I keep common mathematical characters in a text file on my computer and copy them over to my .java files when commenting.

Let's consider following .tex file which I compile with $ xelatex -shell-escape minimal.

\documentclass[a4paper,oneside]{article}
\usepackage{fontspec}
\usepackage{xunicode}
%\usepackage{unicode-math}

% default, bw, perldoc
\usepackage{minted}
\usemintedstyle{perldoc}

\begin{document}

Document symbols.

≠≤≥×·÷±∓√~≈≅⇔¬∧∨∀∃∅∈∉⊆⊂∪∩∆ℕℤℝℂ∞Σ∑∏∫π

\begin{minted}{java}
// Java code
// ≠≤≥×·÷±∓√~≈≅⇔¬∧∨∀∃∅∈∉⊆⊂∪∩∆ℕℤℝℂ∞Σ∑∏∫π
\end{minted}

\end{document}

It only displays the characters ×·÷±√~¬∞∑ (PDF). Why is that? And is there a solution?

share|improve this question

migrated from stackoverflow.com Nov 3 '12 at 13:58

This question came from our site for professional and enthusiast programmers.

    
Did you tried specifying a font with \setmainfont{Some font name} that has all the needed symbols. On Stackoverflow its correctly displayed on my desktop, and the font-family is Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif so one of them is having the correct glyphs –  Alex Oct 18 '12 at 22:01
    
@Alex, thank you for your answer. I tried adding \setmainfont{DejaVu Sans Mono} and then all characters except ~ are displayed in the document - but NOT in the minted code. I don't care about that because I can use the $ math mode. I also tried setting other fonts for minted output: \begin{minted}[fontfamily=x]{java} (where tt, courier and helvetica are pre-defined for minted) but none of those produced any more of the math symbols. Is it possible to use other fonts in the minted code? My editor uses Monospace in my Ubuntu but I got error when trying \setmainfont{Monospace}. –  pegasus Oct 22 '12 at 10:57
    
With \setmainfont{FreeSerif} and \setmonofont{FreeMono} I get all the symbols in both situations. You can obtain the tilde in normal text with \string~. The font used should have the symbols. –  egreg Nov 3 '12 at 14:07

1 Answer 1

up vote 3 down vote accepted

The problem is that the font you're using, that is, Latin Modern, doesn't have the glyphs you want to be printed; you find in the log file something such as

Missing character: There is no ≠ in font [lmmono10-regular]!
Missing character: There is no ≤ in font [lmmono10-regular]!
Missing character: There is no ≥ in font [lmmono10-regular]!
Missing character: There is no ∓ in font [lmmono10-regular]!

The solution is to use a font that has these glyphs. The ~ has a special meaning in LaTeX, so either you input it as \string~ (not in the minted context) or set

\AtBeginDocument{\catcode`~=12 }

but this can break many constructs, so I don't recommend it.

\documentclass[a4paper,oneside]{article}
\usepackage{fontspec}
\setmainfont{FreeSerif}
\setmonofont{FreeMono}

% default, bw, perldoc
\usepackage{minted}
\usemintedstyle{perldoc}

\begin{document}

Document symbols.

≠≤≥×·÷±∓√\string~≈≅⇔¬∧∨∀∃∅∈∉⊆⊂∪∩∆ℕℤℝℂ∞Σ∑∏∫π

\begin{minted}{java}
// Java code
// ≠≤≥×·÷±∓√~≈≅⇔¬∧∨∀∃∅∈∉⊆⊂∪∩∆ℕℤℝℂ∞Σ∑∏∫π
\end{minted}

\end{document}

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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