TransWikia.com

How to use inputenc, fontspec, fontenc, mathdesign and babel to properly render cyrillics and UTF-8 characters?

TeX - LaTeX Asked by Timur Fayzrakhmanov on January 21, 2021

MWE:

% main.tex
documentclass{article}

usepackage[utf8]{inputenc}
usepackage[urw-garamond]{mathdesign}
% usepackage{fontenc} T1,T2A?
% usepackage{fontspec} ?
usepackage[russian,english]{babel}

begin{document}
“Hello” is the same as “Привет”.
end{document}

How do I build:

lualatex -synctex=1 -interaction=nonstopmode -file-line-error -recorder main.tex

Log without usepackage[russian,english]{babel}:

Latexmk: This is Latexmk, John Collins, 26 Dec. 2019, version: 4.67.
Latexmk: All targets () are up-to-date

Output:

des


Log with usepackage[russian,english]{babel}:

Latexmk: This is Latexmk, John Collins, 26 Dec. 2019, version: 4.67.
Rule 'lualatex': File changes, etc:
   Changed files, or newly in use since previous run(s):
      '/home/timfayz/Dropbox/PhD/TeX/RandomDefinitions/main.tex'
      'main.tex'
------------
Run number 1 of rule 'lualatex'
------------
------------
Running 'lualatex  -synctex=1 -interaction=nonstopmode -file-line-error -recorder -output-directory="/home/timfayz/Dropbox/PhD/TeX/RandomDefinitions"  "/home/timfayz/Dropbox/PhD/TeX/RandomDefinitions/main.tex"'
------------
Latexmk: applying rule 'lualatex'...
This is LuaTeX, Version 1.10.0 (TeX Live 2019) 
 restricted system commands enabled.
