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'm using the unicode-math package in comination with xelatex. Thanks to this package I can write unicode symbols in the tex code. However some unicode symbols, don't compile the way I would expect it. For example, I hoped that if type $√{2+3}$ that this would compile the same way as $\sqrt{2+3}$. But I get this output:

enter image description here

What is happening here, and how can I fix this ?

Edit: I understand now that I can fix this using:

\usepackage{unicode-math,newunicodechar}
\newunicodechar{√}{\sqrt}

Now I'm wondering how I could define something like:

\unicodedef█#1{\begin{equation}#1\end{equation}}

share|improve this question
    
There is a difference between the character and a square root layout just as there is a difference between / and a fraction. The odd position is because TeX traditionally uses the height of character to specify the width of the rule, so it has small height and large depth. You could of course define √ to be an active character defined as \sqrt but that is not the default. –  David Carlisle Nov 7 '13 at 9:26
    
@DavidCarlisle Ah, I found it. So I need to do: \usepackage{unicode-math,newunicodechar} \newunicodechar{√}{\sqrt} –  Kasper Nov 7 '13 at 9:32

2 Answers 2

As you already figured out, by default is just printed as a usual symbol and not a mathematical object. Thus you must define it

\documentclass{article}
\usepackage{unicode-math}

\usepackage{newunicodechar}
\newunicodechar{√}{\sqrt}

Now you want to put the argument in between an equation environment. To do that you need to define an auxiliary macro which does that for you:

\newcommand\myeq[1]{\begin{equation}#1\end{equation}}
\newunicodechar{█}{\myeq}

But there are more options. You can also make the character \active manually and use it as command name

\catcode`▒=\active
\newcommand▒[1]{\begin{equation}#1\end{equation}}

Or you can mark the end of the equation by another character

\catcode`▙=\active
\long\def▙#1▜{\begin{equation}#1\end{equation}}

To do this with newunicodechar you need to define

\newunicodechar{▛}{\begin{equation}}
\newunicodechar{▟}{\end{equation}}

This has the possible problem, that when \begin{equation} is expanded, it can not see \end{equation} but only . Although it seems to work in my examples:

\begin{document}

█{√{a^2 + b^2} = c}

▒{a + b ≥ c}

▙e^{iπ} + 1 = 0▜

▛f(z) = \frac{1}{2πi}∫_{∂B_ε(z)}{\frac{f(ζ)}{ζ-z}\;\mathrm{d}ζ}▟

\end{document}
share|improve this answer
1  
\begin{equation} doesn't look up to find the matching \end{equation}, so this works (but I wouldn't recommend doing so). It won't work for align and the other multiline environments. In (Xe|Lua)LaTeX, \newunicodechar just makes the character active and defines it to what the second argument specifies. The definition is \protected, but not \long (which is irrelevant for a command with no argument). –  egreg Feb 27 at 13:43
    
With \newunicodechar no argument can be specified; but one can say \newcommand{\myeq}[1]{\begin{equation}#1\end{equation} and \newunicodechar{█}{\myeq}. Again, I wouldn't recommend doing so. –  egreg Feb 27 at 13:45
    
@egreg: Thanks for the details. The second comment is exactly what I wrote as the first suggestion ;-) –  canaaerus Feb 27 at 13:47
    
I should pay more attention. ;-) –  egreg Feb 27 at 13:55

as active character:

\documentclass{scrartcl}
\usepackage{unicode-math}
\setmathfont{XITS Math}

\begin{document}
$√2+3$ 

\catcode`\√=13 \let√\sqrt
$√{2+3}$
\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.