3

There are some utf8 symbols (ĉ ĝ ...) in the input for pdflatex and I use in preambula commands like

\DeclareUnicodeCharacter{0109}{$\hat{c}$}, 
\DeclareUnicodeCharacter{011D}{$\hat{g}$}

and so on with \hat, \acute, \grave,\ddot, \tilde, \check, \bar, \breve
(to avoid messages like: Unicode char \u8:ǹ not set up for use with LaTeX ). So I replace symbols (utf8) by appropriate latex commands in math mode. Do any bad situations can be with this because commands are in math mode and do I must change to use text mode commands? It works, no error. I worry about future use of this preambula, do I shall be in trouble with it. Here is part of the whole text:

\documentclass[12pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{textcomp}
\usepackage{amstext}

\usepackage{cmap}       
\usepackage[T1,T2A]{fontenc}   
\usepackage[english,russian]{babel}

\usepackage{textalpha}   % Greek symbols

%Latin Accents

\DeclareUnicodeCharacter{01F4}{$\acute{G}$}

\DeclareUnicodeCharacter{01F5}{$\acute{g}$}

\DeclareUnicodeCharacter{1E30}{$\acute{K}$}
\DeclareUnicodeCharacter{1E31}{$\acute{k}$}
\DeclareUnicodeCharacter{1E3E}{$\acute{M}$}
\DeclareUnicodeCharacter{1E3F}{$\acute{m}$}
\DeclareUnicodeCharacter{1E54}{$\acute{P}$}
\DeclareUnicodeCharacter{1E55}{$\acute{p}$}
\DeclareUnicodeCharacter{1E82}{$\acute{W}$}
\DeclareUnicodeCharacter{1E83}{$\acute{w}$}


% GREEK Symbols var

\DeclareUnicodeCharacter{03B5}{$\varepsilon$}
\DeclareUnicodeCharacter{03F0}{$\varkappa$}
\DeclareUnicodeCharacter{03C6}{$\varphi$}
\DeclareUnicodeCharacter{03D6}{$\varpi$}
\DeclareUnicodeCharacter{03F1}{$\varrho$}
\DeclareUnicodeCharacter{03C2}{$\varsigma$}
\DeclareUnicodeCharacter{03D1}{$\vartheta$}

\usepackage{amsmath}

\usepackage{amssymb}

\begin{document}

==

Acute: á ć é ǵ í ḱ ĺ ḿ ń ó ṕ ŕ ś ú ẃ ý ź Á Ć É Ǵ Í Ḱ Ĺ Ḿ Ń Ó Ṕ Ŕ Ś Ú Ẃ Ý Ź   \\

α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ ς σ τ υ φ χ ψ ω Α Β Γ Δ Ε Ζ Η Θ
Ι Κ Λ Μ Ν Ξ Ο Π Ρ Σ Τ Υ Φ Χ Ψ Ω 

var греческие буквы

varepsilon ε   
varkappa ϰ    
varphi φ     
varpi ϖ     
varrho ϱ     
varsigma ς     
vartheta ϑ    

\end{document}
3
  • 1
    It is not so clear what for you need those. Like they stand now, you are declaring italic characters of your math font. Don't know if that works, but it looks strange. Please provide some minimal code which does result in the mentioned error and we try to help you on this. Maybe this is an easier approach. Thanks.
    – LaRiFaRi
    Jun 5, 2015 at 7:38
  • If you use those letters in text, you should use \^c and \^g.
    – egreg
    Jun 5, 2015 at 8:15
  • It works - no error, I worry about future use of this preambula - will not I be in trouble. Here is the whole text:
    – vmk
    Jun 5, 2015 at 9:07

2 Answers 2

7

You can declare characters for use in text or math or both

\DeclareUnicodeCharacter{0109}{\^c}
\DeclareUnicodeCharacter{0109}{\hat{c}}
\DeclareUnicodeCharacter{0109}{\ifmmode\hat{c}\else\^{c}\fi}
\DeclareUnicodeCharacter{0109}{\TextOrMath{\^{c}}{\hat{c}}}

But the definition that you suggest

\DeclareUnicodeCharacter{0109}{$\hat{c}$}

is the worst of both worlds, it can not be used in math because of the $ but it will do the wrong thing, using math fonts not text fonts, if used in text.

6
  • 1
    Possibly \TextOrMath?
    – egreg
    Jun 5, 2015 at 8:20
  • 1
    Remember to load fixltx2e or use TeX Live 2015
    – egreg
    Jun 5, 2015 at 8:37
  • @vmk the \ifmmode one should work. what error do you get? Jun 5, 2015 at 9:49
  • and there was error message for both ifmmode and TextOrMath: Please use \mathaccents for accents in math mode
    – vmk
    Jun 5, 2015 at 9:52
  • @vmk you do not want $ in the definition. Jun 5, 2015 at 10:29
1

If you really(!) need to do it with math-characters you can use

\DeclareUnicodeCharacter{0109}{\ensuremath{\mathrm{\hat{c}}}}

\ensuremath makes sure you use math-mode (whether you are in a math-environment or not). \mathrm switches to upright math-font and should make it consistent with normal text.

3
  • There is no requirement that the font used for \mathrm is the same as the roman font used ion text although it happens to be the case with the default cm font setup) and of course this will always give upright roman even if the surrounding text is italic or bold or whatever. Jun 5, 2015 at 9:51
  • @DavidCarlisle True indeed, unless there is a method to check for surrounding text shape, it'll only work for upright text!
    – Horst
    Jun 5, 2015 at 13:18
  • 2
    @Horst it doesn't really work for upright text either, only by accident in some font setups where \mathrm matches the text font. Jun 5, 2015 at 16:23

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.