(/home/timfayz/Dropbox/PhD/TeX/RandomDefinitions/main.tex
LaTeX2e <2020-02-02> patch level 5
 L3 programming layer <2020-02-25> (/usr/local/texlive/2019/texmf-dist/tex/latex/base/article.cls
Document Class: article 2019/12/20 v1.4l Standard LaTeX document class
(/usr/local/texlive/2019/texmf-dist/tex/latex/base/size10.clo)) (/usr/local/texlive/2019/texmf-dist/tex/latex/base/inputenc.sty

Package inputenc Warning: inputenc package ignored with utf8 based engines.

) (/usr/local/texlive/2019/texmf-dist/tex/latex/mathdesign/mathdesign.sty (/usr/local/texlive/2019/texmf-dist/tex/latex/graphics/keyval.sty) (/usr/local/texlive/2019/texmf-dist/tex/latex/base/ifthen.sty) (/usr/local/texlive/2019/texmf-dist/tex/latex/mathdesign/mdugm/mdugm.cfg) (/usr/local/texlive/2019/texmf-dist/tex/latex/mathdesign/mdugm/mdugm.sty (/usr/local/texlive/2019/texmf-dist/tex/latex/mathdesign/mdfont.def) (/usr/local/texlive/2019/texmf-dist/tex/latex/mathdesign/mdsffont.def

LaTeX Warning: Font shape declaration has incorrect series value `mc'.
               It should not contain an `m'! Please correct it.
               Found on input line 53.


LaTeX Warning: Font shape declaration has incorrect series value `mc'.
               It should not contain an `m'! Please correct it.
               Found on input line 56.


LaTeX Warning: Font shape declaration has incorrect series value `mc'.
               It should not contain an `m'! Please correct it.
               Found on input line 59.


LaTeX Warning: Font shape declaration has incorrect series value `mc'.
               It should not contain an `m'! Please correct it.
               Found on input line 79.


LaTeX Warning: Font shape declaration has incorrect series value `mc'.
               It should not contain an `m'! Please correct it.
               Found on input line 102.


LaTeX Warning: Font shape declaration has incorrect series value `mc'.
               It should not contain an `m'! Please correct it.
               Found on input line 105.


LaTeX Warning: Font shape declaration has incorrect series value `mc'.
               It should not contain an `m'! Please correct it.
               Found on input line 108.


LaTeX Warning: Font shape declaration has incorrect series value `mc'.
               It should not contain an `m'! Please correct it.
               Found on input line 128.


LaTeX Warning: Font shape declaration has incorrect series value `mc'.
               It should not contain an `m'! Please correct it.
               Found on input line 259.


LaTeX Warning: Font shape declaration has incorrect series value `mc'.
               It should not contain an `m'! Please correct it.
               Found on input line 262.


LaTeX Warning: Font shape declaration has incorrect series value `mc'.
               It should not contain an `m'! Please correct it.
               Found on input line 265.


LaTeX Warning: Font shape declaration has incorrect series value `mc'.
               It should not contain an `m'! Please correct it.
               Found on input line 268.


LaTeX Warning: Font shape declaration has incorrect series value `mc'.
               It should not contain an `m'! Please correct it.
               Found on input line 313.


LaTeX Warning: Font shape declaration has incorrect series value `mc'.
               It should not contain an `m'! Please correct it.
               Found on input line 316.


LaTeX Warning: Font shape declaration has incorrect series value `mc'.
               It should not contain an `m'! Please correct it.
               Found on input line 319.


LaTeX Warning: Font shape declaration has incorrect series value `mc'.
               It should not contain an `m'! Please correct it.
               Found on input line 322.

) (/usr/local/texlive/2019/texmf-dist/tex/latex/mathdesign/mdttfont.def) (/usr/local/texlive/2019/texmf-dist/tex/latex/xkeyval/xkeyval.sty (/usr/local/texlive/2019/texmf-dist/tex/generic/xkeyval/xkeyval.tex (/usr/local/texlive/2019/texmf-dist/tex/generic/xkeyval/xkvutils.tex)))

LaTeX Font Warning: Font shape `TU/mdugm/m/n' undefined
(Font)              using `TU/lmr/m/n' instead on input line 186.

) (/usr/local/texlive/2019/texmf-dist/tex/latex/base/fontenc.sty (/usr/local/texlive/2019/texmf-dist/tex/latex/mathdesign/mdugm/t1mdugm.fd))) (/usr/local/texlive/2019/texmf-dist/tex/latex/l3backend/l3backend-pdfmode.def) (/home/timfayz/Dropbox/PhD/TeX/RandomDefinitions/main.aux

Package babel Warning: Unknown language `russian'. Very likely you
(babel)                requested it in a previous run. Expect some
(babel)                wrong results in this run, which should vanish
(babel)                in the next one. Reported on input line 4.

) (/usr/local/texlive/2019/texmf-dist/tex/latex/base/ts1cmr.fd) (/usr/local/texlive/2019/texmf-dist/tex/latex/mathdesign/mdacmr.fd) (/usr/local/texlive/2019/texmf-dist/tex/latex/mathdesign/mdbcmr.fd) [1{/home/timfayz/.texlive2019/texmf-var/fonts/map/pdftex/updmap/pdftex.map}] (/home/timfayz/Dropbox/PhD/TeX/RandomDefinitions/main.aux)

LaTeX Font Warning: Some font shapes were not available, defaults substituted.

)
(see the transcript file for additional information)
 411 words of node memory still in use:
   3 hlist, 1 vlist, 1 rule, 2 glue, 3 kern, 1 glyph, 4 attribute, 49 glue_spec, 4 attribute_list, 1 write nodes
   avail lists: 2:15,3:2,4:1,5:21,6:1,7:36,9:7
{/usr/local/texlive/2019/texmf-dist/fonts/enc/dvips/ly1/texnansi.enc}</home/timfayz/.texmf/fonts/type1/urw/garamond/ugmr8a.pfb>
Output written on main.pdf (1 page, 13243 bytes).
SyncTeX written on main.synctex.gz.
Transcript written on main.log.
Latexmk: Log file says output to 'main.pdf'
Rule 'lualatex': File changes, etc:
   Changed files, or newly in use since previous run(s):
      '/home/timfayz/Dropbox/PhD/TeX/RandomDefinitions/main.aux'
      'main.aux'
------------
Run number 2 of rule 'lualatex'
------------
------------
Running 'lualatex  -synctex=1 -interaction=nonstopmode -file-line-error -recorder -output-directory="/home/timfayz/Dropbox/PhD/TeX/RandomDefinitions"  "/home/timfayz/Dropbox/PhD/TeX/RandomDefinitions/main.tex"'
------------
=== TeX engine is 'LuaTeX'
Latexmk: applying rule 'lualatex'...
This is LuaTeX, Version 1.10.0 (TeX Live 2019) 
 restricted system commands enabled.
(/home/timfayz/Dropbox/PhD/TeX/RandomDefinitions/main.tex
LaTeX2e <2020-02-02> patch level 5
 L3 programming layer <2020-02-25> (/usr/local/texlive/2019/texmf-dist/tex/latex/base/article.cls
Document Class: article 2019/12/20 v1.4l Standard LaTeX document class
(/usr/local/texlive/2019/texmf-dist/tex/latex/base/size10.clo)) (/usr/local/texlive/2019/texmf-dist/tex/latex/base/inputenc.sty

Package inputenc Warning: inputenc package ignored with utf8 based engines.

) (/usr/local/texlive/2019/texmf-dist/tex/latex/mathdesign/mathdesign.sty (/usr/local/texlive/2019/texmf-dist/tex/latex/graphics/keyval.sty) (/usr/local/texlive/2019/texmf-dist/tex/latex/base/ifthen.sty) (/usr/local/texlive/2019/texmf-dist/tex/latex/mathdesign/mdugm/mdugm.cfg) (/usr/local/texlive/2019/texmf-dist/tex/latex/mathdesign/mdugm/mdugm.sty (/usr/local/texlive/2019/texmf-dist/tex/latex/mathdesign/mdfont.def) (/usr/local/texlive/2019/texmf-dist/tex/latex/mathdesign/mdsffont.def

LaTeX Warning: Font shape declaration has incorrect series value `mc'.
               It should not contain an `m'! Please correct it.
               Found on input line 53.


LaTeX Warning: Font shape declaration has incorrect series value `mc'.
               It should not contain an `m'! Please correct it.
               Found on input line 56.


LaTeX Warning: Font shape declaration has incorrect series value `mc'.
               It should not contain an `m'! Please correct it.
               Found on input line 59.


LaTeX Warning: Font shape declaration has incorrect series value `mc'.
               It should not contain an `m'! Please correct it.
               Found on input line 79.


LaTeX Warning: Font shape declaration has incorrect series value `mc'.
               It should not contain an `m'! Please correct it.
               Found on input line 102.


LaTeX Warning: Font shape declaration has incorrect series value `mc'.
               It should not contain an `m'! Please correct it.
               Found on input line 105.


LaTeX Warning: Font shape declaration has incorrect series value `mc'.
               It should not contain an `m'! Please correct it.
               Found on input line 108.


LaTeX Warning: Font shape declaration has incorrect series value `mc'.
               It should not contain an `m'! Please correct it.
               Found on input line 128.


LaTeX Warning: Font shape declaration has incorrect series value `mc'.
               It should not contain an `m'! Please correct it.
               Found on input line 259.


LaTeX Warning: Font shape declaration has incorrect series value `mc'.
               It should not contain an `m'! Please correct it.
               Found on input line 262.


LaTeX Warning: Font shape declaration has incorrect series value `mc'.
               It should not contain an `m'! Please correct it.
               Found on input line 265.


LaTeX Warning: Font shape declaration has incorrect series value `mc'.
               It should not contain an `m'! Please correct it.
               Found on input line 268.


LaTeX Warning: Font shape declaration has incorrect series value `mc'.
               It should not contain an `m'! Please correct it.
               Found on input line 313.


LaTeX Warning: Font shape declaration has incorrect series value `mc'.
               It should not contain an `m'! Please correct it.
               Found on input line 316.


LaTeX Warning: Font shape declaration has incorrect series value `mc'.
               It should not contain an `m'! Please correct it.
               Found on input line 319.


LaTeX Warning: Font shape declaration has incorrect series value `mc'.
               It should not contain an `m'! Please correct it.
               Found on input line 322.

) (/usr/local/texlive/2019/texmf-dist/tex/latex/mathdesign/mdttfont.def) (/usr/local/texlive/2019/texmf-dist/tex/latex/xkeyval/xkeyval.sty (/usr/local/texlive/2019/texmf-dist/tex/generic/xkeyval/xkeyval.tex (/usr/local/texlive/2019/texmf-dist/tex/generic/xkeyval/xkvutils.tex)))

LaTeX Font Warning: Font shape `TU/mdugm/m/n' undefined
(Font)              using `TU/lmr/m/n' instead on input line 186.

) (/usr/local/texlive/2019/texmf-dist/tex/latex/base/fontenc.sty (/usr/local/texlive/2019/texmf-dist/tex/latex/mathdesign/mdugm/t1mdugm.fd))) (/usr/local/texlive/2019/texmf-dist/tex/latex/l3backend/l3backend-pdfmode.def) (/home/timfayz/Dropbox/PhD/TeX/RandomDefinitions/main.aux) (/usr/local/texlive/2019/texmf-dist/tex/latex/base/ts1cmr.fd) (/usr/local/texlive/2019/texmf-dist/tex/latex/mathdesign/mdacmr.fd) (/usr/local/texlive/2019/texmf-dist/tex/latex/mathdesign/mdbcmr.fd) [1{/home/timfayz/.texlive2019/texmf-var/fonts/map/pdftex/updmap/pdftex.map}] (/home/timfayz/Dropbox/PhD/TeX/RandomDefinitions/main.aux)

LaTeX Font Warning: Some font shapes were not available, defaults substituted.

)
(see the transcript file for additional information)
 411 words of node memory still in use:
   3 hlist, 1 vlist, 1 rule, 2 glue, 3 kern, 1 glyph, 4 attribute, 49 glue_spec, 4 attribute_list, 1 write nodes
   avail lists: 2:15,3:2,4:1,5:21,6:1,7:36,9:7
{/usr/local/texlive/2019/texmf-dist/fonts/enc/dvips/ly1/texnansi.enc}</home/timfayz/.texmf/fonts/type1/urw/garamond/ugmr8a.pfb>
Output written on main.pdf (1 page, 13243 bytes).
SyncTeX written on main.synctex.gz.
Transcript written on main.log.
Latexmk: Log file says output to 'main.pdf'
Latexmk: Summary of warnings from last run of (pdf)latex:
  =====Latex reported missing or unavailable character(s).
=====See log file for details.
=== TeX engine is 'LuaTeX'
Latexmk: All targets () are up-to-date

Output:

des


Here is what I’m trying to achieve:

  • I want to use URW Garamond and its mathdesign’s version for typing math
  • I want to have Cyrillic glyphs support (of course, if URW Garamond supports it, if it doesn’t – set another font only for the range of Russian characters)
  • I want to be able to use UTF-8 symbols in both text and math modes
  • I want to know how to list available fonts in my system (both their conventional names, as you will see in the examples below, and filenames). Or would be even better not only list names but to check if a font supports Russian glyphs.

With that being said I have no idea how to glue all these pieces together :(. What I know so far:

  • I need the mix of inputenc, fontspec, fontenc, mathdesign, babel in right order with the right options
  • Reading the logs didn’t give me anything useful for googling. I did a lot of trials and a lot readings on Russian websites but it gave me nothing. Seems like people just miraculously get it working.
  • I don’t know if I still need usepackage[utf8]{inputenc} at preamble. Do I (in 2020)? For I recently got the following Package inputenc Error: inputenc is not designed for xetex or luatex. (I don’t remember the circumstances but I saved it for worst)
  • Seems like babel redefines font afterwords which makes me totally confused. I though it doesn’t touch the font settings and we should use fontspec instead.
  • For the reason above, I have no idea how to properly manage all these peculiar font settings. We have a lot of methods to do the same things. Here is a bunch of commands that influence, explicitly or implicitly, the final font face:
% Method 1
usepackage{fontspec} 
setmainfont{EB Garamond}
setsansfont{CMU Sans Serif}
setmonofont{...}

% Method 2
usepackage{unicode-math}
setmathfont{texgyrepagella-math.otf}

% Method 3
usepackage{ebgaramond} % just an example at hand, I encountered other packages that redefine typefaces as well

% Method 4
babelfont{rm}{DejaVu Serif} % ?

Environment:

$ lualatex -v
This is LuaTeX, Version 1.10.0 (TeX Live 2019)
$ tlmgr version
tlmgr revision 53842 (2020-02-19 08:28:40 +0100)
tlmgr using installation: /usr/local/texlive/2019
$ latex -v
pdfTeX 3.14159265-2.6-1.40.20 (TeX Live 2019)
kpathsea version 6.3.1
$ latexmk -v
Latexmk, John Collins, 26 Dec. 2019. Version 4.67

Packages that I explicitly installed (see only uncommented lines):

tlmgr update --self
tlmgr install 
    collection-basic 
        # luatex 
    collection-latex 
    collection-latexrecommended 
        # fontspec 
    collection-luatex 
        # luaotfload 
        # lualatex-math 
    collection-fontsrecommended 
        # cm-super  # cyrillic support (T1 encoding)
    # collection-binextra 
        latexmk 
        texliveonfly  # resolve deps automagically
    # collection-pictures 
        pgfplots 
    # collection-latexextra 
        needspace 
        mdframed 
        multirow  # to create cells spanning multiple rows
    # collection-bibtexextra 
        biblatex biber  # modern bibliography engine + backend
    # collection-fontsextra 
        ebgaramond  # favorite serif font
        mathdesign  # favorite math + normal text font
        ly1  # resolve missing texnansi.enc
    # collection-langcyrillic 
        babel-russian  # russian support

urw-garamond was installed manually as suggested here

One Answer

Here is an example, to start you off on the Unicode track.

I will try and add to it over the next days and weeks. The answers to all the questions are almost like a set of mini tutorials.

Starting with general text:

tatar

font=Noto Serif; language=Tatar; textsource=Wikipedia; compiler=xelatex (or lualatex); texttopic=solar system; hyphenation-pattern=russian, via babel.

Exercise: Try the example without babel, and see what happens to the hyphenation.

documentclass[12pt]{article}
usepackage{fontspec}
setmainfont{Noto Serif}
usepackage[russian]{babel}%hyphenation
begin{document}
“Hello” is the same as “Привет”.
bigskip

tt Wikipedia
section*{Кояш системасы}

textbf{Кояш системасы} — Кояш йолдызы һәм аның тирәсендә әйләнә торган табигый галәми объектлар белән планеталар системасы.

Кояш системасының Кояштан тыш объектларының төп массасы сигез аерым планетада була. Алар эклиптика яссылыкта түгәрәккә якын орбиталар буенча хәрәкәт итәләр. Дүрт кечерәк эчке планета: Меркурий, Чулпан, Җир һәм Марс (җирсыман планеталар) гомумән силикатлардан һәм металлардан гыйбарәт була. Дүрт зуррак тышкы планета: Юпитер, Сатурн, Уран һәм Нептун (зур газлы планеталар) төп өлешендә водородтан һәм гелийдан гыйбарәт була һәм җирсыман планеталардан күпкә авыррак. 

end{document}

How to find a font

The fc-list utility is useful: fc-list :lang=zh-cn finds fonts that support Chinese (How can I list all the Chinese fonts I have installed? (Ubuntu, TexLive)).

An experiment: on my system (Windows), doing fc-list :lang=tt-tt, to find fonts supporting Tatar, produces a list which includes PT Sans font. Using that font as a test case in the MWE produces this:

PT Sans font

which looks alright, actually, from the glyph-coverage point of view, as far as I can tell (I have yet to learn Tatar).

There are other ways besides: looking in the font itself with a font editor or character map; listing font-features with xelatex/fontspec code (questions on this site); using free apps like BabelPad to examine a font's coverage of a Unicode block, or a Unicode block's coverage by which fonts; and so on.

Answered by Cicada on January 21, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP