3

What is the simplest way to input π in text mode if there is only this one greek letter in the whole English text? May be there is one line of code can make it. The following excellent example is suggested by Manuel:

%%xelatex
\documentclass{article}
\usepackage{fontspec}\setmainfont{Linux Libertine O}
\begin{document}
this is letter π
\end{document}
12
  • 1
    Is $\pi$ a valid answer? :)
    – masu
    Dec 5, 2013 at 10:11
  • 2
    @masu Nope. In text mode~ Dec 5, 2013 at 10:12
  • 3
    \usepackage{textgreek} and \textpi. Or may be just take the necessary code for that letter. EDIT: you use fontspec? Then just load a font with the letter π, and write π in text mode.
    – Manuel
    Dec 5, 2013 at 10:16
  • 4
    @EdenHarder but what do you mean by text mode if I told you to use foobar package and then \tpi to get a text pi, would it matter if internally the package did \newcommand\tpi{$\pi$} ? $ is used internally all over the place, most minipages, parboxes, tabular etc are all inside $..$ That said, if you want a textual pi there are of course Greek text fonts yo could use (but if you want pi for the circle $\pi$ is probably the most natural encoding) Dec 5, 2013 at 10:23
  • 1
    @EdenHarder Would this “π” represent the number?
    – egreg
    Dec 5, 2013 at 10:49

1 Answer 1

6

Leave the hard work to textgreek. If you need the letter to work also in math mode, add a suitable definition with \newunicodechar.

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{textgreek}

% use these if you also want π to work in math mode
\usepackage{newunicodechar}
\newunicodechar{π}{\ifmmode\pi\else\textpi\fi}

\begin{document}
This is π as a letter in text mode and
we can use it also in math: $e^{πi}+1=0$
\end{document}

enter image description here


With XeLaTeX or LuaLaTeX and fontspec it is another matter. Your example

\documentclass{article}
\usepackage{fontspec}
\setmainfont{Linux Libertine O}
\begin{document}
this is letter π
\end{document}

works out of the box, because Linux Libertine does have Greek letters.

enter image description here

Just by way of example, let's suppose the main font doesn't have Greek letters; one can then use a workaround:

\documentclass{article}
\usepackage{fontspec,newunicodechar}

\setmainfont{Linux Libertine O}
\newfontfamily{\greekfont}{Futura} % just for a very different font

\newunicodechar{π}{{\greekfont π}}    \begin{document}

this is letter π
\end{document}

enter image description here

You can have a look at the ucharclasses package in case you have several characters missing from the main font.

5
  • Thanks so much! There may be some other ways, so let's wait for some time. Thanks again. Dec 5, 2013 at 12:11
  • Egreg, one of the tags is fontspec. Which will ease the problem partially (apart from using XeTeX), but I think we still don't know what @EdenHarder wants.
    – Manuel
    Dec 5, 2013 at 12:33
  • @Manuel I want to see what is the simplest way to solve this question. In the beginning, I think Then just load a font with the letter π, and write π in text mode may be the one but I DO not know what's the proper font (maybe with extended characters?). Now, I want to see what is the simplest way at last. Dec 5, 2013 at 12:45
  • @EdenHarder Perhaps you could make clearer what environment you're in: are you using XeLaTeX or LuaLaTeX with fontspec? If so, what's the document preamble?
    – egreg
    Dec 5, 2013 at 12:50
  • 1
    @EdenHarder But IF you are in XeLaTeX, with fontspec, you can write this is letter π and get no errors. That's why we don't know what your problem is and what are you really asking. As egreg said, add more info (a minimal working example would be great).
    – Manuel
    Dec 5, 2013 at 12:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .