LuaTeX Questions and Answers 9781534601161

If you have a question about LuaTeX this is the book with the answers. LuaTeX: Questions and Answers takes some of the b

4,012 199 12MB

English Pages 1312 Year 2016

Report DMCA / Copyright

DOWNLOAD FILE

Polecaj historie

LuaTeX Questions and Answers
 9781534601161

Table of contents :
Table of Contents......Page 1
About this book......Page 3
Q: Which Lua environment should I use with LuaTeX (LuaLaTeX)?......Page 4
Q: Why should I be interested in Lua?......Page 7
Q: LuaJIT and LuaTeX......Page 10
Q: "Lua tree" (analogue of texmf tree)......Page 12
Q: How to read a file with luatex......Page 13
Q: Can the Lua part of LuaTeX know about tokens?......Page 18
Q: \documentclass: undefined control sequence......Page 20
Q: How to access LaTeX lengths in LuaTex?......Page 22
Q: Would you consider Luatex to be ready for a production environment......Page 24
Q: how for Lua commands......Page 27
Q: luatex and starting TeX macros which handle new line characters......Page 29
Q: Problem using length operator in Lua......Page 33
Q: LuaLaTeX for dummies: how to add LaTeX macros into \directlua?......Page 37
Q: Printing LaTeX code in LuaTeX......Page 39
Q: In which order is Lua Code in LuaTeX being processed......Page 43
Working with Google......Page 50
Processing the Data......Page 51
Q: What does \luaescapestring do for us?......Page 53
Q: The strange \luaescapestring in LuaTeX......Page 56
Q: Can I create a node list from some text entirely within lua?......Page 58
Q: How to access LaTeX counters in luatex?......Page 62
Q: How to do a 'printline' in LuaTeX......Page 65
Q: percent signs in luacode* environment (LuaLaTeX)......Page 67
Q: Interactive lualatex compiling......Page 69
Q: Get value of macro from lualatex directly......Page 71
Q: My first luaLaTeX example......Page 73
Q: How to check for Lua definitions......Page 79
Q: LuaLaTeX, sprint verbatim text......Page 80
Q: Accessing pointers in LuaTeX......Page 83
Q: LuaTeX gets stuck when "." is added to pattern-expression......Page 84
Q: Cannot access arguments in a lua block......Page 87
Q: Problem with luacode in sty file......Page 90
Q: LuaTeX: \luaexec leads to 'Missing number, treated as zero.'......Page 93
Q: Token expansion with the token library......Page 94
Q: Using lua code to obtain rules of different lengths......Page 95
Q: How to convert glue spec like `\parfillskip=0pt plus 1fil' to LuaTeX glue node......Page 97
Q: lualatex print, directlua env, and newline......Page 99
Q: lualatex: how to produce PDF acceptable by arxiv?......Page 101
Q: Problems with multi-page output when building nodes directly with node.write()......Page 102
Q: In LuaLaTeX, how do I pass the content of an environment to Lua verbatim **Without displaying it** in a beamer frame?......Page 106
Q: Using LuaLaTeX and SQLite3......Page 109
Q: Find node above and under......Page 112
Q: Why the luatex85 package and the luatex manual does not share the same definitions for \pdf...?......Page 113
Q: In LuaTeX, how can I escape text that will be inserted in LaTeX?......Page 115
Fonts......Page 117
Q: microtype settings for dummies......Page 118
Q: How to keep a "rare" ligature from interfering with a "common" ligature?......Page 121
Q: Why does it take LuaLaTeX so long to load fonts and can I speed it up?......Page 125
Q: Suppress certain ligatures generally......Page 128
Q: FontAwesome font not found?......Page 130
texlive-fontconfig.conf from TeX Live 2015......Page 133
Q: How do I get a list of all font features supported by current font......Page 135
Q: Differences regarding kerning and ligaturing when using the MacTex2013 and MacTeX2014 versions of LuaLaTeX with .ttc fonts......Page 140
Q: How to enable ligatures for emdash/endash in LuaTeX ?......Page 146
Q: Specify different fonts for bold and italic with fontspec......Page 151
Q: How do I get a list of all available fonts for luaotfload?......Page 153
Edit for Texlive 2014......Page 154
Edit for TeXlive 2015 / MiKTeX in july 2015......Page 155
Q: Lualatex: Font table with examples......Page 157
Q: How to properly install and use a new font with LuaLaTeX?......Page 160
Edit......Page 164
Q: Conflict between microtype, LuaLaTeX, and otf fonts when typesetting material in small-caps......Page 165
Q: How to set-up LuaTeX, Microtype, with Minion Pro, Myriad Pro......Page 169
Q: LuaLaTeX: use or don't use classical font packages?......Page 172
Q: TeX accents do not seem to work with fontspec and xe/lua/latex......Page 174
Q: Bembo, Bembo Book or Garamond Premier Pro? And how to exploit all their features with LuaLaTex?......Page 176
Q: Can't generate ligatures with LuaLaTeX under MacTeX2014 and MacTeX2015 when using certain fonts......Page 184
Q: How to use OpenType fonts with plain-LuaTeX?......Page 193
Q: Problem while compiling friggeri CV template with: ' fontspec error: "font-not-found"'......Page 195
Q: How does fontspec select fonts "by name"?......Page 197
Q: Reference about "modern" LaTeX usage for scientific works......Page 198
Q: Selecting optical sizes for all fonts in a family......Page 199
Q: Selecting main math font in LuaTeX?......Page 206
Q: Best practice - how can I get my whole document (including math) to only use font X with LuaLaTeX and fontspec?......Page 207
Q: How to find out which glyphs are different in an OpenType style set?......Page 212
Q: Which fonts can be used with *unicode-math* package?......Page 216
Q: How can you check if fontspec (with LuaLaTeX) can load a font?......Page 217
Q: Prevent LuaLaTeX from splitting umlauts......Page 219
Q: How to generate compounded diacritical fonts for Sanskrit with XeTeX and LuaTeX?......Page 222
Q: How do I combine fonts for different scripts?......Page 232
Q: Why does LuaLaTeX produce smaller files than pdfLaTeX in this example?......Page 234
Q: How is a TeX document written when using LuaLaTeX?......Page 236
Q: In LuaTex is it possible to change font/language according to the script/glyphs used?......Page 238
Q: Switching to lualatex: How to translate font setups?......Page 243
Q: Fake bold in LuaLaTeX......Page 248
Q: Can we stop recommending fontspec as first choice in case lualatex is used?......Page 251
Q: Create a font table for all available characters for a particular font......Page 257
Q: Fixing fonts with LuaTeX feature files......Page 259
A little guide to feature files......Page 261
Q: Accent positioning on 'oe' character with feature file in fontspec......Page 268
Q: Replacing greek glyphs in math mode......Page 270
Q: LuaTeX cannot find existing font......Page 275
Q: Sans-serif to go with EB Garamond (no math)?......Page 276
Q: uneven line spacing......Page 279
Q: How can I replace a character (zero)?......Page 284
Q: How to use fakeslant as slanted but not italic font with fontspec?......Page 287
Q: Embedding Type 1C fonts using LuaLaTeX......Page 289
Q: Reduce compilation time for opentype fonts (otf)......Page 290
Q: Measuring the true height of a character......Page 291
Q: LuaTeX with unicode-math, how to get the font id of current math font......Page 294
Q: Select a font via luaotfload on lua side......Page 297
Q: How to get \copyright when mixing T1 fonts and fontspec?......Page 299
Q: Why is etmainfont case sensitive with XelateX but not with LuaLaTeX?......Page 302
Q: Problem with й (\cyrishrt) in LuaLaTeX......Page 304
Q: Why does LuaTeX not generate some fonts automatically, in contrast with TeX?......Page 305
Q: Can one instruct LuaLaTeX to use T2A encoded fonts?......Page 309
Q: First steps with LuaLaTeX and ttf fonts......Page 313
Q: luatex cannot find font metric data......Page 323
Q: Ligatures in (Graphite) TrueType fonts......Page 325
Q: Using \fontsize in XeLaTeX and LuaLaTeX......Page 328
Q: Double quotes with monospaced font and LuaLaTeX......Page 331
Q: Is using \addfontfeatures (much?) less efficient than defining a \newfontface?......Page 333
Q: Command \texteuro unavailable in encoding T1......Page 335
Q: LuaLaTeX sees a font while fc-list doesn't......Page 338
Q: greek accents with TeX Gyre Termes in lualatex and xelatex......Page 340
Q: luaotfload can't find fonts......Page 344
Q: Problems with luaotfload and certain font shapes......Page 346
Q: How can I enter Unicode bold Fraktur math characters with LuaTeX?......Page 349
Q: Luatex and unicode math without unicode-math......Page 351
Q: Use other font in restricted area won't compile......Page 352
Q: Font package in lualatex gives the cm style figure......Page 355
Q: After MiKTeX update: suddenly all fonts (incl. existing path-referenced ttf files) are not found by fontspec / LuaLaTeX anymore......Page 357
Q: Strange output with LuaTeX's fontloader library......Page 358
Q: Fix ligature mapping of obscure old font with LuaLaTeX or XeLaTeX......Page 363
Q: Remove ligature in a font using luaotfload (TeXLive 2016)......Page 364
Q: Linux Libertine Biolinum xelatex and lualatex......Page 365
Q: System-wide feature file in lualatex......Page 367
Q: Font name in LuaTeX's fontspec......Page 369
Q: Font issue on using lualatex with beamer......Page 372
Q: Loading fonts in LuaTeX (plain TeX)......Page 373
Q: Avoid update font name database by luaotfload......Page 374
Q: When using unicode math, the math glyphs disappear......Page 375
Q: Does lualatex embed fonts for compatibility?......Page 379
Q: Changing numbers font features while changing shape......Page 381
Q: Macro to calculate \baselineskip for given font......Page 383
Q: Using Iwona as a math font with lualatex......Page 385
Q: How to use TeX Gyre Pagella in pdflatex for arXiv......Page 387
Q: LuaLaTeX: Font table with examples of font files (not system or TEXMF installed)......Page 388
Q: Can I downsize lua tables generated by luaotfload?......Page 392
Q: LuaLaTeX: german special character ß with `newpxtext`......Page 397
Q: Can I use Wolfram Mathematica fonts in XeTeX / LuaTeX?......Page 400
Q: How to suppress a "Rare" ligature that pre-empts a "Common" ligature for the same character pair?......Page 401
Q: An example of changing kerning of a font in LuaLaTeX......Page 405
Q: Bad interaction between fontspec and some lua code that performs string-related search and replace operations......Page 407
Q: How can I access a specific glyph in LuaLaTeX/Fontspec?......Page 416
Xetex......Page 420
Q: Lualatex (luaotfload) broke after upgrading to Mavericks......Page 421
Q: LuaLaTeX protrusion problem with Negative value......Page 423
Q: How do I change the font size in LuaLaTeX?......Page 429
Q: Towards a \ucshape and \textuc command for uppercase text (XeTeX, LuaTeX)......Page 432
Q: Lualatex : € as a utf8 character is not recognized : why?......Page 438
Q: Kerning and ligatures in TeX without TeX......Page 442
Q: Getting started with Greek and Hebrew in LuaLaTeX......Page 447
Q: fontspec: what does Renderer=Basic do?......Page 449
Q: Is it possible now to use microtype with opentype fonts?......Page 450
Q: using Hoefler Text font under lualatex and MacOSX......Page 451
Q: fontspec throwing error with lualatex - broken?......Page 454
Q: Replacing Unicode non-breakable spaces by normal spaces......Page 457
Q: Check for missing font characters in LuaLaTeX......Page 459
Q: Contextual Substitution with LuaLateX......Page 461
Q: Why does fontspec change the maths accents (and only with lualatex)?......Page 466
Q: fontspec option "Renderer=Basic" - what does it mean?......Page 468
Q: How to typeset a letter or grapheme specimen with alternates?......Page 472
Q: What is the implication of the warning in the fontspec manual with respect to babel and LuaTeX?......Page 479
Q: A Big fancy "Q"......Page 480
Q: LuaLaTeX: Load order fontspec, microtype (breaks hyphenation in bibliography)......Page 482
Q: LuaLaTeX, fontspec and tracking with microtype......Page 484
Q: Modifying fraction macro for in-line text and exponents......Page 485
MWE to illustrate the problem......Page 490
MWE to demonstrate that this problem is specific to Beamer......Page 491
Non-satisfactory workaround......Page 492
Why I do not consider this workaround a satisfactory solution......Page 494
Q: How to have Helvetica or helvet font with lualatex having similar look as with pdflatex?......Page 496
Q: Strange interaction between fontspec, lua and pgfplots......Page 498
Q: Automatically alter letterspacing (intra-word spacing) to avoid loose lines with LuaLaTeX......Page 501
Q: Math digits are in CM with newtxmath and fontspec (LuaLaTeX, TeX Live 2017)......Page 508
Q: LuaLaTeX: option clash for package graphicx when loaded after fontspec......Page 514
Q: xelatex hangs when using fontspec......Page 516
Q: placement of dot-below accent using LuaLaTeX: significant variations depending on text font......Page 517
Q: Is this a bug with fancyvrb, fancyhdr and fontspec?......Page 521
Q: How can I use the Optima font delivered with my Mac in LuaLaTeX?......Page 525
Q: Arithmetic overflow with fontspec and LuaTeX......Page 527
Q: Where does fontspec store newfontfamily name?......Page 529
Q: french: Add \usepackage{fontspec} to the preamble of your document......Page 530
Q: ettowidth in preamble wrong with fontspec+lualatex w/ MWE......Page 533
Q: How to use otf fonts correctly?......Page 534
Q: Using LuaTeX, HSRM beamer theme, fontspec says DANTE font not found. .sty file has no reference to DANTE......Page 537
Q: Why are Accented Capital Letters not well decoded in QRCODE?......Page 538
Q: Circumflex over Numeral with fontspec......Page 544
Q: Differences between LuaTeX, ConTeXt and XeTeX......Page 545
Q: Drawbacks of XeTeX/LuaTeX......Page 548
Q: The ^^ notation in various engines......Page 551
Q: What have been the most important changes to LaTeX in the last five years? (2011–2016)......Page 559
Q: Are XeTeX and LuaTeX platform dependent?......Page 561
Q: What are lccode and uccode used for?......Page 564
Q: Detect which TeX engine is used......Page 567
Q: Considerations when migrating from XeTeX to LuaTeX?......Page 569
Q: Will LaTeX work on any TeX?......Page 570
Q: Combining \ifxetex and \ifluatex with the logical OR operation......Page 572
Q: PDF file size with LuaLaTeX vs XeLaTeX......Page 576
Q: Analog of \pdfelapsedtime for LuaTeX and XeTeX......Page 577
Q: How to use xindy with XeTeX/LuaTeX?......Page 579
Q: What is the latest progress in the realm of TeX?......Page 583
Q: Choosing TeX engine for novel --- just how unstable is LuaTeX?......Page 585
Q: dealing with thin spaces in XeLaTeX and LuaLaTeX......Page 587
Q: Remapping LaTeX symbol to another unicode value......Page 591
Q: Using XeTeX for automatic transliteration of cyrillic letters......Page 592
Q: Accessing side-bearings in LuaTeX......Page 601
Q: Access specific characters in LuaTeX......Page 606
Q: Do XeTeX and LuaTeX always use Unicode?......Page 608
Q: PDF/X-1a on TeX Live 2014 for publishing with POD lightining source......Page 609
Q: Fix message about outdated xelatex......Page 613
Q: British hyphenation with either xelatex or lualatex......Page 615
Q: XeLaTex and TexMaker "cannot-use-pdftex"......Page 617
Q: Can XeLaTeX | LuaTeX import movies?......Page 619
Q: Expex glosses get broken when unicode-math is loaded in XeLaTeX and LuaLaTeX......Page 620
Q: Place TikZ picture over top of text......Page 622
Q: How are non-unicode glyphs referenced in LuaTeX .dvi files?......Page 625
Q: How to write a LaTeX command that could discriminate if it's being called with pdfLaTeX in order to use PSTricks?......Page 627
Q: How does XeLaTeX and LuaLaTeX extend the dvi format?......Page 630
Q: Defining `commands' or `macros' with unicode names......Page 632
Q: List of all post original TeX control commands......Page 634
Q: LuaLaTeX + libertine... the issue of math font......Page 636
Q: Define MakeUppercase list with XeLaTeX/LuaLaTeX......Page 639
Q: Latex command for unfilled \bigstar......Page 641
PdfTeX......Page 643
Q: Frequently loaded packages: Differences between pdfLaTeX and LuaLaTeX......Page 644
Q: Abandon LaTeX2e for LaTeX3 or LuaTeX......Page 647
Q: Highlight every occurrence of a list of words?......Page 651
Q: pgfplot: plotting a large dataset......Page 661
Q: Compile all tex files within a folder at once......Page 664
Q: How to get accented unicode characters that can be copy-pasted?......Page 665
Q: \ifpdf returns true when using LuaLaTeX......Page 668
Q: hyperref: Wrong DVI mode driver option `dvips',(hyperref) because pdfTeX or LuaTeX is running in PDF mode. \ProcessKeyvalOptions{Hyp}......Page 671
Q: Selectively disable dash ligatures in LuaLaTeX......Page 672
Q: Problems with mixing Icelandic and German with LuaLaTex......Page 675
Q: Using \input|texlua... to emulate \directlua in pdfTeX......Page 683
Q: Hyphenation does not work with acro and luatex, but with pdftex......Page 688
Q: Does the lualatex shell enable behavior differ from pdflatex on purpose?......Page 691
Q: How to increase bufsize for lualatex or pdflatex?......Page 693
Q: char to integer cast in latex......Page 694
Q: warning (pdf backend): pop empty color page stack 0......Page 696
Q: What is the right way to input prime with Unicode-math (LuaTeX backend)......Page 699
Q: LuaTeX: Wrong/missing italic correction in TeXLive 2015 vs 2014......Page 704
Q: clash between mathtools and unicode-math......Page 706
Q: Is direct utf8 input of combining diacritics in math mode possible with lualatex?......Page 709
Q: Spacing changes when using unicode-math range feature. Why?......Page 715
Q: How to use unicode-math with beamer and lualatex?......Page 718
Q: pgfplots + unicode-math + lualatex gives the error "kernel/command-already-defined"......Page 721
Q: Less vertical space in frac......Page 723
Q: Invisible math characters with unicode-math and ntheorem......Page 727
Q: Unicode math with amsmath, new error......Page 728
Q: Arrow length in LuaTeX in combination with the unicode-math package......Page 729
Q: How can I change math font with etmathfont inside a group?......Page 732
Q: How can I avoid that a functions argument touches the brackets using unicode-math?......Page 737
OpenType......Page 738
Q: How can I enable italic correction for LuaTeX?......Page 739
Q: lualatex: smallcaps and microtype don't work together......Page 741
Q: OpenType fonts for Metapost Labels......Page 742
Q: Asymptote with lualatex and otf fonts......Page 744
Q: LuaLaTeX OpenType style sets by 4-character style set code......Page 747
Q: Migrating from pdfTeX to LuaTeX: Problems with reproducing output for legacy projects......Page 751
Q: LuaLaTeX and hyperref ate my document (properties). How do I get them back?......Page 755
Q: Write18: LuaTeX has an encoding problem, where XeLaTeX does not......Page 758
Q: How to write infix macro/newcommand?......Page 759
Q: How to insert a specific unicode character (such as the ZWNJ symbol) into the text stream via lua code compiled by Lua(La)TeX?......Page 760
Q: Any suggestions/requests for features for a new package that allows disabling ligatures for (pre)selected words?......Page 761
Q: How to suppress the operation of a luatex-defined macro on a string if the string is part of macro or a label......Page 767
Q: Ligature suppression algorithm fails if the word in question contains an Umlaut (dieresis) before the ligature......Page 776
Q: How do I customize a LuaLaTeX cmap?......Page 778
Q: LuaTeX does not respect brace groups used for disabling ligatures......Page 782
Errors......Page 784
Q: Tex capacity exceeded compiling only 50 lines latex file (pdftex), seg. fault (lualatex)......Page 785
Q: After MiKTeX update when using LuaLaTeX: Package pgf Error: Driver file ``pgfsys-luatex.def'' not found......Page 796
Q: why lualatex gives erorr "Too many open files" but pdflatex does not on same latex file?......Page 797
Q: MiKTeX's LuaLaTeX and minitoc: "I can't write on file ...mtc"......Page 800
Q: How to place a dot below for example: e?......Page 802
Q: Who's at fault with this error concerning csquotes and LuaLaTeX?......Page 803
Q: How to raise a LaTeX warning from within Lua code?......Page 807
Q: How to get csquotes, polyglossia with german and hyperref work together?......Page 810
Q: Outputfile generated on error......Page 814
Q: l3names error in lualatex (\reserveinserts{32})......Page 815
Microtype......Page 820
Q: How to set expansion and protrusion for TeX Gyre Pagella using LuaLaTeX?......Page 821
Q: hanging punctuation with microtype and luaLaTeX......Page 824
Q: How can I fix a problem where italics prevent line breaking when using microtype?......Page 827
Q: Letterspacing titles with LuaLaTeX......Page 829
Macros......Page 832
Q: Lua function to see if a macro is defined or not......Page 833
Q: Solution to 'Multiple PDF generation with one tex file' does not work anymore with TeXLive 2016......Page 836
Q: How to pass a LaTeX argument verbatim to lua?......Page 839
Q: Matrix multiplication (and other operations) macro using lua module......Page 841
Q: Use lualatex to create macros......Page 850
Q: Use luatex to \let command to other......Page 852
Q: luacode and ExplSyntaxOn/Off......Page 854
Q: LuaTeX: How to handle a Lua function that prints TeX macros......Page 856
Q: Why does the ragged2e package screw up my emphasized text and headings?......Page 858
Q: Check all hyphenations within a document......Page 862
Q: Reviewing hyphenations with LuaTeX......Page 863
Q: Ancient Greek hyphenation in LuaLaTeX......Page 865
Q: Why does hyphsubst not work with LuaTeX?......Page 869
Q: How to avoid a linebreak before a comma in Lua(La)TeX?......Page 875
Q: Latin text not hyphenated at all with LuaLaTeX and polyglossia......Page 877
Q: Does polyglossia with LuaLaTeX hyphenate greek text?......Page 880
Q: How to disable hyphenation in lualatex?......Page 882
Q: LuaTeX cyrillic hyphenation problems......Page 893
Q: Redefining the emdash so as to allow hyphenation......Page 895
Q: Who maintains babel now?......Page 896
Q: How to fix this interaction bug between pgfplots and babel-french module?......Page 897
Q: How to get LuaLaTeX to work with babel's \textgreek?......Page 899
Q: Chinese, Russian and English (and Arabic, and Thai, if possible) in LuaLaTeX......Page 901
Q: Russian in document with Japanese as main language (LuaLaTeX + ltjsarticle)......Page 906
Tikz Pgf......Page 914
Q: \tikzexternalize doesn't work with lua code......Page 915
Q: \pgfmathdeclarefunction and LuaLaTeX......Page 917
Q: Lua code with Tikz......Page 919
Q: Why can I include tikz in a custom latex format with pdftex and not with luatex?......Page 922
Q: Passing options to a macro......Page 925
Q: LuaTeX and graphics......Page 927
Q: Using tikz/pgf and gnuplot with lualatex......Page 928
Q: Symbols for left and right limits......Page 930
Q: lualatex-luatextra math mode issue......Page 931
MiKTeX......Page 934
Q: How do I use LuaTex in MikTeX?......Page 935
Q: Is it possible to pass options to mpost.exe using luamplib?......Page 936
Q: LuaTeX stumbles over special characters in path names, is this a bug?......Page 938
Q: How to run latexmk with LuaTeX on Windows?......Page 939
ConTeXt......Page 940
Q: Concerns on Switching to Plain LuaTeX or ConTeXt Mark IV......Page 942
Q: How to debug METAPOST inlined in ConTeXt? (Or "message" primitive and "loggingall;" in inlined METAPOST)......Page 946
Q: How to put signature number in footer (derived from page number)?......Page 948
Q: Write unit tests for Lua in ConTeXt......Page 951
Q: Replacing matching text with a macro containing information from a CSV file......Page 954
Q: How to make a font book in context/texlua?......Page 957
Q: Difference between setting parindent and hangindent......Page 960
Q: How to display only certain lines of a paragraph?......Page 963
Q: Namespace in luatex......Page 972
Q: How to not have widows and orphans without using raggedbottom......Page 973
Symbols......Page 976
Q: How to pick a specific symbol from a specific font?......Page 977
Q: Printing backslash from a luacode* environment......Page 978
Polyglossia......Page 980
Q: Changing language back and forth with polyglossia......Page 981
Q: Macro definition not working when using LuaLaTeX and polyglossia (with ` etmainlanguage{german}`)......Page 983
Q: How should I have found out that LuaTeX removed \write18?......Page 988
Q: gnuplottex and lualatex......Page 992
Q: Using macros in \DeclareGraphicsRule statement using shell command......Page 995
Q: LuaLaTeX:PGFplots can't read data passed by Lua......Page 997
Q: Is lualatex supposed to be a superset of pdflatex? (regarding production of PDF)......Page 1002
Q: When does a glue node have type `xspaceskip` in LuaTeX?......Page 1006
MetaPost......Page 1010
Q: Why won't this Metapost while loop terminate?......Page 1011
Q: btex and etex in luamplib labels......Page 1016
Q: How to use mplib directly from lua?......Page 1018
Q: Replacement(s) for TeX's paragraph builder using LuaTeX......Page 1020
Q: Why do user-defined whatsit nodes affect LuaTeX pagebreaking?......Page 1021
Answers......Page 1023
Q: Paragraph callback to help with widows/orphans hand tuning......Page 1028
Q: In LuaTeX, what is the ``identity'' linebreak_filter? (Or: how can we use `tex.linebreak` to match the default line-breaking algorithm?)......Page 1039
Q: LuaLaTeX, TeXLive 2016, standalone: undefined control sequence......Page 1042
Q: datetime package does not work with lualatex in TL 2016......Page 1044
Q: Error with tex4ht under TL 2016 when using lua. String contains an invalid utf-8 sequence......Page 1048
Q: lualatex texlive 2016 tcolorbox......Page 1051
Q: Error using pdfpages and lualatex......Page 1058
Beamer......Page 1059
Q: pdfx, beamer and lua(la)tex: is it possible?......Page 1060
Q: LaTeX3 versus pure Lua......Page 1062
Q: How to access the last line of a paragraph with LuaTeX......Page 1070
Q: Can luaLaTeX convert xlsx tables into LaTeX code?......Page 1077
Q: How can one get a list of the available functions in Lua(La)TeX......Page 1078
LaTeX3......Page 1079
Q: Why do I need Lua or LaTeX3 in a plain old technical document?......Page 1080
Q: Will LaTeX3 have proper support for hooks? Does LuaTeX?......Page 1081
Q: hyperref, lualatex and unicode bookmarks issue (garbled page numbers in AR for Linux)......Page 1084
Q: Possible LuaLaTeX Problem (compilation seems to hang)......Page 1086
Q: How does one retrieve \rpcode values in LuaTeX?......Page 1092
Q: Can LuaTeX change the PAGE-breaking algorithm......Page 1094
2. Assumption......Page 1096
Context Mkiv......Page 1097
Q: Escape a string printed from Lua using ConTeXt......Page 1098
Q: How can I list fonts available to LuaTeX in ConTeXt (TeX Live 2013)?......Page 1100
Q: Hiring someone to help me with LaTeX for my PhD thesis......Page 1102
Q: how to get lualatexmk to run in \nonstopmode......Page 1105
Q: How to set the interactive editor in TeXLive? lualatex bug?......Page 1107
Q: How can I dump Lua code to a format file?......Page 1109
Q: LuaTeX 0.85 \pdf* primitive changes and format file generation......Page 1111
Q: Good lua code in .tex doesn't work in .sty?......Page 1117
Windows......Page 1119
Q: Is it possible to run LuaTeX from a USB flash drive......Page 1120
Q: Precompiled header in Lualatex on Windows?......Page 1121
Conditionals......Page 1122
Q: Check if LuaTeX is running......Page 1123
Q: Testing for TeX boolean in Lua code......Page 1124
Graphics......Page 1125
Q: Ploting a function using mplib in lualatex......Page 1126
Q: How to handle verbatim material in LuaLaTeX?......Page 1134
Q: show content of token register as a string in the document......Page 1139
Q: Is there latexmk functionality for LuaTeX?......Page 1143
Q: Specify timezone for \today and \currenttime......Page 1144
Q: Value of LuaTeX's \mathstyle in \frac (de)nominator......Page 1146
Q: write the content of an hbox in an auxilary file......Page 1149
Q: How to get box dimensions within lualatex......Page 1151
TeX4ht......Page 1153
Q: text4ht and LuaTeX......Page 1154
Q: tex4ht corrupts "--" inside CDATA in the HTML file......Page 1156
Q: What happened to \luatextextdir?......Page 1163
Q: Typesetting arabic with LuaLaTeX......Page 1164
Q: Is there a limit to the size of a tex-file?......Page 1166
Tcolorbox......Page 1168
Q: Possible Lualatex problem with documentation library from tcolorbox......Page 1169
Q: TeX Live 2016: minted doesn't work with LuaLaTeX (bug fixed in June 2016)......Page 1170
Q: How to use luatex callbacks to generate a verbatim copy of the input file......Page 1177
Q: Footnote numbers in index (e.g., 23n3)......Page 1181
Q: Convert color name to pdfliteral code......Page 1186
Listings......Page 1187
Q: error with LuaLaTeX, lstinputlisting and an extension-less file......Page 1188
Q: Installing Lua Modules for use in LuaLaTeX - the sequel......Page 1189
Q: Updating to Beta Builds of ConTeXt / LuaTeX from tlcontrib breaks MacTeX......Page 1191
Q: Which is the best editor for LuaTeX?......Page 1196
Biblatex......Page 1200
Q: Engines of Tex-Editors and Biber/Biblatex......Page 1203
Q: \lastnodetype not working as expected in luaTeX......Page 1205
Q: Parsing files through LuaTeX......Page 1211
Catcodes......Page 1214
Q: cantokens in LuaTeX......Page 1215
Q: Automatically fixing catcode output......Page 1216
Q: Convert numbered pinyin to pinyin with tone marks......Page 1220
Terminal Output......Page 1227
Q: Accessing to .log messages from LuaTeX. Is it possible?......Page 1228
Q: ^^M garbles my terminal output......Page 1231
Letterspacing......Page 1233
Q: How to letter space (German) abbreviations automatically......Page 1234
Q: LuaTeX hpack_filter callback not triggering on certain hlist creations......Page 1246
Q: How to use LuaTeX `append_to_vlist_filter` callback......Page 1247
Texdoc......Page 1249
Q: Why does texdoc call luatex......Page 1250
Header Footer......Page 1252
Q: How can I achieve dictionary headers for two page spreads in LaTeX......Page 1253
Q: LaTexing vs LaTexTools (Sublime text plugins)......Page 1259
Q: Lualatex and a5 paper format......Page 1262
Q: Compound representation of numbers. Possible?......Page 1263
Scripts......Page 1269
Q: What are the advantages of Lua over other scripting languages for a TeX implementation?......Page 1270
Q: LuaLaTeX: Calculate length in Lua......Page 1273
AUCTeX......Page 1275
Q: AUCTeX changes name of pdf file when compiling with LuaTeX......Page 1276
Q: Extract data from excel file with lualatex......Page 1277
Q: Obtain a TikZ tree from a Lua table/string......Page 1280
Q: LuaLaTeX and \pdfminorversion......Page 1284
Q: How do you configure Texmaker to use LuaTeX?......Page 1286
Q: pdfcrop using luatex engine minimal setup......Page 1288
Typein......Page 1291
Q: incompatibilities between LuaLaTeX and \typein ?......Page 1292
Q: Lua reimplementations of PGF math?......Page 1293
Forward Inverse Search......Page 1295
Q: When is Synctex file written?......Page 1296
Q: How to use ocg-p with LuaLaTeX (TeXlive 2015)?......Page 1299
Q: Getting lilyglyphs working in LuaTeX......Page 1303
Q: etextools throws error when run with LuaLaTex......Page 1306
Q: LuaTeX analogue of \ifcsname for active characters......Page 1308
Q: How can I use cbgreek with lualatex?......Page 1311
Copyright......Page 1312

Citation preview

LuaTeX: Questions and Answers George Duckett

Table of Contents About this book LuaTeX (43 questions) Fonts (91 questions) Fontspec (86 questions) XeTeX (63 questions) PdfTeX (30 questions) Unicode Math (25 questions) OpenType (16 questions) Unicode (16 questions) Ligatures (16 questions) Errors (15 questions) Microtype (15 questions) Macros (13 questions) Hyphenation (13 questions) Babel (12 questions) Tikz Pgf (12 questions) Math Mode (11 questions) MiKTeX (10 questions) ConTeXt (9 questions) Tex Core (8 questions) Symbols (8 questions) Polyglossia (8 questions) Shell Escape (8 questions) Pgfplots (7 questions) Spacing (6 questions) 1

MetaPost (6 questions) Paragraphs (6 questions) Texlive 2016 (6 questions) Beamer (5 questions) Programming (5 questions) LaTeX3 (5 questions) Hyperref (5 questions) Protrusion (5 questions) Page Breaking (5 questions) Context Mkiv (5 questions) Compiling (4 questions) Format Files (4 questions) Packages (4 questions) Windows (4 questions) Conditionals (4 questions) Graphics (3 questions) Verbatim (3 questions) Latexmk (3 questions) Boxes (3 questions) TeX4ht (3 questions) Arabic (3 questions) File Size (3 questions) Tcolorbox (3 questions) Bugs (3 questions) Input (2 questions) Indexing (2 questions) Color (2 questions) Listings (2 questions) Installing (2 questions) Editors (2 questions) Biblatex (2 questions) E TeX (2 questions) External Files (2 questions) Catcodes (2 questions) Cjk (2 questions) Terminal Output (2 questions) Letterspacing (2 questions) Callback (2 questions) 2

Texdoc (1 question) Header Footer (1 question) IDE (1 question) Paper Size (1 question) Numbering (1 question) Scripts (1 question) Lengths (1 question) AUCTeX (1 question) Database (1 question) Trees (1 question) PDF (1 question) TexMaker (1 question) Pdfcrop (1 question) Typein (1 question) Pgfmath (1 question) Forward Inverse Search (1 question) OCG (1 question) LilyPond (1 question) Etextools (1 question) Active Characters (1 question) Cbgreek (1 question) Copyright

About this book This book has been divided into categories where each question belongs to one or more categories. The categories are listed based on how many questions they have; the question appears in the most popular category. Everything is linked internally, so when browsing a category you can easily flip through the questions contained within it. Where possible links within questions and answers link to appropriate places within in the book. If a link doesn’t link to within the book, then it gets a special icon, like this.

3

LuaTeX Skip to questions, Wiki by user joseph-wright LuaTeX is an extension of TeX which integrates Lua (a scripting language) into TeX. LuaTeX is an extension of pdfTeX, which means that both DVI and PDF output are possible. LuaTeX makes it possible to access the internals of the TeX process ’as they happen’, allowing effects that are difficult to achieve otherwise. It is also Unicode-capable and can use OpenType and TrueType fonts. Use this tag if your question is about LuaTeX or LuaLaTeX specific problems and is not related to general (La)TeX issues. ConTeXt Mark IV uses LuaTeX as its engine: if the question is about ConTeXt and LuaTeX, use contextmkiv instead.

Questions Q: Which Lua environment should I use with LuaTeX (LuaLaTeX)? Tags: luatex (Next Q) Lua code environment I moved on to XeTeX (XeLaTeX) a while ago. I was using pdfLaTeX before that, but now I’m quite comfortable with XeLaTeX. Now, I’d like to use LuaLaTeX to embed Lua in some LaTeX documents. The doc states several ways to embed Lua in TeX, but they confuse me more than actually explain what I need to know about embedding Lua. There’s \directlua{ ... }, \luacode ... \endluacode, and \begin{luacode} ... \end{luacode} with the luacode package. The dots (...) is where Lua code would go. Now, which one should I use? 4

And is there a quicker way to enter Lua environment like with math mode where I can enter mathmode with ’$’? Saving variables A quick one: When using Lua code embedded in LuaLaTeX, all variables are lost when the code finishes. Now, can I save return values, etc. so I can use them in my document later, with \myvar for sinstance, or something? Tags: luatex (Next Q) User: polemon

Answer by topskip There are two questions here. You should consider asking one question at a time for your next posts. Now to the Lua code environment. Don’t use any of them if you can. Just do \directlua{

require("myfile")

}

and put all of your Lua code in that file. See another answer for a list of directories TeX searches for the file myfile.lua. If for some reason you can’t do that (when you are only allowed to ship only one file for example) you should use the environment luacode* (with *) from the luacode package. That has the safest character catcodes. That means you can say something like: \begin{luacode*} texio.write_nl("This is a string with\n a newline in it") tex.print(-2, string.format( "5 %% 4 is %d ", 5 % 4)) \end{luacode*} (You need the -2 as the first argument to tex.sprint(), because the % sign (resulting from the double %% is interpreted from TeX as a comment sign after the environment closes. TeX sees at the end of the environment 5 % 4 is 1 and treats the % as the end of input. So you need to tell TeX that this % is a regular character. You have two choices: either pass TeX a string like this: 5

string.format("5 \\%% 4 is ...") so that TeX sees 5 \% 4 is ... as you would do with normal text or make % a normal letter, so TeX does not recognize it as a comment sign. To do that you have to change the category code. The easiest way is to assign the special catcode table -2 to tex.print(). It is a safe catcode table, no characters have a special meaning.) If you need to use TeX macros in Lua code, use the luacode environment (without *): \begin{luacode} local current_page = tonumber(\thepage) texio.write_nl("We are on page " .. current_page) \end{luacode} And if you need to put your code in a command, use \luaexec: \newcommand\myrepeat[2]{% \luaexec{ for i=1,#1 do tex.sprint("\luatexluaescapestring{#2}") end }} \myrepeat{4}{Hello world} (you can’t use the environments directly in a \newcommand, but you could use \luacodestar ... \endluacodestar if you really want the environment functionality). The \luatexluaescapestring{} is necessary to escape input characters like " that would be harmful to the Lua string. You have also asked if there is a shortcut such as the $...$ for math typesetting. No, there is none. IMO that is not such a big problem, as Lua code (in practice, but YMMV) is only used at a few points (with macros or with environments for example) and not so much in running text. Mostly in packages. (See the documentation to the luacolor package for example. Even if you don’t understand the package in full detail at the first glance, you can see where the TeX code is with the \directlua calls, aliased in the example to \[email protected] and how the Lua code is separated from it in another file. See that there are only very few lines of Lua code inside the \[email protected] commands? In my opinion we can learn a lot from this code, as Heiko Oberdiek is an excellent package writer.) 6

Now to your second question about Saving variables. If you don’t declare your variables local, they are accessible in all Lua chunks. But you are asking to pass Lua code to TeX. You can do this for example: \begin{luacode*} tex.sprint("\setcounter{mycounter}{" .. my_lua_value .. "}") \end{luacode*} to create a \setcounter command with your value. Or you can use the tex.count Lua interface: \begin{luacode*} tex.count[10] = my_lua_value \end{luacode*} and your value is in \count10. But this is a bit dangerous as you have to be certain to use a free counter.

Tags: luatex (Next Q)

Q: Why should I be interested in Lua? Tags: luatex (Prev Q) (Next Q) I have been using LuaLaTex since I got acquainted with TeX, because it can easily work with system fonts, which I really need. Font packages in TeX are not friends of the Russian language, though they are friends of the Lua language. I have found some examples here: What is a simple example of something you can do with LuaTeX?, but I still do not fully understand what can Lua do. So, my questions are the following: • Was Lua specially designed for TeX, or it is just a programming language that can be implemented in TeX? Answer: It is just a programming language, not specific to TeX. 7

• How can it be used in typesetting? Can it somehow substitute any packages? • Is it OS dependent, i. e. is there anything specific while using it on Windows? • Can it work with non-latin characters? Answer: YES. Tags: luatex (Prev Q) (Next Q) User: michael-fraiman

Answer by mico You asked, inter alia: What for can [Lua] be used in typesetting? Can it somehow substitute any packages? • Some typesetting tasks can be achieved only in LuaTeX, but not pdfTeX or XeTeX. We’re starting to see more and more packages that require LuaLaTeX to accomplish their objectives; these packages simply couldn’t have been written at all in pdfLaTeX or XeLaTeX. Examples are the showhyphens and selnolig packages. (Full disclosure: I’m the main author of the selnolig package.) • Some typesetting tasks can be accomplished more easily (or, at least, with no more work) in LuaLaTeX than in either pdfLaTeX or XeLaTeX. Compare, for instance, the following two code chunks (from the posting Arithmetic temporaries in tex). In both cases, the macro \StrMid serves to extract a substring from a string:

\usepackage{luacode} % for "\luastring" macro \newcommand\StrMid[3]{\directlua{tex.sprint(string.sub(\luastring{#1},#2,#3)) versus \usepackage{xparse} \ExplSyntaxOn \NewExpandableDocumentCommand{\StrMid}{mmm} { \tl_map_function:fN { \tl_range:onn { #1 } { #2 } { #3 } } \use:n } 8

\cs_generate_variant:Nn \tl_map_function:nN { f } \cs_generate_variant:Nn \tl_range:nnn { o } \ExplSyntaxOff By contrasting these two chunks of code, I certainly do not mean to slight the author of the LaTeX3 code. Not at all! All I mean to do is to show that some tasks can be rather easy to accomplish if one knows even just a little bit of Lua. This is especially true when it comes to manipulating strings, as Lua provides quite a few powerful string-handling functions. • If you’re used to working with a modern programming language but haven’t ever fully mastered all the fine points of a macro expansion language -- I myself must plead guilty to just this charge... -- you’ll probably find it much easier to program some non-trivial typesetting tasks by using Lua code and the clear interface between Lua and TeX that’s built into LuaTeX.

Answer by david-carlisle Lua is a programming language designed to run in a small easily embedded virtual machine (much smaller than the Java JVM for example) and so ideal for embedding in other systems (it is used as the configuration language for several games for example). So it is not developed by the luatex people (in fact Lua itself is currently at at least at version 5.3, ahead of the Lua 5.2 version shipped with luatex) but chosen as a suitable extension language. It can be used to re-implement several of the built in TeX algorithms It’s more or less OS independent Yes as you see in Luatex it can handle Unicode fonts and Unicode strings (Unicode strings are exposed as UTF-8 encoding so a single unit is a byte rather than a character)

Answer by caleb-reister

9

As an example of what can be done with LuaLaTeX, I created a script that automatically converts CSV data into the LaTeX tabular or matrix format. It is quite useful for lab reports since the user no longer has to worry about manually updating data or simulation results in the TeX file. https://gist.github.com/calebreister/8dd7ab503c91dea4dd2c499b9d004231

Tags: luatex (Prev Q) (Next Q)

Q: LuaJIT and LuaTeX Tags: luatex (Prev Q) (Next Q) Is it possible to change the Lua engine in LuaTeX to LuaJIT? Will it be as simple as replacing the Lua5.1 source code in the LuaTeX tarball with the LuaJIT source, or does it require (drastic) changes to the build system, or is it entirely not possible? Tags: luatex (Prev Q) (Next Q) User: jonathan-yip

Answer by taco-hoekwater I did an attempt a while ago with LuaJIT 1, and it did not seem to be that hard. A few small build tweaks would be needed, but nothing major. The main reason why there is no LuaJIT in LuaTeX currently is that we have a few patches to Lua now that are not in LuaJIT (and are hard to add) like an extended coroutine subsystem. In lua5.2, our patches to the Lua core will become obsolete, so once we switch to that Lua version, LuaJIT becomes interesting again and I will certainly try to have LuaJIT support by default on the supported platforms. That should be before LuaTeX 1.0, but not in next few months.

10

But, don’t expect much of it. Even in ConTeXt, most Lua processing is iterating over C data structures using our embedded Lua support libraries. JITting the little bit of Lua code that wraps that together will not help a lot, a few percent at best is my current guess (which is also why incorporating LuaJIT is low priority)

Answer by marco Since 2012-12-25 LuaJitTeX is available. It is LuaTeX with LuaJit based on Lua 5.1. Two modes are available by default: • jit turned off, the default mode (only use the faster virtual machine) • jit turned on (in most cases not faster, even slower) In ConTeXt standalone LuaJitTeX is included by default, which means using MkIV with LuaJitTeX is as easy as providing the --jit argument: context --jit somefile.tex context --jiton somefile.tex

# or

For plainTeX simply use luajittex as compiler: luajittex --fmt=luajittex-plain.fmt somefile.tex luajittex --jiton --fmt=luajittex-plain.fmt somefile.tex

# or

Building the format for plainJitTeX is no different than building the format for LuaTeX. Just to provide an impression of the speed difference I did a quick nonscientific test on a simple document. Here are the results for a ConTeXt document with the three possible options: Engine -----LuaTeX LuaJitTeX (jit turned off) LuaJitTeX (jit turned on)

Compile time -----------3.6s 2.9s 3.0s

Edit: There seems to be some confusion about how to obtain LuajitTeX. The project is hosted on foundry.supelec.fr - LuajitTeX. Recently they restruc11

tured their servers and relocated their content. Unfortunately the URLs changed and the old ones are not valid any longer. The sources can be obtained with SVN using svn checkout --username anonsvn https://foundry.supelec.fr/svn/luajittex/trunk The binaries can be found on the ConTeXt garden.

Tags: luatex (Prev Q) (Next Q)

Q: ”Lua tree” (analogue of texmf tree) Tags: luatex (Prev Q) (Next Q) I have a lua file that I would use in many of my TeX’s documents, loading it with dofile(). I thought it was ok if I simply put it in the (local) texmf tree*, but this doesn’t work. Instead I have the following error message : LuaTeX error cannot open the mycode.lua: No such file or directory Is there any nice solution ? • I try to save the file in ~/Library/texmf, in ~/Library/texmf/tex, ~/Library/texmf/tex/latex and even in ~/Library/texmf/lua (I had to create the directory). Tags: luatex (Prev Q) (Next Q) User: matsaya

Answer by khaled-hosny dofile() expects full path (or path relative to current directory). You have to either use require() which will search TEXMF tree, or use kpse.find_file() and pass the returned path to dofile(). kpsewhich -show-path=lua should show the search path for lua files. 12

Answer by topskip require() searches (TeXlive2011, LuaLaTeX) in these texmf subdirectories: Skip code block scripts/lualatex/lua/ scripts/luatex/lua scripts/lua scripts/lualatex scripts/luatex scripts tex/lualatex tex/latex tex/luatex tex/generic tex

Answer by ulrike-fischer require() should normally use kpse. E.g. require("fontspec.lua") finds fontspec.lua in tex\latex\fontspec.

Tags: luatex (Prev Q) (Next Q)

Q: How to read a file with luatex Tags: luatex (Prev Q) (Next Q) I tried to read a file with lua and set the content as normal text in my document, but I didn’t worked it out. Here my code: Skip code block \documentclass{scrartcl} 13

\usepackage{luatextra} \usepackage{filecontents} \begin{filecontents}{testdata.dat} A B 1.0 20 1.1 21 1.2 22 \end{filecontents} \begin{luacode} function readtxt() file = io.open("testdata.dat", "r") text = file:read("*all") print(text) return tex.print(text) end \end{luacode} \begin{document} \directlua{readtxt()} \end{document} But nothing is printed to the document although lua diplays the content of the file in the terminal. Tags: luatex (Prev Q) (Next Q) User: reza

Answer by paul-gaborit Edit: a short version of readtxt() function. \begin{luacode*} function readtxt() file = io.open("testdata.dat", "r") tex.print(string.split(file:read("*a"),"\n")) end 14

\end{luacode*} First proposition: a solution consists to store lines in a table and to ”tex.print” the lines one by one (each argument of tex.print is a single line of TeX). Skip code block \documentclass{scrartcl} \usepackage{luatextra} \usepackage{filecontents} \begin{filecontents}{testdata.dat} A B 1.0 20 1.1 21 1.2 22 \end{filecontents} \begin{luacode} function readtxt() file = io.open("testdata.dat", "r") for line in file:lines() do print(line) tex.print(line) end end \end{luacode} \begin{document} \directlua{readtxt()} \end{document}

Answer by loop-space The file being written by filecontents looks like this: %% LaTeX2e file `testdata.dat' %% generated by the `filecontents' environment 15

%% from source `luareadfile' on 2013/02/12. %% A B 1.0 20 1.1 21 1.2 22 When lua reads that in to the string, it does no processing. If TeX were to read that in, it would ignore the comment lines since everything from a % to a newline gets eaten up. Moreover, TeX would translate the newlines to space characters (and translate any double newlines to \par tokens). The file then gets inserted into the TeX stream via tex.print. This, it would appear, is inserted as if the input parser has already done its job. So TeX assumes that double newlines have already been replaced by \pars and treats a newline character as simply a space token. However, it still sees the % character and is prepared to deal with it by ignoring anything after it up to a newline. But there are no newlines, so TeX keeps discarding stuff until it is stopped (at the end of the tex.print). I don’t know if it is possible to fix this ”properly” by getting the new lines to be interpreted correctly, but if you have control over the file contents (as you appear to here) you could get lua to strip out the comments first using a simple pattern match before presenting the data to TeX. Skip code block \documentclass{scrartcl} %\url{http://tex.stackexchange.com/q/97822/86} \usepackage{luatextra} \usepackage{filecontents} \begin{filecontents}{testdata.dat} A B 1.0 20 1.1 21 1.2 22 \end{filecontents} \begin{luacode} 16

function readtxt() file = io.open("testdata.dat", "r") text = file:read("*all") clean = string.gsub(text,'%%[^\string\n]*',"") print(clean) return tex.print(clean) end \end{luacode} \begin{document} Reading in text: \directlua{readtxt()} Finished reading in text. \end{document} Notice the \string! That’s because your lua code is embedded in your document. It’s usually a good idea to avoid that by having the lua code in a separate file. This produces: Reading in text: A B 1.0 20 1.1 21 1.2 22 Finished reading in text.

Answer by topskip Another (besides @AndrewStacey’s solution) string.gmatch() and insert the file line by line: Skip code block \documentclass{scrartcl} \usepackage{luatextra} \usepackage{filecontents} \begin{filecontents}{testdata.dat} A B 1.0 20 1.1 21 1.2 22 \end{filecontents} 17

possibility

is

to

use

\begin{luacode*} function readtxt() file = io.open("testdata.dat", "r") text = file:read("*all") file:close() for x in string.gmatch(text,"[^\n]+") do tex.print(x) end end \end{luacode*} \begin{document} \directlua{readtxt()} \end{document} And if you want to insert your file verbatim, you can use the -2 catcode table: tex.print(-2,text) Which tells TeX not to interpret the contents of the string.

Tags: luatex (Prev Q) (Next Q)

Q: Can the Lua part of LuaTeX know about tokens? Tags: luatex (Prev Q) (Next Q) Using \directlua and tex.print, it is possible to send strings of characters back and forth between TeX and Lua. Let’s take an example: starting with a macro \A, I pass its replacement text to Lua and back, defining \B Skip code block \edef\A{ab\string c} \directlua{tex.print("\noexpand\\def\noexpand\\B{\unexpanded\expandafter{\A}}")} \show\A 18

\show\B \ifx\A\B \message{Identical :)!} \else \message{Different :(.} \fi \bye The two macros appear identical, but they aren’t: the weird/special combination of category codes (letter and other) is lost before reaching Lua, and tokenization on the return trip is done using the category code régime in effect when \directlua is performed. Can the \directlua line be replaced by some other Lua code which would be able to define \B to be identical to \A, including category codes? Of course, \directlua{\unexpanded{tex.print("\\edef\\B{\\unexpanded\\expandafter{\\A}}")}} would work (by delaying the expansion of \A until after the passage through LuaTeX), but my goal would be to perform some complicated operations on the token lists on the Lua side. Tags: luatex (Prev Q) (Next Q) User: bruno-le-floch

Answer by topskip You can play with tex.print() and catcode tables. The result of tex.tprint({"\\def\\B{ab"},{-2,"c"},{"}"}) gives ”Identical :)”. This is, because -2 is a predefined catcode table where all characters have the catcode ”other” (12) except for space (10) assigned. So you get the same as your edef in TeX.

Answer by bruno-le-floch Using the token_filter callback and the token library (as Patrick kindly mentionned to me in comments to his answer) allows to build arbitrary token

19

lists and insert them in the input stream. The callback should only be called once, it disables itself with callback.register(..., nil). Skip code block \expandafter\def\expandafter\B\expandafter{% \directlua { callback.register ( 'token_filter', function() callback.register ('token_filter', nil) return { token.create(\number`\a, 11), token.create(\number`\b, 11), token.create(\number`\c, 12) } end ) }% } \show\B \def\test#1#2#3{\show#1\show#2\show#3} \expandafter\test\B This answer only covers the Lua to TeX part. It should be possible to use token.expand() to do the TeX to Lua step, but I don’t know how.

Tags: luatex (Prev Q) (Next Q)

Q: \documentclass: undefined control sequence Tags: luatex (Prev Q) (Next Q)

20

There’s probably a ton of questions about this already but I’ve been spending all day feeling overwhelmed with the TeX learning curve. I’m trying to learn LuaTeX (by the way, if you know of a good tutorial I’d love to know about it). I have downloaded TeX Live 2011 for Windows yesterday. I have a LaTeX document with working syntax which renders properly. When I switch the typeset setting to ConTeXt (LuaTeX), I get Undefined control sequence for the first line, \documentclass{report}. What am I doing wrong? Tags: luatex (Prev Q) (Next Q) User: glifchits

Answer by yan-zhou I hope this answer can clarify a few basic concepts for you. TeX TeX is a (macro) programming language invented by Knuth. It is a Turing complete language. That is, theoretically you can do almost anything you can do with other languages, though not necessarily easily. TeX Engine A program that can interpret the TeX language. It is like the perl program for the Perl language. The first TeX engine was written by Knuth. Nowadays, popular engines include pdftex, xetex, luatex. pdftex is much faster than the other two though the other two provide extra functionality, especially for using opentype fonts. luatex provides much more than fonts. LaTeX and ConTeXt These are formats. A format is just a set of TeX macros (well, not exactly so simple). They define a lot of macros for you to use. For example, LaTeX defines the \documentclass and \begin{document} macros while ConTeXt defines \starttext. It will take a much longer paragraph to answer what there really is in a format. For now, you may just think the program lualatex is a shortcut for starting the luatex engine, inputting the LaTeX macro packages (i.e., the format), and then processing your input. (I know this is not the exact explanation, but I believe it helps a beginner to understand). LuaLaTeX, XeLaTeX, pdfLaTeX, ... these are all just shortcuts for using the LaTeX format with a TeX engine. 21

In the question, you seems to think ConTeXt and LuaTeX are the same. This is not true. ConTeXt Mark IV requires LuaTeX as an engine to process this format. Just like many LaTeX packages and the forthcoming LaTeX3 format requires an engine with e-TeX features. Please correct me if there’s anything wrong with this answer.

Answer by �aphink Most likely, you typed luatex to compile a LaTeX document. The proper command to use to compile LateX code with LuaTeX is lualatex.

Tags: luatex (Prev Q) (Next Q)

Q: How to access LaTeX lengths in LuaTex? Tags: luatex (Prev Q) (Next Q) I know I can access raw TeX dimens with Lua using tex.dimen[key], but how do I access a LaTeX length in Lua? MWE: Skip code block \documentclass{article} % This is TeX \newdimen\boxwidth \boxwidth=3.4ex % end of TeX \newlength{\boxwidthlatex} \setlength{\boxwidthlatex}{5.8ex} \begin{document} 22

\directlua{tex.print(tex.dimen['boxwidth'])} % How to do something like this? % \directlua{tex.print(tex.dimen['boxwidthlatex'])} \end{document} Tags: luatex (Prev Q) (Next Q) User: nathanael-farley

Answer by ulrike-fischer LaTeX lengths are skips, and skips are not a simple object but a table. So you need to do something like this: Skip code block \documentclass{article} % This is TeX \newdimen\boxwidth \boxwidth=3.4ex % end of TeX \newlength{\boxwidthlatex} \setlength{\boxwidthlatex}{5.8ex} \begin{document} \directlua{tex.print(tex.dimen['boxwidth'])} \directlua{tex.print(tex.skip['boxwidthlatex'].width)} \directlua{tex.print(tex.skip['boxwidthlatex'].stretch)} \end{document}

Tags: luatex (Prev Q) (Next Q)

23

Q: Would you consider Luatex to be ready for a production environment Tags: luatex (Prev Q) (Next Q) I’m setting up a number of document with dynamic texts. Basically LaTeX is view mechanism to dynamically present the results of ongoing statistical analysis on a database. So I have numerous \ifnums and \newifs that are fed by Sweave with the values calculated in the R chunks of and Rnw file. And although the LaTeX if else constructs work, the LuaTex examples posted here on tex.se look so much more elegant and easier to debug that I would much prefer to go that route. Especially when I have multiple nesting I sometimes struggle to pinpoint why errors occur. I certainly do ask about advantages and disadvantages of LuaTeX and LuaLaTex itself. There are some excellent posts here discussing that already. What I do need is some arguments to propose the switch to LuaTex for some or all reports to my team. The immediate response is ”LuaTex is still in beta, and will be for a while”. However the authors suggest that it is stable enough: major releases (x.x0 versions) are stable enough to be used for production work Can you validate this with experience? Are there risks other than the possibility of having to refactor when a new version of LuaTex/LuaLaTex comes out? The documents I’m working on are relatively simple from a type setting perspective, and I’m only using standard document classes. Also, once prepared the templates are not likely to change much. I realize that there are some things I take entirely for granted with pdflatex, and my question could narrow down to whether this already applies (in your experience) to lualatex: • Starting many pdflatex processes concurrently has never lead to any trouble. • Once an a (Rnw --> Sweave --> tex) template works (has been tested, debugged and brought into production) I have never had too look at it again (except for some updates in R packages but that is definitely off topic here). 24

topskip already gives me one pointer: learn the limitations of the current beta, work around it if necessary and be careful when updating. I interpret this as follows: looking at cost vs benefits it will be easier to program now and possibly (but most likely not) more costly to maintain later. Do you have more experiences you could share along that train of thought? UPDATE - moved my notes on making the switch from pdflatex to lualatex to an answer below. It was getting too long to remain in the question Tags: luatex (Prev Q) (Next Q) User: fvd

Answer by martin-schröder Yes. I have two projects with customers where we switched from XeTeX to LuaTeX (because of problems with image inclusion which are now fixed in XeTeX) and which now run for more than a year without problems (still using TL2012). Of course you need to consider how to get professional support if your business depends on LuaTeX. It’s definitely production ready; I switched from pdfTeX to luaTeX for personal use years ago. But then I can fix bugs in LuaTeX myself if need be. :-)

Answer by topskip I make my living for a few years using LuaTeX, so I do consider LuaTeX to be ready for a production environment. This doesn’t mean its bug free or you can use it without any thoughts. I am still using a rather old version of LuaTeX and I never change my environment, so I have a very stable setting. (At least) one annoying bug is in my current binary (0.71.0) and I have a bit of trouble working around it, but it’s ok. If you update regularly, you might be in trouble. LuaTeX changes, Lua changes and the userland changes even more. If you have documents that

25

don’t rely on the most secret features of any of those, you have good chances that you won’t notice any differences throughout the years. So the answer is ”it depends on your very personal needs” and thus I consider this question off-topic ;)

Answer by fvd Yes, it seems perfectly ready for production but it comes at a steep performance cost. After working with LuaLatex in a test environment for a while, there is much to like, and I have yet to encounter a bug, so I finally choose for Martin’s resounding yes. However, I would like to qualify some aspects of my personal needs. It may help if you are deciding about including LuaLaTex in your work flow. 1. Migration Migrating to LuaTex is a easy and well documented and requires only minor changes for documents with a layout as (relatively) simple as mine. It takes little time to become productive in Lua, and once you have figured out how the different Lua environments you are pretty much set. This means that rewriting documents is pretty fast. The very few peculiarities of tex.print are all well documented so it does not take long to figure it out. Another one of those peculiarities is the way you can to pass R values with Sweave to a Luacode environment. It turns out that it is perfectly possible to evaluate \Sexpr{} inside a lua environment. The trick is to make sure that you use luacode and that you use the tostring and tonumber functions in lua. \begin{luacode} local mystring = tostring(\Sexpr{df[3,c("TextColumn")]}) local myinteger = tonumber(\Sexpr{df[3,c("NumberColumn")]}) end \end{luacode} Expressions like tostring and tonumber are among the few things that require an effort to find in de documentation. The rest is pretty standard 26

syntax. Because migration involves the removal of the inputenc package Sweave needs to be called with the utf8 encoding option, otherwise it will not recognize the encoding: R CMD Sweave --encoding='utf8' testluatex.Rnw 2. Performance This is where the costs really lie. My test document with a number of nested if-then blocks takes 0.28 seconds to convert to pdf with pdflatex and a full 1.45 seconds with lualatex. Changing the fonts back to using the pdffonts (uarial instead of Arial through fontspec) speeds it up a little bit (1.32 seconds) but not much. That performance is still behind LuaTex’s cousins is also well documented. I just did not know how much performance loss could be expected. 3. Coding and Maintainability It is really a breath of fresh air to work in luacode instead of tex when you are working on reports with dynamic content. And it is definitely much easier and faster to read and debug in comparison to tex. Performance happens to weigh heavily in our decision, and unfortunately the coding benefits do not yet outweigh the cost to performance. But performance may not be relevant to you, and in that case there is the benefits are substantial.

Tags: luatex (Prev Q) (Next Q)

Q: \show for Lua commands Tags: luatex (Prev Q) (Next Q) TeX (and all newer engines) has the primitive \show which helps me probe macros, and most of the time is enough to understand/remember the implementation (rather than having to go back to the source code). 27

Is there something similar for Lua commands? For instance, Heiko Oberdiek has written replacements for some pdfTeX primitives in LuaTeX, and I’d like to get more information about them using some hypothetical \showluatexcmd macro. \input pdftexcmds.sty \catcode`@=11 \show\[email protected] %\showluatexcmd{oberdiek.pdftexcmds.strcmp} \bye Tags: luatex (Prev Q) (Next Q) User: bruno-le-floch

Answer by topskip I seriously doubt that there is something similar for Lua, but you can do the following to find out where the function is defined (to get to the source code). \directlua{ require("showluatexcmd") } \def\showluatexcmd#1{\directlua{showluatexcmd.show(#1)}} \input pdftexcmds.sty \catcode`@=11 \show\[email protected] \showluatexcmd{oberdiek.pdftexcmds.strcmp} \bye and the file showluatexcmd.lua: module(...,package.seeall) function show( fun ) local debuginfo = { "source","linedefined","what" } for _,v in ipairs(debuginfo) do texio.write_nl(string.format("%20s=%q", v, debug.getinfo(fun)[v])) end end

28

One could extend this probably to directly load the function and display it. But in most cases this won’t help as there are a lot of functions that are short and call other functions. A sample output is source="@/opt/texlive2011/texmf-dist/scripts/oberdiek/pdftexcmds.lua" linedefined="46" what="Lua" )

Tags: luatex (Prev Q) (Next Q)

Q: luatex and starting TeX macros which handle new line characters Tags: luatex (Prev Q) (Next Q) This here is actually some kind of isolated follow-up question to Workaround for open lualatex bug in \scantokens? . I tried to use tex.print("{}") and expected it to work as if I would have typed the content of tex.print in TeX directly. More precisely, I tried to write \pgfplotstabletypeset{A B 2 3 4 5 } inside of tex.print. The entire motivation is in the linked question. No matter what I tried, I could not get the same treatment of the (mandatory) newline characters as if I typed them in TeX. So, the question is: how can I use tex.print from LUA in order to get the same effect as if I wrote the stuff directly into TeX?

29

Here is a list of my attempts. Perhaps I overlooked something more or less obvious. You see that I started with something trivial (printing two empty lines to generate a paragraph) to see how this is handled: Skip code block \documentclass{article} \usepackage{pgfplotstable} \begin{document} \parskip=20pt \parindent=0pt \expandafter\ifx\csname directlua\endcsname \relax \else \directlua {tex.enableprimitives('',tex.extraprimitives ())} % % using tex.print(42, ...) does not make a difference: %\savecatcodetable 42 \fi This is what I would like to generate -- from within LUA: \pgfplotstabletypeset{A B 2 3 4 5 } FAIL: \def\n{\noexpand\n} Here is a lua paragraph\directlua{tex.print("\n\n")}And here is the rest. GOOD: Here is a lua paragraph\directlua{tex.print("", "")}And here is the rest. FAIL: Here is a lua paragraph\directlua{tex.sprint("", "")}And here is the rest. FAIL: 30

\directlua{ % FAILS: the newline appears to have some strange catcode- and is % reported in a different way %tex.print("\noexpand\\pgfplotstabletypeset{A B\n 2 3\n 4 5\n}") } FAIL: \directlua{ % FAILS: the newline appears to have some strange catcode- and is % reported in a different way %tex.sprint("\noexpand\\pgfplotstabletypeset{A B\n 2 3\n 4 5\n}") } FAIL: \directlua{% % % FAILS: the curly brackets do not match, it interpretes % \pgfplotstabletypeset{A B % % as first statement and does not see the rest %tex.print("\noexpand\\pgfplotstabletypeset{A B", "2 3", "4 5}") } FAIL: \directlua{% % % FAILS: the curly brackets do not match, it interpretes % \pgfplotstabletypeset{A B % % as first statement and does not see the rest %tex.sprint("\noexpand\\pgfplotstabletypeset{A B", "2 3", "4 5}") } \end{document} I uncommented the items which produce compile failures. It should be noted that \pgfplotstabletypeset redefines the category code of newline to be 12 (other) and then it does its operation. I suppose this is 31

what caused the problem (in conjunction with LUA’s catcodetables).

Tags: luatex (Prev Q) (Next Q) 32

User: christian-feuersänger

Answer by bruno-le-floch A single call to tex.print produces a single line of input, so you must call it once per line. For instance, to get two newline markers, do Here is a Lua paragraph\directlua{tex.print("") tex.print("")}And here is another Issuing \tracingall before these lines shows that indeed there is a single \par, and not two. The same is true for the table: \documentclass{article} \usepackage{pgfplotstable} \begin{document} \directlua{tex.print("\string\\pgfplotstabletypeset{A B") tex.print("2 3")tex.print("4 5")tex.print("}")} \end{document}

Tags: luatex (Prev Q) (Next Q)

Q: Problem using length operator in Lua Tags: luatex (Prev Q) (Next Q) This is my MWE: Skip code block \documentclass{article} \newcommand{\printdata}{% \directlua{ data = {"a", "b", "c"} for i = 1, #data do 33

tex.print(data[i]) end } } \begin{document} \printdata \end{document} I get the following error message: ! Illegal parameter number in definition of \printdata. LuaLaTeX doesn’t seem to understand the length operator # in #data. Somewhere else I read that you must prefix it thus: \string#data, but this only works outside the \newcommand definition. How can I fix this problem? Tags: luatex (Prev Q) (Next Q) User: nvaughan

Answer by shreevatsar Make a file (say foo.lua) containing your Lua code: function printeverything() data = {"a", "b", "c"} for i = 1, #data do tex.print(data[i]) end end Then in your .tex file you can use it: \documentclass{article} \directlua{dofile('foo.lua')} \newcommand{\printdata}{\directlua{printeverything()}} \begin{document} 34

\printdata \end{document} (You don’t need to use a Lua function — you could just dump the function’s contents in your file and define \newcommand{\printdata}{\directlua{dofile('foo.lua')}} — but if you have multiple chunks of Lua code you may not want to create separate files for each of them.)

Explanation: When working with Lua code, and putting it in your .tex files, sooner or later you’ll run into this issue: the TeX engine (LuaTeX) will read through the characters of your .tex file assuming certain category codes, and characters like # have special meanings in TeX that you don’t intend in Lua code. There exists a way of working around this (run texdoc luacode to see the documentation of the luacode package), but IMO there are good reasons to do avoid these workarounds. As that documentation says in the very first paragraph: Before presenting the tools in this package, let me insist that the best way to manage a nontrivial piece of Lua code is probably to use an external file and source it from Lua, as explained in the cited document. The cited document (lualatex-doc.pdf) says: The luacode package provides commands and environments that help to varying degrees with some of these problems. However, for everything but trivial pieces of Lua code, it is wiser to use an external file containing only Lua code defining functions, then load it and use its functions. For example: \directlua{dofile("my-lua-functions.lua")} \newcommand*{\greatmacro}[2]{% \directlua{my_great_function("\luatexluaescapestring{#1}", #2)}} One of the reasons I prefer putting Lua code in a separate .lua file is that your editor probably does better syntax highlighting for the Lua code when it’s in an separate .lua file. (Similarly, you can get better highlighting when pasting the Lua code here on this website, if it’s a separate code block.)

35

Answer by egreg You can hide # to TeX, while making it good for Lua: Skip code block \documentclass{article} \newcommand{\printdata}{% \directlua{ data = {"a", "b", "c"} for i = \string##data, 1, -1 do tex.print(data[i]) end }% } \begin{document} \printdata \end{document} This prints cba Note that a direct call to \directlua would need a single #. The doubling here is because # appears in a definition. What’s this about? # is a special character for TeX. It is the “prefix” for parameters in definitions (and can be used alone in \halign, but it’s not the problem here). When TeX absorbs a definition it doesn’t interpret macros and commands, but it ensures that # is followed by a digit according to the number of arguments of the macro being defined. If we want to pass # to the replacement text of a macro, we need to double it. See What is the meaning of double pound symbol (number sign, hash character) ##1 in an argument? for details. In this way, the replacement text of \printdata will actually contain a sin36

gle #. However, such # would be interpreted at a call of the macro and it would appear in a wrong context; but \string# transforms # into a printable character, so it doesn’t harm macro expansion when \directlua is executed. Thus \string##data: the doubling means that just \string#data is stored in the replacement text of \printdata. Since \directlua first does TeX macro expansion, Lua will just see #data (with a safe #).

Tags: luatex (Prev Q) (Next Q)

Q: LuaLaTeX for dummies: how to add LaTeX macros into \directlua? Tags: luatex (Prev Q) (Next Q) How to make the following code to compile? \documentclass{article}

\newcommand*{\mycommand}{\directlua{for i = 1, 10 do tex.sprint(i\hskip1cm) end}} %\newcommand*{\mycommand}{\directlua{for i = 1, 10 do tex.sprint(i\\hskip1cm) end} %\newcommand*{\mycommand}{\directlua{for i = 1, 10 do tex.sprint(i) end}} \begin{document} test \mycommand \end{document} Tags: luatex (Prev Q) (Next Q) User: andreas-hettel

Answer by jldiaz First, you want to concatenate the value of the variable i with the token \hskip1cm, but the expression i\hskip1cm is not a valid lua expression.

37

What you need is to make \hskip1cm a lua string and concatenate it with the value of i. That is: tex.sprint(i .. "\hskip1cm") This, however, won’t work either because inside the quotes, the \ is a escapechar for lua, so \h will be interpreted as a escape sequence, and lua will complain that \h is an invalid escape sequence. So you have to ”escape the escape”: tex.sprint(i .. "\\hskip1cm") This would be ok for lua, but causes problems to TeX, since it makes \\ to appear inside a tex definition, and TeX tries to expand it, causing trouble. You can avoid this trouble in two different ways: First solution This is the preferred one. Move your lua code to an external file. For example, create a file called mycommand.lua, which contains a lua function implementing your code: -- mycommand.lua function mycommand() for i = 1, 10 do tex.sprint(i .. "\\hskip1cm") end end Then, in your tex file, run the lua file (which defines that function and makes it available for lua), and define \mycommand to execute the function mycommand. This way: \documentclass{article} \directlua{dofile("mycommand.lua")}

% This defines the lua function mycommand()

\newcommand*{\mycommand}{\directlua{mycommand()}} % This defines the tex macro \begin{document} test \mycommand \end{document} 38

Note that the expansion of \mycommand does not contain now any \\, so TeX is happy. When TeX expands \mycommand, this causes the function mycommand() to be executed, and this will ”output” into the tex document the concatenation of i.."\\hskip1cm", which results into 1\hskip1cm2\hskip1cm3\hskip1cm etc, which is ok. The resulting pdf shows the intended result:

Second solution This is uglier and in general not recommended. You can put any tex macro inside \luatexluaescapestring, and this will modify its expansion so that the result is a valid lua string. So, if you write for example "\luatexluaescapestring{\foo}" this will produce a complex string which contains the expansion of \foo, but wich each \ escaped as \\. Applying this to your example:

\documentclass{article} \newcommand*{\mycommand}{% \directlua{for i = 1, 10 do tex.sprint(i .. "\luatexluaescapestring{\hskip1cm}") } \begin{document} test \mycommand \end{document} Note how you still require double quotes around it, to get a lua string which can be concatenated to the value of variable i.

Tags: luatex (Prev Q) (Next Q)

Q: Printing LaTeX code in LuaTeX Tags: luatex (Prev Q) (Next Q) 39

A calculation is done in Lua, and according to the result a certain type of cell must display the data. This works: \multicolumn{3}{p{11cm}}{Test}&-10\\[0.4cm] But this doesn’t \directlua{tex.print(\multicolumn{3}{p{11cm}}{Test}&-10\\[0.4cm])} with the following error message: ! Undefined control sequence. \@setfontsize ...b ####1##2") else out:write("\space\space\space\space->") end if head.next==nil then out:write("nil") else out:write(string.format("%3d",head.next.id)) end out:write(" ("..n[head.id].."->") if head.next==nil then out:write("nil)\string\n") else out:write(n[head.next.id]..")\string\n") end if head.id==0 or head.id==1 then printnode(head.head) end head=head.next end return true end callback.register("post_linebreak_filter",printnode,"printnode")} \endgroup hello world \bye

Tags: luatex (Prev Q) (Next Q)

61

Q: How to access LaTeX counters in luatex? Tags: luatex (Prev Q) (Next Q) In the same vein as this question, I know I can access raw TeX counts with Lua using tex.count[key], but how do I access a LaTeX counters in Lua? MWE: Skip code block \documentclass{article} % This is TeX \newcount\mycount \mycount 4\relax % end of TeX \newcounter{mycountlatex} \setcounter{mycountlatex}{5} \begin{document} \directlua{tex.print(tex.count['mycount'])} % How to do something like this? % \directlua{tex.print(tex.count['mycountlatex'])} \end{document} Tags: luatex (Prev Q) (Next Q) User: nathanael-farley

Answer by nathanael-farley LaTeX counters can be accessed as TeX counts, but LaTeX prepends the name with a [email protected] so mycountlatex becomes [email protected] in TeX (source). This means the MWE above would become: Skip code block 62

\documentclass{article} % This is TeX \newcount\mycount \mycount 4\relax % end of TeX \newcounter{mycountlatex} \setcounter{mycountlatex}{5} \begin{document} \directlua{tex.print(tex.count['mycount'])} % How to do something like this? \directlua{tex.print(tex.count['[email protected]'])} \end{document}

Answer by aditya It is a good idea to hide such internal details from the user and define a latex.counter that ”does the right thing(tm)”. This is relatively easy to do in Lua using metatables: latex = latex or {} latex.counter = latex.counter or {} local counter = latex.counter local count = tex.count setmetatable(counter, {__index = function(t, key) return count['[email protected]' .. key] end} ) Now latex.counter[key] will return the value of the LaTeX counter key. Here is a complete example: Skip code block

63

\documentclass{article} \usepackage{luacode} \begin{luacode*} latex = latex or {} latex.counter = latex.counter or {} local counter = latex.counter local count = tex.count setmetatable(counter, {__index = function(t, key) return count['[email protected]' .. key] end} ) \end{luacode*} % This is TeX \newcount\mycount \mycount 4\relax % end of TeX \newcounter{mycountlatex} \setcounter{mycountlatex}{5} \begin{document} \directlua{tex.print(tex.count['mycount'])} % How to do something like this? \directlua{tex.print(latex.counter['mycountlatex'])} \end{document}

Tags: luatex (Prev Q) (Next Q)

64

Q: How to do a ’printline’ in LuaTeX Tags: luatex (Prev Q) (Next Q) I have just started exploring the world of LuaTeX and wanted to write a piece of code, that prints a name to a new line in the document. \directlua{ for i=1,3,1 do tex.print("FOO") end } which should produce the following output: FOO FOO FOO rather than: FOO FOO FOO How do I use Lua correctly? I have tried messing with \\ and many other things over the course of an hour. Am I approaching this problem from the wrong angle? Any help is highly appreciated. Tags: luatex (Prev Q) (Next Q) User: julian

Answer by topskip If you are using LaTeX (LuaLaTeX), I’d strongly advice against using \directlua{} for more than a simple call to execute another Lua file. \directlua{} is in no way safe. For example: • if you use a Lua comment (--), your code gets Q=”!%”§I. This is because in \directlua{} everything is read on one line. • If you try to use a literal % sign, for example in tex.print() you... well, try yourself . Good luck.

65

• If you try to use an active character such as ~ surprising results are guaranteed. • When you want to use tex.print() with a macro, such as \par, you have do crazy stuff to not let TeX see the macro before Lua sees the macro. • And good luck inserting strings like ”\n” for a new line character. Now what to do? Use the environment luacode* from the luacode package: \begin{luacode*} for i=1,3,1 do tex.print("FOO\\par") end \end{luacode*} If you can’t use the luacode package (for example when you use plain TeX), use dofile() or require() to load a package and put your code there. TeX can’t find and interpret the code there, only Lua. And then you can write for i=1,3,1 do tex.print("FOO\\par") end without trouble.

Answer by khaled-hosny tex.print appends \endlinechar to each string it prints except the last, so just print an empty string at the end. \directlua{ for i=1,3,1 do tex.print("FOO", "") end } \bye

Answer by chel

66

Two problems here: A "\\" in Lua just gets you one literal backslash which TeX stumbles over; as in the answers to this question you must use "\\\\" or [[\\]]. Also, \directlua expands control sequences within it; so if you want to pass a control sequence verbatim into Lua you’ll need to either\noexpand it or use \luaexec instead. Any of these three would work: \directlua{ for i=1,3,1 do tex.print([[FOO\noexpand\\]]) end }

\luaexec{ for i=1,3,1 do tex.print([[FOO\\]]) end }

\luaexec{nl = [[\\]]} \directlua{ for i=1,3,1 do tex.print("FOO" .. nl) end }

Tags: luatex (Prev Q) (Next Q)

Q: percent signs in luacode* environment (LuaLaTeX) Tags: luatex (Prev Q) (Next Q) Can someone explain what happens here: 67

\documentclass{article} \usepackage{luacode} \begin{document} \begin{luacode*} tex.print("xx\%a","yy\\%b","zz\\\%c") \end{luacode*} \end{document} The result is xxyy%b zz%c. (The xx,yy,zz is clear.) The \%a is ”ignored”, the \\%b and the \\\%c results in the ”same” %b (or c). What is the preferred way to get a % in the PDF output? Why is the \%a ignored? What does TeX see after returning from the lua call? Tags: luatex (Prev Q) (Next Q) User: topskip

Answer by aditya I assume that luacode in LaTeX works the same way as \startluacode...\stopluacode in ConTeXt. luacode expands its contents before passing control to lua. So, • xx\%a => xx%a (because \% = %) • yy\\%b => yy\%b (because \\ = \) • zz\\\%c => zz\%c (because \\ = \ and \% = %) Thus, (as Paŭlo Ebermann) mentioned, lua writes the following to TeX input stream: xx%a yy\%b zz\%c which explains the output that you get. Perhaps the following test file will make this clear (Compare the console output from pdf output). \def\%{?} \def\?{!} \starttext 68

\startluacode tex.print("xx\%a","yy\\%b","zz\\\%c") print("xx\%a","yy\\%b","zz\\\%c") \stopluacode \stoptext

Answer by paŭlo-ebermann I think the single \ serves to escape the next letter in Lua, letting itself dissappear. So, TeX gets to see these three lines: xx%a yy\%b zz\%c And obviously the first one causes the %a (+ the following line-break) to be ignored, while the second and third write out a %. It is a bit annoying that all (most) programming languages use the same \ as an escape character, so when embedding one in another you need multipleescaping.

Tags: luatex (Prev Q) (Next Q)

Q: Interactive lualatex compiling Tags: luatex (Prev Q) (Next Q) I have a made document using LuaLaTeX with some constants I have to change each time regarding about the circumstances. Is there a way that LuaLaTeX open an interactive window to ask me the value for the constants? For example, I want to be ask for n in the next MWE: Skip code block 69

\documentclass[border=3pt]{standalone} \usepackage{luacode} \newcommand{\bob}{% \luadirect{ n = 5 for i = 1,n do tex.print(i) end } } \begin{document} \bob \end{document} Tags: luatex (Prev Q) (Next Q) User: tarass

Answer by egreg You can have a rather primitive form of interaction if you run LuaLaTeX in interactive mode to begin with, that is, from a shell (a console/terminal, in other words). All front ends run LaTeX (any engine) in non interactive mode. Here’s how: Skip code block \documentclass[border=3pt]{standalone} \usepackage{luacode} \typein[\myn]{Tell me n, boss!} \newcommand{\bob}{% \luadirect{ 70

n = \myn\space for i = 1,n do tex.print(i) end } } \begin{document} \bob \end{document} The run on the terminal will interrupt with the message Tell me n, boss! \myn = to which you should answer by typing a number. No window system, I’m afraid. You can get a window with a fancy dialog box with any scripting language; the answer should be used to make the script run something like lualatex -interaction=nonstopmode '\def\myn{}\input{}' (add all other options you need). The \typein line should not be used, in this case.

Tags: luatex (Prev Q) (Next Q)

Q: Get value of macro from lualatex directly Tags: luatex (Prev Q) (Next Q)

71

I need to get the value of a macro from lualatex directly and return it in a function call function GetMacroValue(macro) return macro.value end I’ve tried various things such as using tex.print to store the value in a temp value BUT since tex.print executes after the function call/luacode block it does not work function GetMacroValue() tex.print("\\directlua{value = tonumber('\\the\\"..macro.."')}") return value end Would work except the tex.print line does not execute until after the fact in which case the previous value is returned. since tex.execute does not exist yet is there any other method? I’ve tried coroutines but it does not work for(or I can’t get it to work). Tags: luatex (Prev Q) (Next Q) User: abstractdissonance

Answer by topskip If it’s a count register, you can access it directly (tex.count[...]). Similar for other stored items such as toks, skip, dimen and attribute registers. See manual section 4.13.4. If it is something you only get ”during runtime” you have to use coroutines for that. I have written an answer to another question where I have given a short working example for a coroutine: https://tex.stackexchange.com/a/20905/243

Tags: luatex (Prev Q) (Next Q)

72

Q: My first luaLaTeX example Tags: luatex (Prev Q) (Next Q) I am totaly inexperienced in LuaLaTeX and I don’t know why but it was somehow very difficult to find working LuaLaTeX example so I can start playing around. I finaly found the example in a document Numerical methods using LuaLaTeX (p.3): Skip code block \documentclass{article} \usepackage{luacode}

\begin{luacode*} function trigtable () for t=0, 45, 3 do x=math.rad(t) tex.print(string.format( ’%2d$^{\\circ}$ & %1.9f & %1.9f & %1.9f & %1.9f \\\\’, t, x, math.sin( end end \end{luacode*} \newcommand{\trigtable}{\luadirect{trigtable()}} \begin{document} \begin{tabular}{rcccc} \hline & $x$ & $\sin(x)$ & $\cos(x)$ & $\tan(x)$ \\ \hline \trigtable \hline \end{tabular} \end{document} What I found out from this example is, how to implement Lua code in LaTeX document and it is all great, but how come that this example fails to com73

pile with LuaLaTeX if I save it as text.tex and process it using lualatex test.tex? I get this command line output: Skip code block This is LuaTeX, Version 1.0.4 (TeX Live 2017/Arch Linux) restricted system commands enabled. (./test.tex LaTeX2e (using write cache: /home/ziga/.texlive/texmf-var/luatex-cache/generic)(using r ead cache: /var/lib/texmf/luatex-cache/generic /home/ziga/.texlive/texmf-var/lu atex-cache/generic) luaotfload | main : initialization completed in 0.128 seconds Babel and hyphenation patterns for 1 language(s) loaded. (/usr/share/texmf-dist/tex/latex/base/article.cls Document Class: article 2014/09/29 v1.4h Standard LaTeX document class (/usr/share/texmf-dist/tex/latex/base/size10.clo(load luc: /home/ziga/.texlive/ texmf-var/luatex-cache/generic/fonts/otl/lmroman10-regular.luc))) (/usr/share/texmf-dist/tex/lualatex/luacode/luacode.sty (/usr/share/texmf-dist/tex/generic/oberdiek/ifluatex.sty) (/usr/share/texmf-dist/tex/luatex/luatexbase/luatexbase.sty (/usr/share/texmf-dist/tex/luatex/ctablestack/ctablestack.sty)))[\directlua]:5: malformed number near '2d'. \[email protected]@exec [email protected]@printdbg {#1} #1 } l.12 \end{luacode*} Tags: luatex (Prev Q) (Next Q) User: 71ga

Answer by shreevatsar (Answering the question rather than voting to close, because I can find no other occurrences of “malformed number near” on this site, so it would be useful to have this question around for anyone else who is likely to make a similar typo.)

74

The error message [\directlua]:5: malformed number near ’2d’. tells you where to look: on line 5 within the luacode block, near the string 2d. And this is what your file contains there (part of line 5 replaced with ...): tex.print(string.format( ’%2d$^{\\circ}$ ... note the character before the %2d: it’s ’ which is U+2019 RIGHT SINGLE QUOTATION MARK, and the Lua interpreter doesn’t know what to do with it. Actually it does: it thinks that ’ is the name of a variable, then looks at the % and decides you’re trying to take the remainder, but on the right side of the % operator you have 2d which is not a number. (Hence the error message about a malformed number.) If you had ’ = 23 and then string.format(’%4), the latter would correctly give you 3. (In this case even though you haven’t defined ’ to be a variable, the syntax-analysis part of Lua cannot give you an error immediately, because you could define a variable with that name later.) How did ’ get in there? Possibly a bug in your editor; make sure you fix it or it will happen again. Just change ’ to ’ in both places, and your code works; congratulations on getting your first LuaLaTeX file working correctly!

75

Aside: I have found it better to put all Lua code in a separate .lua file and in your .tex file have only \directlua{dofile('myluascript.lua')} (or whatever). This way you get better syntax highlighting for your lua code, when editing your file or when showing it on a site like this. Your code, with the lua code moved out and with @marsupilam’s advice of using [[ ... ]] strings: .tex file: Skip code block \documentclass{article} \directlua{dofile('lualatex-bug.lua')} \newcommand{\trigtable}{\directlua{trigtable()}} \begin{document} \begin{tabular}{rcccc} \hline 76

& $x$ & $\sin(x)$ & $\cos(x)$ & $\tan(x)$ \\ \hline \trigtable \hline \end{tabular} \end{document} lualatex-bug.lua:

function trigtable () for t=0, 45, 3 do x=math.rad(t) tex.print(string.format([[%2d$^{\circ}$ & %1.9f & %1.9f & %1.9f & %1.9f \\ t, x, math.sin(x), math.cos(x), math.tan(x))) end end

Answer by marsupilam You may be interested in lua long strings to discard all special characters in the string, and have them raw. This is especially relevant to luaLaTeX, as the escape character in lua is the backslash \. If you want to pass a command to TeX, the \ has to be doubled, and it may thus be less annoying to type [[\mycmd]] than "\\mycmd", or [[\\]] than "\\\\" The output

77

The code Skip code block \RequirePackage{luatex85} \documentclass[12pt,border=2pt]{standalone} \usepackage{luacode} \begin{luacode*} function trigtable () for t=0, 45, 3 do local x=math.rad(t) local sf =[[%2d$^{\circ}$ & %1.9f & %1.9f & %1.9f & %1.9f \\]] tex.print(string.format(sf, t, x, math.sin(x), math.cos(x), math.tan(x))) end end \end{luacode*} 78

\newcommand{\trigtable}{\luadirect{trigtable()}} \begin{document} \begin{tabular}{rcccc} \hline & $x$ & $\sin(x)$ & $\cos(x)$ & $\tan(x)$ \\ \hline \trigtable \hline \end{tabular} \end{document}

Tags: luatex (Prev Q) (Next Q)

Q: How to check for Lua definitions Tags: luatex (Prev Q) (Next Q) When there is \directlua{x = 25} one can say \edef\rgf{\directlua{tex.sprint(x)}}, but when x was never created by \directlua{x = 25}, \directlua{tex.sprint(x)} will fail. Thus something like \@ifundefined{x}{x undefined}{x defined} would be nice. How does one ”say this in Lua”, please? Tags: luatex (Prev Q) (Next Q) User: stephen

Answer by topskip You can do this: \directlua{tex.sprint( x or 42 ) } or perhaps \directlua{ 79

if x then tex.sprint(x) % else % do something else end }

Tags: luatex (Prev Q) (Next Q)

Q: LuaLaTeX, sprint verbatim text Tags: luatex (Prev Q) (Next Q) The code below, uses the lua, socket.http library to pull a web page (for simplicity I have used a link to a text file). I have used tex.sprint to pass it back to the typesetting engine. However I would have preferred to print within a verbatim environment or preferably using the listings environment. Any suggestions as to how I can achieve this? \documentclass{article} \usepackage[utf8]{luainputenc} \begin{document} \bgroup \catcode`\%=12 \catcode`\_=12 \catcode`\^=12 \catcode`\&=12 \directlua{ Skip code block local http = require("socket.http") function url_encode(str) if (str) then str = string.gsub (str, "\string\n", "\string\r\string\n") str = string.gsub (str, "([^%w ])", 80

function (c) return string.format ("%%%02X", string.byte(c)) end) str = string.gsub (str, " ", "+") end return str end function url_decode(str) str = string.gsub (str, "+", " ") str = string.gsub (str, "%%(%x%x)", function(h) return string.char(tonumber(h,16)) end) str = string.gsub (str, "\string\n", "\string\n") return str end local page = http.request( 'http://mirror-cybernet.lums.edu.pk/pub/ctan/dviware/ tex.sprint(page) } \egroup \end{document} Note, the MWE contains two functions that I haven’t used, for encoding and decoding the url. I left them in case you want to try a different url. As a sideline I find it amazing that old ’TeX’ in new clothes can talk to the web. Tags: luatex (Prev Q) (Next Q) User: yiannis-lazarides

Answer by topskip There are some problems with your code: 1. don’t use \usepackage[utf8]{luainputenc} in your document as utf8 is the default 2. Put the Lua code in a separate file. If that is not feasible, use the luacode* environment from the luacode package See the question about luacode enviroments. Then you don’t need to mess with the cat codes. 3. The two functions you define are not used (and are unnecessary). Here is a solution which works with the listings environment: 81

Skip code block \documentclass{article} \usepackage{luacode} \usepackage{listings} \begin{document}

\begin{luacode*} local http = require("socket.http") local page = http.request( 'http://mirror-cybernet.lums.edu.pk/pub/ctan/dviware/s tex.print("\\begin{lstlisting}") tex.print(page:gsub("\n","\r")) tex.print("\\end{lstlisting}") \end{luacode*} \end{document}

Answer by aditya FWIW, in ConTeXt you can simply use

\starttext \typefile{http://mirror-cybernet.lums.edu.pk/pub/ctan/dviware/screenview/vms/test. \stoptext to load a file from the net. Almost all file loading macros use the socket library to download (and cache) the file, if a url is specified. If you want to do this manually, the following works:

\starttext \startluacode local http = require("socket.http") local page = http.request( 'http://mirror-cybernet.lums.edu.pk/pub/ctan/dviware/s tex.print(string.format("\\starttyping %s \\stoptyping", page)) \stopluacode \stoptext (I could not get the similar code to work in LuaLaTeX because the luacode 82

environment in LaTeX uses different catcodes than the luacode environment in ConTeXt)

Tags: luatex (Prev Q) (Next Q)

Q: Accessing pointers in LuaTeX Tags: luatex (Prev Q) (Next Q) This code writes the subtype of disc nodes to the log file. Skip code block \documentclass{minimal} \usepackage{fontspec} \directlua{ show_hyph = function(head) while head do if head.id == 0 or head.id == 1 then % hlist, vlist show_hyph(head.head) elseif head.id == 7 then % disc texio.write_nl("Subtype " .. head.subtype) end head = head.next end return true end luatexbase.add_to_callback("post_linebreak_filter",show_hyph,"show_hyph") } \begin{document} \begin{minipage}{1pt} discretionary \end{minipage} \end{document} 83

The LuaTeX reference manual says in section 8.1.2.7 “disc nodes” pre pointer to the pre-break text How do I access this? Tags: luatex (Prev Q) (Next Q) User: håkon-malmedal

Answer by topskip How do I access this? This is very simple and straightforward: use head.pre to access the list pointing to the pre part of the discretionary. Now the question you might ask next is ”why is the pre-part nil?” This is because you call your function show_hyph() on the post_linebreak_filter. At that point the pre part is already inserted before that disc node and thus the pre part is empty. The same is with post and replace. What I can’t tell you is why the disc node stays in the node list.

Tags: luatex (Prev Q) (Next Q)

Q: LuaTeX gets stuck when ”.” is added to pattern-expression Tags: luatex (Prev Q) (Next Q) today on SE I got inspired to try LuaTeX. I’m facing a problem where the compilation process stalls at some point if I add a single ”.” to a pattern matching expression. In short, this works: line = string.gsub ( line , "^(%s*)" this doesn’t: 84

,

"%1" )

line = string.gsub ( line , "^(%s*)."

,

"%1" )

(I know this pattern doesnt make toooo much sense, but it’s a reduced version of a longer expression) Compilation stalls at: This is LuaTeX, Version beta-0.80.0 (TeX Live 2015/Debian) (rev 5238) restricted \write18 enabled. (./mwe4.tex LaTeX2e patch level 2 [...] (/usr/share/texlive/texmf-dist/tex/luatex/luatexbase/cctb.lua)) (/usr/share/texlive/texmf-dist/tex/luatex/luatexbase/luatexbase-mcb.sty (/usr/share/texlive/texmf-dist/tex/luatex/luatexbase/mcb.lua)))) (./mwe4.aux)) * A full MWE is here (the critical line being #6): Skip code block \documentclass{article} \usepackage{luacode,luatexbase} \begin{luacode} function replacetext2 ( line ) line = string.gsub ( line , "^(%s*)" return ( line ) end \end{luacode}

,

"%1" )

\newenvironment{haystack}{% \directlua{luatexbase.add_to_callback( "process_input_buffer", replacetext2, "replacetext2")}}{% \directlua{luatexbase.remove_from_callback( "process_input_buffer", "replacetext2")}} \begin{document} \begin{haystack} 85

a b \end{haystack} \end{document} Tags: luatex (Prev Q) (Next Q) User: sheß

Answer by heiko-oberdiek The pattern ^(%s*). in line = string.gsub ( line , "^(%s*)."

,

"%1" )

looks for any white space (can be empty) at the begin of line, followed by one character (.). This is replaced by the white space (%1) and the matched non-white-space character is removed. Therefore LuaTeX will no longer see \end{haystack}, but end{haystack} and keeps looking for the end of the environment. The example with some debug output to show the line in brackets, before and after the substitution: Skip code block \documentclass{article} \usepackage{luacode,luatexbase} \begin{luacode} function replacetext2 ( line ) texio.write_nl('') texio.write('[', line, '] --> [') line = string.gsub ( line , "^(%s*)." texio.write(line, "]") texio.write_nl('') return ( line ) end \end{luacode} \newenvironment{haystack}{% 86

,

"%1" )

\directlua{luatexbase.add_to_callback( "process_input_buffer", replacetext2, "replacetext2")}}{% \directlua{luatexbase.remove_from_callback( "process_input_buffer", "replacetext2")}} \begin{document} \begin{haystack} a b \end{haystack} \end{document} Result: [a] --> [] [ b] --> [ ] [\end{haystack}] --> [end{haystack}] [\end{document}] --> [end{document}] If you only want to remove a real dot at the beginning of a line, then the dot needs to be escaped as magic character %., since the pure dot . means any character.

Tags: luatex (Prev Q) (Next Q)

Q: Cannot access arguments in a lua block Tags: luatex (Prev Q) (Next Q) The follow code is trying simply to print the first argument of a macro. I’ve tried various things found on the net(there is very little) to get #1 printed in lua but nothing works. I assume there is an issue with interpreting it in lua. Would be nice if there was some tutorial on bridging the gap between

87

tex and lua. Most stuff I’ve seen use external lua files or do not reference anything except macros in a directlua block. Skip code block \documentclass[11pt]{book} % use larger type; default would be 10pt \usepackage{luatex} \usepackage{pgffor} \tracingonline 6 \directlua{ tex.enableprimitives('',tex.extraprimitives()) local lpeg = require "lpeg" } \begin{document} \def\Parse#1{ \directlua{ cmdString = tostring(#1) tex.print(cmdString) } } \Parse{hello12341234asdf}

\end{document} Tags: luatex (Prev Q) (Next Q) User: uiy

Answer by mico

88

You shouldn’t just specify #1 as the argument of tostring; rather, try something like "\luatexluaescapestring{#1}". With this modificaton, your MWE works fine: Skip code block \documentclass[11pt]{book} \usepackage{luatex,pgffor} \tracingonline 6 \directlua{ tex.enableprimitives('',tex.extraprimitives()) local lpeg = require "lpeg" } \def\Parse#1{ \directlua{ cmdString = tostring("\luatexluaescapestring{#1}") tex.print(cmdString) } } \begin{document} \Parse{hello12341234asdf} \end{document}

Update, May 2016: Alain Matthes has pointed out in a comment that the code shown above no longer runs, at least not with TeXLive2015. The problem turns out to be related to the version of the luatex package that’s installed on one’s system. Happily, arlier this month Heiko Oberdiek released an update to luatex.sty which fixes this issue. As TeXLive2015 is currently ”frozen”, one either needs to download the updated package from the CTAN and install it manually, switch to the latest release of TeXLive2016-pre, or wait a few more weeks until the official version of TeXLive2016 is released and may be installed Alternatively, load the luacode package instead of the luatex package.

Answer by topskip

89

Mico has already given the correct answer. Let me extend the explanation. When you write: \def\Parse#1{\directlua{

cmdString = tostring(#1)

}}

and call \Parse{hello12341234asdf}, the result is pretty much like this: \directlua{

cmdString = tostring(hello12341234asdf)

}

Which is, of course, not what you want. You need to put the quotation marks around the definition: \def\Parse#1{\directlua{

cmdString = tostring("#1")

}}

and a call to \Parse{hello12341234asdf}, gives \directlua{

cmdString = tostring("hello12341234asdf")

}

Now what happens if you call \Parse{hello"1234}? You get \directlua{

cmdString = tostring("hello"1234")

}

which, again, is not what you want. Therefore you need to escape the contents of #1. This is what \luaescapestring{} does for you. But this won’t work in LaTeX, because in LaTeX every Lua command from the reference manual is prefixed with luatex (except for \directlua). Therefore the defintion is that what Mico writes: \def\Parse#1{\directlua{

cmdString = tostring("\luatexluaescapestring{#1}")

Tags: luatex (Prev Q) (Next Q)

Q: Problem with luacode in sty file Tags: luatex (Prev Q) (Next Q) I’m trying to include a gcd function using lua in a sty file. Here is the code of euclide.sty : Skip code block

90

}}

\RequirePackage{ifluatex,luacode,luatextra} \ifluatex \begin{luacode} function euclide(a,b) if a < b then a,b = b,a end r = a-math.floor(a/b)*b if r == 0 then tex.print(b) else euclide(b,r) end end \end{luacode} \newcommand{\euclide}[2]{\luaexec{euclide(#1,#2)}} \fi Here is the texfile code : \documentclass[10pt,oneside]{article} \usepackage{euclide} \begin{document} \euclide{435}{630} \end{document} The lualatex compilation give me errors : Skip code block Runaway argument? ! File ended while scanning use of \[email protected]@lines.

\par l.4 I suspect you have forgotten a `}', causing me to read past where you wanted me to stop. I'll try to recover; but if the error is serious, you'd better type `E' or `X' now and fix your file.

! LaTeX Error: Missing \begin{document}. Can somebody tell me what’s wrong in my code ? (this code works fine in the main tex file, but not in sty file) Thanks, MB. 91

Tags: luatex (Prev Q) (Next Q) User: mb78

Answer by heiko-oberdiek I can reproduce the problem, if the white space before \end{luacode} is a tabulator character. Environment luacode is a special environment, because it changes category codes to read its contents in a more verbatim way. Therefore the end detection is not done by the usual macro expansion, but by searching for the string \end{luacode} at the start of a new line (spaces are ignored with catcode 10 here). Fix: Replace tabulators by spaces (depending on the editor, there might be an option for this.) BTW: It is a little inconsistent: First packages are loaded that require LuaTeX (luacode and luaextra), then the code is wrapped in \ifluatex. If the package works with and without LuaTeX: Skip code block \RequirePackage{ifluatex} \ifluatex \RequirePackage{luacode,luaextra} \begin{luacode} ... \end{luacode} ... \else ... \fi Or test for LuaTeX and throw an error, if LuaTeX is required: Skip code block \RequirePackage{ifluatex} \ifluatex \else \PackageError{euclide}{LuaTeX is required}\@ehd 92

\newcommand*{\euclide}[2]{% % dummy definition }% \expandafter\endinput % abort early \fi \RequirePackage{luacode,luaextra} \begin{luacode} ... \end{luacode}

Tags: luatex (Prev Q) (Next Q)

Q: LuaTeX: \luaexec leads to ’Missing number, treated as zero.’ Tags: luatex (Prev Q) (Next Q) I can’t handle Lua LaTeX interaction in LuaTeX. I’m getting type errors anytime luacode is suppose to output non-string token. For example in this case: Skip code block \documentclass{report} \usepackage[export]{adjustbox} \usepackage{fontspec} \usepackage{luacode} \begin{luacode*} function params() tex.print(0.12) end \end{luacode*} \begin{document} 93

{\adjustbox{trim={\luaexec{params()}\width} {.2\height} {0.1\width} {.15\height},c {\includegraphics[keepaspectratio,width=5cm]{pic.jpg}}} \end{document} I’ll get: ’Missing number, treated as zero.’ Tags: luatex (Prev Q) (Next Q) User: tomas-jakl

Answer by joseph-wright This is an expansion question: \luacode is not expandable. Underlying the trim key is a TeX dimension assignment: what is given here needs to be assignable by TeX as a length, and that means any code used has to be expandable. However, if you trace the definition of \luacode it contains a \begingroup (and other stuff) which stops expansion. This non-expandable code is used to make the \luacode macro work, but it means that you can’t structure you input in the way you want. As mentioned in a comment, a ’raw’ \directlua will work here: the primitive is expandable so supplies TeX with what is required (here 0.12\textwidth). To explain the error itself, what happens is that TeX finds the \begingroup but is looking for a number. Non-expandable tokens terminate the number search but TeX hasn’t got anything it can interpret as a number, so it gives an error.

Tags: luatex (Prev Q) (Next Q)

Q: Token expansion with the token library Tags: luatex (Prev Q) (Next Q) I don’t understand how the token library of luatex works. Skip code block 94

\documentclass{standalone} \begin{document} \def\mymacro{A} \directlua{% t = token.create ('mymacro') token.expand(t) token.get_next() } \end{document} The token.expand does not work as I expected: luatex says Undefined control sequence. Why? With the token.get_next(), I don’t know exactly what I should get... Tags: luatex (Prev Q) (Next Q) User: cjorssen

Answer by andrew-swann Unfortunately token.expand is currently broken. See the bug report which derives from an example exactly like yours.

Tags: luatex (Prev Q) (Next Q)

Q: Using lua code to obtain rules of different lengths Tags: luatex (Prev Q) (Next Q) I started to learning LuaLateX nowadays and I’d like to get some rules with increasing lengths, but I can’t figure out why this simple code doesn’t give 95

the desired output: Skip code block \documentclass[11pt]{book} \usepackage{xcolor} \usepackage{luatex,pgffor, luacode, calc} \begin{document} \newcommand{\myrules}{ \dimen0=2cm \luaexec{ for i=1,4 do tex.dimen[0]=tex.dimen[0]*i tex.print("\\color{red}\\rule{\\dimen0}{3pt}\\par") end } } \myrules \end{document} Tags: luatex (Prev Q) (Next Q) User: paulo-henrique-duarte

Answer by heiko-oberdiek \luaexec is a wrapper for\directlua. It executes the Lua code and expands to: \color{red}\rule{\dimen0}{3pt}\par \color{red}\rule{\dimen0}{3pt}\par \color{red}\rule{\dimen0}{3pt}\par \color{red}\rule{\dimen0}{3pt}\par Also \luaexec calls \directlua inside a group. Thus the local assignments of tex.dimen[0] are lost before TeX proceeds with the expansion result of \directlua. If the rules should be 2cm, 4cm, 6cm, and 8cm, then there is also a flaw in the algorithm that yields 2cm, 4cm, 12cm, 48cm.

96

Example file for the first version: Skip code block \documentclass[11pt]{book} \usepackage{xcolor} \usepackage{luatex,pgffor, luacode, calc} \parindent=0pt \begin{document} \newcommand{\myrules}{% \dimen0=2cm % \luaexec{ for i=1,4 do tex.print("\\color{red}\\rule{", tex.dimen[0]*i, "sp}{3pt}\\par") end }% } \myrules \end{document}

Tags: luatex (Prev Q) (Next Q)

Q: How to convert glue spec like ‘\parfillskip=0pt plus 1fil’ to LuaTeX glue node Tags: luatex (Prev Q) (Next Q) I am trying to create a glue node that I can assign to the internal parameter tex.parfillskip.

97

In Plain TeX, the glue for \parfillskip is assigned as \parfillskip=0pt plus 1fil. Dumping the values in Lua(TeX): print("width: " .. tex.parfillskip.width) print("stretch: " .. tex.parfillskip.stretch) print("shrink: " .. tex.parfillskip.shrink) print("stretch_order: " .. tex.parfillskip.stretch_order) print("shrink_order: " .. tex.parfillskip.shrink_order) leads to this output: width: 0 stretch: 65536 shrink: 0 stretch_order: 2 shrink_order: 0 So my questions are: • How does one convert a value 1fil to the stretch component of the glue spec. Is it just as simple as multiplying by 65536 (as it seems from the dump)? • How does one determine the value stretch_order? It seems a bit arbitrary. The value above is 2, but the stretch_order value for tex.topskip is 0. How does one determine what to put in that component for the glue spec. Tags: luatex (Prev Q) (Next Q) User: anjaan-aadmi

Answer by egreg LuaTeX introduced an additional degree of infinite glue: you can have fi, fil, fill and filll. So settings like \parfillskip=0pt \parfillskip=0pt \parfillskip=0pt \parfillskip=0pt \parfillskip=0pt

plus plus plus plus plus

1pt 1fi 1fil 1fill 1filll 98

will have stretch orders 0, 1, 2, 3, 4 respectively. Indeed

{\directlua{tex.setglue("parfillskip",65536,65536,65536,1,1)}\showthe\parfillskip} will stop with > 1.0pt plus 1.0fi minus 1.0fi. The units are in scaled points, so to get 1 you need 65536 whatever you choose among the ones above.

Tags: luatex (Prev Q) (Next Q)

Q: lualatex print, directlua env, and newline Tags: luatex (Prev Q) (Next Q) When using print from lua, if the log file’s current line has not been terminated then the lua tex will not start on a new line. This is very annoying because many times I search for some debug string being printed and it is not on a new line but at the end of some rather long line printed from TeX. e.g.,

Printing some debug string 1 [1{C:/Users/Administrator/AppData/Local/MiKTeX/2.9/pdftex/config/pdftex.map}] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13]Printing another debug string 2 [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27]` Instead of Printing some debug string 1 [1{C:/Users/Administrator/AppData/Local/MiKTeX/2.9/pdftex/config/pdftex.map}] [2] Printing another debug string 2 [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27] The 2nd one is the preferred case but if I print a newline, \n, then I’ll get unnecessary empty lines I do not want. 99

Is there any way to fix this? Basically on every entry of \directlua or whatever is used I want to print a new line ONLY if something is actually printed(so I don’t get a bunch of blank lines) and, even better, only if the log file does not also end on a new line. Tags: luatex (Prev Q) (Next Q) User: abstractdissonance

Answer by topskip Use texio.write_nl(...): Skip code block \documentclass{article} \usepackage{luacode} \begin{document} \begin{luacode*} texio.write_nl("Printing some debug string 1") \end{luacode*} foo \clearpage \begin{luacode*} texio.write_nl("Printing some debug string 2") \end{luacode*} \end{document} gives ... (/opt/texlive2012/texmf-dist/tex/luatex/luatexbase/luatexbase-modutils.sty (/opt/texlive2012/texmf-dist/tex/luatex/luatexbase/modutils.lua)) (/opt/texlive2012/texmf-dist/tex/luatex/luatexbase/mcb.lua)))) (./test.aux) Printing some debug string 1 [1{/opt/texlive2012/texmf-var/fonts/map/pdftex/upd map/pdftex.map}] Printing some debug string 2 (./test.aux) ) 267 words of node memory still in use: ... In one project I have defined a helper function: 100

function w( ... ) texio.write_nl("-----> " .. string.format(...)) end so that I can easily use formatted strings: w("Printing some debug string %d",1)

Tags: luatex (Prev Q) (Next Q)

Q: lualatex: how to produce PDF acceptable by arxiv? Tags: luatex (Prev Q) (Next Q) With pdflatex, it is possible to create PDF files that are acceptable by arxiv even without sources (with hyperref + \pdfsuppressptexinfo=1, see Making an anonymous PDF file using PDFLaTeX). However, I don’t manage to create such a PDF using lualatex. With LuaLaTeX, what is the equivalent of \pdfsuppressptexinfo=1? Tags: luatex (Prev Q) (Next Q) User: martin-monperrus

Answer by ulrike-fischer The (extended) equivalent to \pdfsuppressptexinfo is \pdfvariable suppressoptionalinfo \numexpr number\relax see the luatex documentation. So something like this works: Skip code block \documentclass{article} \usepackage{hyperref} \hypersetup{ 101

pdfcreator = {}, pdfproducer = {} } \pdfvariable suppressoptionalinfo \numexpr 1+2+4+8+16+32+64+128+256+512 \relax

\begin{document} abc \end{document}

Tags: luatex (Prev Q) (Next Q)

Q: Problems with multi-page output when building nodes directly with node.write() Tags: luatex (Prev Q) (Next Q) MWE mwe.tex \directlua{tex.enableprimitives('',tex.extraprimitives())} \output={\shipout\box255} \pagewidth=210mm \pageheight=2in \hoffset=1in \voffset=1in \directlua{dofile("mwe.lua")} \end mwe.lua Skip code block tex.outputmode = 1

102

-- Build a simple paragraph node from given text. This code does not do any comple --- adapted from: http://tex.stackexchange.com/questions/114568/can-i-create-a-node local function text_to_paragraph(text) local current_font = font.current() local font_params = font.getfont(current_font).parameters local para_head = node.new("local_par") local last = para_head local indent = node.new("hlist",3) indent.width = tex.parindent indent.dir = "TRT" last.next = indent last = indent

for c in text:gmatch"." do -- FIXME use utf8 lib local v = string.byte(c) local n if v < 32 then goto skipchar elseif v == 32 then n = node.new("glue",13) node.setglue(n, font_params.space, font_params.space_shrink, font_params.spa else n = node.new("glyph", 1) n.font = current_font n.char = v n.lang = tex.language n.uchyph = 1 n.left = tex.lefthyphenmin n.right = tex.righthyphenmin end last.next = n last = n ::skipchar:: end 103

-- now add the final parts: a penalty and the parfillskip glue local penalty = node.new("penalty", 0) penalty.penalty = 10000 local parfillskip = node.new("glue", 14) parfillskip.stretch = 2^16 parfillskip.stretch_order = 2 last.next = penalty penalty.next = parfillskip node.slide(para_head) return para_head end

local content = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do e for i = 1,3 do local head = text_to_paragraph(content) -- Break the paragraph into vertically stacked boxes local vbox = tex.linebreak(head, { hsize = tex.hsize }) node.write(vbox) node.write(node.copy(tex.parskip)) node.write(node.copy(tex.baselineskip)) print("PAGE TOTAL " .. tex.pagetotal) end Output Note that it gets cut off. I was expecting a page break to happen, and the rest of the content to move over to the next page.

104

Notes/Questions The idea is to create paragraph nodes entirely in Lua, and feed them to LuaTeX using node.write(). • I am overriding the Plain TeX output routine with the default output routine by doing: \output={\shipout\box255} • The tex.pagetotal parameter does not seem to increment itself automatically. Not sure if that is part of the problem • I guess another way to do this is to populate the entire box on my own and ship it out using tex.shipout, but I was hoping to exercise the page-building routines inside TeX to break the page at the right location, instead of doing it on my own. How can I fix this? Tags: luatex (Prev Q) (Next Q) User: vyom

Answer by vyom Turns out, it is a pretty silly oversight on my part. I was only adjusting the \pageheight. The \vsize parameter being used was the one set in the Plain TeX macro (which is 8.9in). If I change the size of \vsize to be a little less than \pageheight, then things work fine. \directlua{tex.enableprimitives('',tex.extraprimitives())} \output={\shipout\box255} 105

\pagewidth=210mm \pageheight=2in \vsize=1in \hoffset=1in \voffset=1in \directlua{dofile("mwe.lua")} \end

Tags: luatex (Prev Q) (Next Q)

Q: In LuaLaTeX, how do I pass the content of an environment to Lua verbatim **Without displaying it** in a beamer frame? Tags: luatex (Prev Q) (Next Q) In this question / answer : one pass verbatim latex material to lua, but latex displays this material by him self. If one suppress the two lines : local buf_without_end = mybuf:gsub("\\end{foobar}\n","") print(string.format("Lua: %q", buf_without_end)) the material doesn’t disapear. I’d like to modify this material using lua code and display it after. Skip code block \documentclass{beamer} \usepackage{luacode,tikz} \directlua{dofile("verb.lua")} \newenvironment{LuaVerb}{% \directlua{start_recording()}}{% \directlua{stop_recording()} } \begin{document} 106

\begin{frame} % pass the material to lua \begin{LuaVerb} hello word \end{LuaVerb} % use of this material, but with or witout this line % the material is displayed %\directlua{print_recording()} \end{frame} \end{document} verb.lua Skip code block tp = tex.print mybuf = "" function readbuf( buf ) mybuf = mybuf .. buf .. "\n" end function start_recording() luatexbase.add_to_callback('process_input_buffer', readbuf, 'readbuf') end function stop_recording() luatexbase.remove_from_callback('process_input_buffer', 'readbuf') end function print_recording() local buf_without_end = mybuf:gsub("\\end{LuaVerb}\n","") 107

print(string.format("Lua: %q", buf_without_end)) mybuf = "" end Tags: luatex (Prev Q) (Next Q) User: tarass

Answer by michal.h21 If you don’t want to pass lines to LaTeX, you have to return empty string from the callback, otherwise callback pass the line if return value is nil. Because you don’t return any value, nil is used implicitly. And because LaTeX doesn’t process input anymore, you have to parse input for \end{LuaVerb} from Lua side, otherwise you would grab all lines until the end: local end_verb = '%s*\\end{LuaVerb}' function readbuf( buf ) if buf:match(end_verb) then return buf end mybuf = mybuf .. buf .. "\n" return "" end Now there is some strange issue with beamer, which is maybe caused by how frames are processed, because no output is printed with print_recording(). But when I changed document class to article, I got: (/opt/texlive/2013/texmf-dist/tex/luatex/luatexbase/mcb.lua)))) (./jej.aux)Lua: " hello word\ "

Tags: luatex (Prev Q) (Next Q)

108

Q: Using LuaLaTeX and SQLite3 Tags: luatex (Prev Q) (Next Q) I am trying to access SQLite databases from LuaLaTeX but am not able to load an installed lsqlite3 package. Here’s what I tried so far: 1. Took a brandnew Xubuntu 14.04 installation 2. Installed a complete TeX Live 2014 3. Installed Luarocks (which installed Lua5.1 on the way) 4. Used Luarocks to install lsqlite3 [email protected]:/media/uwe$ luarocks list Installed rocks: lsqlite3 0.9.1-2 (installed) - /usr/local/lib/luarocks/rocks 5. Appended the package.path in the following TeX file: \documentclass{article} \usepackage{luacode} \begin{document}

\begin{luacode*} package.path="/usr/local/lib/luarocks/rocks;/usr/local/lib/luarocks/rocks/l /usr/local/lib/lua/5.1/lsqlite3.so" .. package.path require("lsqlite3") \end{luacode*} Hello Lua! \end{document} The error I receive is the following: ! LuaTeX error [\directlua]:3: module 'lsqlite3' not found: no field package.preload['lsqlite3']

109

[luatexbase.loader] Search failed [kpse lua searcher] file not found: 'lsqlite3' [kpse C searcher] file not found: 'lsqlite3' [oberdiek.luatex.kpse_module_loader]-eroux Search failed stack traceback: [C]: in function 'require' [\directlua]:3: in main chunk. \[email protected]@exec [email protected]@printdbg {#1} #1 } l.9 \end{luacode*} What must be set to have LuaLaTeX find the lsqlite3 package? EDIT I have tried to adjust everything following the comments below: 1. Adjusted /usr/local/texlive/2014/texmf.cnf 2. Put everything into the example 3. Still get the error about the missing lsqlite3 module with the following example \documentclass{article} \directlua{ require "lualoader" } \usepackage{fontspec} \usepackage[english]{babel} \begin{document}

\directlua{package.path='/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/ package.cpath='/usr/local/lib/lua/5.1/?.so;/home/uwe/.luarocks/lib/lua/5.1/?. require "lualoader" } \directlua{% local sqlite3 = require("lsqlite3") local db = sqlite3.open_memory() 110

db:exec[[ CREATE TABLE test (id INTEGER PRIMARY KEY, content); INSERT INTO test VALUES (NULL, 'Hello World'); INSERT INTO test VALUES (NULL, 'Hello Lua'); INSERT INTO test VALUES (NULL, 'Hello Sqlite3') ]] for row in db:nrows("SELECT * FROM test") do tex.print(row.id .. " : ".. row.content ) end } \end{document} Tags: luatex (Prev Q) (Next Q) User: uwe-ziegenhagen

Answer by vyom As of May 2017, there is a package on CTAN called luapackageloader, that allows you to modify the default package searching behavior in LuaTeX. Once you load luapackageloader, doing a require will first try the default kpse based searcher. If the module isn’t found, it will also try to load the package from Lua’s package.path and package.cpath values. Usage example Skip code block \documentclass{article} \usepackage{luacode} \usepackage{luapackageloader} \begin{document} \begin{luacode*} 111

package.path="/usr/local/lib/luarocks/rocks;/usr/local/lib/luarocks/rocks/lsqlit /usr/local/lib/lua/5.1/lsqlite3.so" .. package.path require("lsqlite3") \end{luacode*} Hello Lua! \end{document} Additional note: you can do eval $(luarocks path) on your shell to set the package path using environment variables which the Lua interpreter will pick up automatically. That way, you do not need to fiddle with the package.path yourself.

Tags: luatex (Prev Q) (Next Q)

Q: Find node above and under Tags: luatex (Prev Q) (Next Q) Using a post_linebreak_filter callback, is it possible to access the nodes positioned above and under a given node? Tags: luatex (Prev Q) (Next Q) User: �aphink

Answer by topskip Yes. You have to do a lot of calculation, though. To find the position of a node use node.dimensions() from the head to the node (see the examples in the reference manual, beware of glue_set, glue_sign and glue_order in the hlist node) and do the same with the lines above and below. With this you could implement a river detection algorithm :).

112

Tags: luatex (Prev Q) (Next Q)

Q: Why the luatex85 package and the luatex manual does not share the same definitions for \pdf...? Tags: luatex (Prev Q) (Next Q) One can read in the luatex85 documentation: LuaTEX 0.85 and 0.87 contain many changes from LuaTEX 0.80 as contained in TEXLive 2014. Most notably almost all the pdfTEX extended primitves with names \pdf... have been renamed or removed. [...] The LuaTEX manual lists suitable compatibility definitions that may be made so that documents can continue to use the old names. Mostly this package just consists of those definitions, with minor changes in some cases. (Mostly different choices over the use of \protected or \edef.) Is there a reason other than ”programming taste” for those different choices? Tags: luatex (Prev Q) (Next Q) User: cjorssen

Answer by david-carlisle The luatex85 definitions have the advantage that they are in code and tested in more cases (used in the wild in latex) so work in more cases. Several of the definitions were tweaked in the first few releases. Usually it doesn’t matter too much whether you use \def or \edef or whether or not you use \protected, and whether you terminate a number using a space or by \numexpr...\relax. But if you try the emulation in enough real 113

world documents doing enough weird expansion contexts then you find that different commands need different types of emulation. For example the case you mention in comments \def\pdffontname{\pdffeedback fontname} % (luatex85.sty) \def\pdffontname{\numexpr\pdffeedback fontname\relax}% manual In almost all cases this is going to be used as a number as in \[email protected]=\pdffontname and either definition will work, but pdftex allows this to expand to a number in all contexts, and does not require \the so this plain tex document \pdffontname\font \bye Is error free and typesets 1 The \numexpr version would produce ! You can't use `\numexpr' in vertical mode. \pdffontname ->\numexpr \pdffeedback fontname\relax l.5 \pdffontname \font ? unless you prefixed with \the But the version without \def\pdffontname{\pdffeedback fontname} \pdffontname\font \bye does the right thing. Sometimes as in {\outputmode=1 114

\xdef\pdfcreationdate

{\pdffeedback creationdate}

} we work harder to expand to the right thing in one expansion step as someone had a real package that did ....\expandafter\something\pdfcreationdate and \something needed to access the expanded date not just the first level expansion of \pdffeedback creationdate, and also pdftex makes this available in both PDF and DVI modes whereas the LuaTeX feedback is only available if \outputmode is 1. It isn’t clear that these considerations to make a robust emulation that works in the wild would necessarily clarify the manual which is giving the basic idea of how you might address the name changes that happened in LuaTeX 0.85, so we never thought it necessary to push these differences back to the LuaTeX team for the manual.

Tags: luatex (Prev Q) (Next Q)

Q: In LuaTeX, how can I escape text that will be inserted in LaTeX? Tags: luatex (Prev Q) I wrote a Lua function that dumps data from a TXT file in my LaTeX document. The problem I have right now is that the data the TXT file is treated as LaTeX code so I need to escape special characters with backslashes and so on. Is there a way to treat the data from the TXT file as ”plain text” without any LaTeX formatting? My hunch is that either: • There is a LaTeX macro for this. kindof like verbatim, but without displaying my text in typewriter font. • There is ready-made LuaTeX macro or function for this. Basically the opposite of \luaescapestring 115

• I’ll have to write down a special-character-escaping function by hand.

Source for test.tex: \documentclass{article} \directlua{dofile("test.lua")} \begin{document} \directlua{test("test.txt")} \end{document} Source for test.lua: function test(filename) local file = io.open(filename) local s = file:read("*a") tex.print(s) file:close() end My current test.txt, which uses LaTeX formatting: Hello \$\#\%! My desired test.txt would be plain text and possibly contain any special characters: Hello $#%! Tags: luatex (Prev Q) User: hugomg

Answer by topskip Use tex.print(-2,s) to get the desired output. Background: the function tex.print() accepts different numbers of parameters. In the simplest variant, it accepts the string that should be output. It also accepts a ”catcode table” as the first argument (a number). There are 116

predefined catcode tables, and -2 is a catcode table where all special characters are not special anymore. Therefore tex.print(-2,"#") does not insert a ”# with catcode 6” but ”# with catcode 12”. As you all know, 12 is the catcode for ”other characters” which are harmles.

Tags: luatex (Prev Q)

Fonts Skip to questions, Wiki by user stefan-kottwitz fonts is about fonts and how to use them. It deals with questions about changing family, shape and weight of fonts, but also with font packages. For choosing a font, the LaTeX Font Catalogue is a very useful resource. If you are interested in installing a new font, perhaps the font installation guide can help. Though be warned, installing fonts in LaTeX is not trivial. For using a font locally, see How do I use a particular font for a small section of text in my document?. If your question is not about a font in general but about specific symbols, use symbols instead. For questions about font sizes, use fontsize. Specialized tags: fontenc, fontspec, opentype, truetype, metafont, fontmetrics, berry Tags for specific ”styles”: bold, italic, small-caps, blackboard, typewriter Tags for specific typefaces: computer-modern, latin-modern, libertine, mathpazo, minion, amssymb, xits

117

Questions Q: microtype settings for dummies Tags: fonts (Next Q), fontspec (Next Q), microtype (Next Q) More than a year ago, a friend of mine was totally excited about microtype features in LaTeX. He was talking about it quite a bit and then said to me: ”Show me your document, let me add some lines of code and it’s gonna be awesome!” What he added was this: Skip code block \usepackage[ protrusion=true, expansion=true, final, babel ]{microtype} \usepackage{fontspec} \pdfprotrudechars=2 \pdfadjustspacing=2 \newfontfeature{Microtype}{protrusion=default;expansion=default;} \directlua{fonts.protrusions.setups.default.factor=.5} \setmainfont[ Microtype, Numbers={OldStyle, Proportional}, Ligatures=TeX ]{Brill} The only thing I changed about this was the font. I use the Brill Font, but only because it contains many special characters I need for work. About the rest, I don’t have a clue what all this means. Okay, I did look into the documentations (months ago) and searched tex.sx (just now), and I learned what protrusion is and what expansion is, and what they do, but I don’t really see a difference, for -- to me -- simply (almost) every TeX result looks super, and I certainly see no real difference between Garamond, Minion, Caslon, et al., nor could I tell which I’d prefer. I am not a man of the ”finer” arts, so deciding about microtype settings and features is but a little too ”designical” for me. 118

By the way: I am using LuaLaTeX. So maybe, someone could just tell me if these settings may be alright the way they are. Brill makes a full ”Typeface User Guide” available. If you want an example of how this font looks in order to answer my question, please see this document. Tags: fonts (Next Q), fontspec (Next Q), microtype (Next Q) User: clinteastwood

Answer by robert A number of answers: Firstly, microtypography is (in my book) the art of enhancing the appearance of a document while exhibiting the minimum degree of visual obtrubsion, that is, ideally, without even being recognisable: Characters with less optical weight should slightly protrude into the margin to make it appear more even, but they shouldn’t stick in your face; fonts may be distorted ever-so-slightly to allow for better line breaks, but they should not look distorted. Therefore, it is actually good that you don’t see any difference. You should, however, make sure that something does indeed happen: for protrusion, find a hyphen at the end of a line and check whether it protrudes, as it should do, into the margin (by about half of its length), or whether it is fully contained in the text block; for expansion, check whether line breaks in a longer paragraph change when you remove the lines your colleague added. If line breaks are the same in both cases, and if hyphens don’t hang over, then protrusion and expansion are in fact not enabled at all, which would be a topic for a new question. Secondly, the microtypepackage tries to lift the burden of deciding about settings as much as possible from the user. Considering that you say yourself that you are not a man of the finer arts, I would advise to just load the microtype package without any options at all. (In your code, the protrusion and expansion options are superfluous as they are enabled anyway, babel doesn’t have any effect, only final may be justified to ensure that line breaks don’t change when adding draft as a class option.) Now for the final point, which obviously causes the most confusion. As 119

Jörg has pointed out, you are using both the microtype package as well as lualatex’s own microtypography feature (with the latter taking precedence). You should therefore decide, and either load microtype: \usepackage[final]{microtype} \usepackage{fontspec} \setmainfont[Numbers={OldStyle, Proportional}, Ligatures=TeX ]{Brill} or use lualatex’s techniques: \usepackage{fontspec} \pdfprotrudechars=2 \pdfadjustspacing=2 \newfontfeature{Microtype}{protrusion=default;expansion=default} \directlua{fonts.protrusions.setups.default.factor=.5} \setmainfont[Microtype, Numbers={OldStyle, Proportional}, Ligatures=TeX ]{Brill} I would advise to go with the first, as microtype’s settings are more complete and balanced IMHO (but then, I am, of course, biased ...). The second option has the advantage of better integration with luatex. Here, a factor of .5 seems reasonable (the default protrusion, especially of the hyphen, is just too much, quite obtrusive and therefore contradicting the idea of microtypography to me).

Answer by fran I think that defaults are just enough for most texts, but it depend the overall text format (font size, font type, text width, margins, columns, etc.) and how sensitive are your eyes to bad spacing or the abuse of microtype methods. To test if your settings are OK first try (with some long text) a disproportionated value in one option as stretch=1000. You surely will notice a very strong stretch effect that ruins your text. All right, it was only to see the effect.

120

Now try successively with much more moderate options (100, 50, 40 ...). When you reach a value (suppose that is 30) where you cannot notice the stretch effect and the text just look good probably you have found a good value. It is time to check finally if there are some difference within you election and the default (20) or even less (For example, some people find 10 more appropriate). In a editor as Gummi you can see the changes in the PDF in about one second, so this check is faster than it looks. It would also be advisable to look on Google to see the options that people choose. After all, the document should not be attractive to the author but to target readers.

Tags: fonts (Next Q), fontspec (Next Q), microtype (Next Q)

Q: How to keep a ”rare” ligature from interfering with a ”common” ligature? Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q), xetex (Next Q), ligatures (Next Q) In ligature-rich Opentype fonts which feature both ”common” and ”rare” ligatures, it can happen that a ”rare” ligature is applied first to one character pair, pre-empting the use of a ”common” or ”rare” ligature that ought to be applied to the preceding or trailing character pair. (Regarding ligature terminology in Opentype fonts: Most, but not all, Opentype font families I’m familiar with classify the f-ligatures -- ff, fi, fl, ffi, ffl, and possibly also ft, fft, and a few more -- as ”common” and all others as either ”rare”/”discretionary” or ”historic”. ) Two examples of this behavior, which can arise with both XeLaTeX and LuaLaTeX: • With the font Garamond Premier Pro, the ”rare” is ligature is applied first to words such as fish and fist, pre-empting the use of the ”common” fi ligature. 121

• With the font Junicode, the ”rare” iv and ix ligatures are applied first to words such as five, fix, and affixed, pre-empting the use of the ”common” fi and ffi ligatures.

Without this pre-emption, the output would look like this (achieved the ”brute force” way, i.e., by inserting \kern0pt between i and s, i and v, and i and x, respectively):

(Observe, by the way, that the brute-force suppression of the rare is ligature in the word ”fist” not only enables the common fi ligature but also the rare st ligature.) Question: Which methods may be available -- ideally on a document-wide basis -- that prevent the application of certain rare ligatures if they pre-empt other, either common or rare, ligatures? Aside: This posting is not a duplicate of the earlier posting How to suppress a ”Rare” ligature that pre-empts a ”Common” ligature for the same character pair? In the earlier question, the issue was that ”rare” and ”common” forms of a given ligature could be present for one and the same character pair (or triple). Examples of this issue are common and rare forms of ligatures for ”ft” and ”fft”.

Here’s the code that gives rise to the second screenshot shown above; remove the \kern0pt directives to generate the first screenshot: Skip code block

122

% !TEX TS-program = lualatex \documentclass{article} \usepackage{fontspec} \begin{document} \setmainfont[Ligatures = Rare, ItalicFont = {Garamond Premier Pro Italic}] {Garamond Premier Pro} % 'is'-ligature available only in italic shape in GPP \emph{fi\kern0ptsh fi\kern0ptst} --- Garamond Premier Pro \setmainfont[Ligatures = Rare]{Junicode} fi\kern0ptve fi\kern0ptx affi\kern0ptx --- Junicode \end{document} Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q), xetex (Next Q), ligatures (Next Q) User: mico

Answer by mico In my view, the following ligature suppression rules are needed. • In order to enable the fi ligature, suppress the is, iv, and ix ligatures if is/iv/ix is preceded by f; • In order to enable the sp and st ligatures, suppress the is ligature if is is followed by either p or t. In the jargon of Opentype fonts, fi is called a common ligature, and is, iv, and ix, as well as sp and st, are called rare or discretionary ligatures. The following solution, which works under LuaLaTeX (but not under XeLaTeX), employs the selnolig package. (Full disclosure: I’m the main author of the selnolig package.) The ligature suppression rules given above are implemented via several \nolig instructions: 123

\nolig{fis}{fi|s} \nolig{fiv}{fi|v} \nolig{fix}{fi|x} \nolig{isp}{i|sp} \nolig{ist}{i|st}

% % % % %

break break break break break

up up up up up

'is' 'iv' 'ix' 'is' 'is'

lig. lig. lig. lig. lig.

if if if if if

preceded preceded preceded followed followed

by by by by by

'f' 'f' 'f' 'p' 't'

More concisely, one would write: \nolig{fi[svx]}{fi|.} \nolig{is[pt]}{i|s.} The . character after the | is shorthand for ”any glyph”. I’m not sure if the increase in terseness and density is worth the cost of reduced (human) legibility. If one wanted to suppress the is, iv, and ix ligatures globally, while still allowing other ”rare” ligatures to be used, a single \nolig instruction would do the job: \nolig{i[svx]}{i|.}

In the following code, the upright shape of Junicode is used for the iv and ix cases, and the italic shape is used of Garamond Premier Pro is used for the sp and st ligatures. The first data row shows the outcome with selnolig being ”on”; for comparison, the second data row shows the outcome with selnolig being turned ”off”.

Skip code block % !TEX TS-program = lualatex \documentclass{article} \usepackage{fontspec,booktabs} \setmainfont[Ligatures = Rare, ItalicFeatures = {Scale = MatchLowercase}, 124

ItalicFont = {Garamond Premier Pro Italic}] {Junicode} \setsansfont[Scale=MatchLowercase]{Palatino Sans Com} \usepackage{selnolig} \nolig{fis}{fi|s} % break \nolig{fiv}{fi|v} % break \nolig{fix}{fi|x} % break \nolig{isp}{i|sp} % break \nolig{ist}{i|st} % break

up up up up up

'is' 'iv' 'ix' 'is' 'is'

lig. lig. lig. lig. lig.

if if if if if

preceded preceded preceded followed followed

by by by by by

'f' 'f' 'f' 'p' 't'

%% Or, more concisely: % \nolig{fi[svx]}{fi|.} % \nolig{is[pt]}{i|s.} \begin{document} \noindent \begin{tabular}{@{}[email protected]{}} \textsf{selnolig} & Junicode: iv, ix & \em Gar.\ Prem.\ Pro Italic: is\\ \midrule On & five fix affix & \em fish fissure fist gist lisp\\[0.5ex] \selnoligoff % turn off selnolig's operations Off & five fix affix & \em fish fissure fist gist lisp\\ \end{tabular} \end{document}

Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q), xetex (Next Q), ligatures (Next Q)

Q: Why does it take LuaLaTeX so long to load fonts and can I speed it up? Tags: fonts (Prev Q) (Next Q) 125

To test Mico’s upcoming selnolig package, I tried out LuaLaTeX. While the overall experience for me as a pdfLaTeX end-user was very similar, I noticed that LuaLaTeX takes a long time to load fonts. Here is a sample document that I compiled several times (lualatex foo.tex), measuring the compilation time unscientifically with a clock, deleting the auxiliary files between each compile (latexmk -c foo.tex), and trying different fontspec configurations. Skip code block \documentclass{article} % the following lines were included in: \usepackage{fontspec} % A, B, C \setmainfont{Minion Pro} % B, C \setsansfont{Myriad Pro} % C \usepackage{lipsum} \begin{document} \lipsum \end{document} My timing results turned out the same ±1s for three runs each, so I assume they are reliable: A B C C

(just fontspec) (+ Minion Pro) (+ Myriad Pro) (using XeLaTeX)

10s 33s 39s 7s (just as a comparison)

Killing all processes that I knew I could safely kill, including but not limited to things you tend to have open while TeXing like an editor and a browser, brought down compilation times for configuration C to 26s (LuaLaTeX) and 4s (XeLaTeX). (Cf. my comment to topskip) When the compilation became slow the following lines were displayed in the command line output (the log file contains the same information with a lot more information in between):

luaotfload | Font names database loaded: C:/Users/doncherry/AppData/Local/MiKTeX/2 126

9/luatex-cache/generic/names/otfl-names.lua(load: C:/Users/doncherry/AppData/Local MiKTeX/2.9/luatex-cache/generic/fonts/otf/temp-minionpro-regular.lua)(load: C:/ Users/doncherry/AppData/Local/MiKTeX/2.9/luatex-cache/generic/fonts/otf/temp-minio pro-bold.lua)(load: C:/Users/doncherry/AppData/Local/MiKTeX/2.9/luatex-cache/gener c/fonts/otf/temp-minionpro-it.lua)(load: C:/Users/doncherry/AppData/Local/MiKTeX/2 9/luatex-cache/generic/fonts/otf/temp-minionpro-boldit.lua)(load: C:/Users/doncher ry/AppData/Local/MiKTeX/2.9/luatex-cache/generic/fonts/otf/temp-myriadpro-regula r.lua)(load: C:/Users/doncherry/AppData/Local/MiKTeX/2.9/luatex-cache/generic/font /otf/temp-myriadpro-bold.lua)(load: C:/Users/doncherry/AppData/Local/MiKTeX/2.9/lu tex-cache/generic/fonts/otf/temp-myriadpro-it.lua)(load: C:/Users/doncherry/AppDat /Local/MiKTeX/2.9/luatex-cache/generic/fonts/otf/temp-myriadpro-boldit.lua) The keywords cache and temp appearing here made me think there might be some way to store this information permanently so that it doesn’t have to be created each time? I used LuaTeX, Version beta-0.70.2-2012060719 (MiKTeX 2.9) (format=lualatex 2012.9.9) on Windows 7 64 bit. The fonts are the ones provided through Adobe Reader X, manually installed by me to C:\Windows\Fonts. So my question is: Why is the compilation with LuaLaTeX so slow and can I do anything about that? Tags: fonts (Prev Q) (Next Q) User: doncherry

Answer by topskip There are several causes here, but 39 seconds seems way too much. Your log file shows that your files are already in the cache format (temp-fontname.lua). • fontspec loads a lot of instances during startup (\setmainfont). Each of them takes time. • memory speed/limit can have a big impact. These lua tables tend to be huge and need to be parsed each time the font loads. If the available memory is limited, even paging might be a problem (though I doubt it is nowadays). 127

Since XeTeX is so quick, I assume most of the time is spent on the second given point.

Tags: fonts (Prev Q) (Next Q)

Q: Suppress certain ligatures generally Tags: fonts (Prev Q) (Next Q), ligatures (Prev Q) (Next Q) Whether or not certain ligatures should be used (if available in a font) is a least in theory depending on the language used. For example traditional German texts would not have an ”ffl” ligature but would have ”ft” and also ”ch” and ”ck”. pdfTeX supports disabling selected ligutures but you will always disable the full set beginning with a certain character, so it is not possible to drop ”ffl” but keep ”fi”, say. (I haven’t checked what pdfTeX actually does, this is my understanding from the microtype manual). From reading through the LuaTeX manual I can see that there should be (in theory) much finer control possible, but I don’t see concepts to hook into the ligature mechanism to easily provide a language-based abstraction. In my opinion a mechanism should apply at (or close to) the typesetting stage and not at during input preparation, i.e., the answer to ”Can one suppress ligatures for certain words?” addresses this too early in the game. So my questions are: • Has something for this already be programmed? • If not, how complicated would it be, given the current functionality in LuaTeX, or are there some useful interfaces for this still missing? Unfortunately this doesn’t address how to specify that for certain languages you may want to have ”ligature-kerns” i.e., some extra kerning used only in a particular language to bring some character pairs closer together than in other languages. Tags: fonts (Prev Q) (Next Q), ligatures (Prev Q) (Next Q) 128

User: frank-mittelbach

Answer by mico In addition to the question Can one (more or less) automatically suppress ligatures for certain words? (and the associated answers) that you already mention in your posting, you may also want to check out the content of the follow-up questions: Any suggestions/requests for features for a new package that allows disabling ligatures for (pre)selected words? and How to suppress the operation of a luatex-defined macro on a string if the string is part of macro or a label. Shameless self-citation alert! In the latter question in particular, I provided the rudiments of lua code to suppress the use of certain (or all) ligatures for certain words. This code could easily be made language-specific by linking it, say, to the use of a language option set in babel. Unfortunately, my initial plans to create a stand-alone package that implements this approach have gotten stymied after I discovered that the code is too powerful: the ligature substitution (suppression, if you will) algorithm cannot be instructed not to operate on TeX macros; e.g., should there be a macro named \auflaufen, one apparently cannot instruct luatex not to replace the string ”auflaufen” with ”auf{\hspace{0pt}}laufen}, leading to unpredictably chaotic consequences. Similarly, the ligature suppression algorithm can’t be instructed not to operate on the arguments of certain macros such as \label and \ref (and, by extension, \vref, \cref etc.). For these reasons I’ve given up for now on making this a standalone package, as its applicability would always be ”experimental” at best. Hopefully, more lua programming tools and hooks will be made available so that it’ll become possible to set up the needed exceptions (e.g., don’t operate on the names of TeX macros, and don’t operate on the arguments of \label, \ref, etc) to make the approach I’ve developed usable for a general public.

Answer by j.-c.-salomon OpenType fonts class ligatures as Required, Common, Contextual, Rare/Discretionary, and Historic; and there are “features” for each of these (rlig, liga, clig, dlig, & hlig), which can be enabled or disabled 129

separately via fontspec (and, presumably, ConTeXt, but I don’t know for certain). For example, in this answer, letter-spacing Fraktur requires certain ligatures (ch, ck, ſt, & tz) to be kept, but others disabled. The fontspec invocation given therefore disables the “Common” ligatures but explicitly enables the “Required” ones;—and this is the important part—the font used in that example has the ligatures classed correctly for this purpose. This is therefore only a partial answer. It only works for OpenType fonts for which this classification of ligatures has been correctly done, and it’s not useful in the arbitrary case of (e.g.) enabling “fi” but disabling “fl”. (On the other hand, a font designed for German might have different ligature tables enabled depending on the language setting. YMMV. (On the gripping hand, see An example of changing kerning of a font in LuaLaTeX, which indicates that patches to faulty OpenType tables [presumably including ligature tables] can be included at font-load time.)

Tags: fonts (Prev Q) (Next Q), ligatures (Prev Q) (Next Q)

Q: FontAwesome font not found? Tags: fonts (Prev Q) (Next Q), xetex (Prev Q) (Next Q) I’m using the latest version of MacTeX 2013 on OS X 10.8.4. All of my Tex Live packages are fully up-to-date. Tex Live also lists the fontawesome package as installed. I’m trying to use the FontAwesome font with XeLatex or LuaLatex and getting font-not-found errors. The exact message is: kpathsea: Running mktexmf FontAwesome ! I can't find file `FontAwesome'. There’s a longer traceback which I am omitting for brevity. Let me know if it’s needed to resolve this problem.

130

I have already tried running the following commands, to no avail: sudo -H mktexlsr sudo -H updmap-sys Other than the above two commands, this is a 100% new out-of-the-box installation, with no modifications whatsoever. Here’s a minimal broken example: \documentclass{article} \usepackage{fontawesome} \begin{document} \faTwitter \end{document} How can I add this missing font? Tags: fonts (Prev Q) (Next Q), xetex (Prev Q) (Next Q) User: knite

Answer by michael-kropat If anyone wants to get this working with xelatex without installing the font into your system, see section 4.2 By file name of the fontspec.pdf manual: [Loading the font by file name] is also necessary in XeTeX when loading OpenType fonts that are present within your TEX distribution, such as /usr/local/texlive/2013/texmf-dist/fonts/opentype/public. Fonts in such locations are visible to XeTeX but cannot be loaded by font name, only file name; LuaTEX does not have this restriction. Since fontawesome.sty simply references the font by name: % definition of \FA as a shortcut to load the Font Awesome font \newfontfamily{\FA}{FontAwesome} We have to set the default Path to locate the font, before loading fontawesome:

131

Skip code block \documentclass{article} \usepackage{fontspec}

\defaultfontfeatures{ Path = /usr/local/texlive/2013/texmf-dist/fonts/opentype/public/fontawesome/ } \usepackage{fontawesome} \begin{document} \faTwitter \end{document} You may have to change Path depending on where fontawesome is installed. Assuming you’re using TeX Live, you can find the relative path to the font file by running: tlmgr info --list fontawesome Output: Skip code block

package: fontawesome category: Package shortdesc: Font containing web-related icons. longdesc: The package offers access to the large number of web-related icons pr installed: Yes revision: 31020 sizes: doc: 173k, run: 101k relocatable: Yes cat-version: 3.1.1 cat-date: 2014-04-26 20:05:48 +0200 cat-license: other-free collection: collection-fontsextra Included files, by type: run files: texmf-dist/fonts/opentype/public/fontawesome/FontAwesome.otf texmf-dist/tex/latex/fontawesome/fontawesome.sty doc files: texmf-dist/doc/latex/fontawesome/README details="Readme" 132

texmf-dist/doc/latex/fontawesome/fontawesome.pdf texmf-dist/doc/latex/fontawesome/fontawesome.tex

Answer by jonathan-komar Note this answer assumes you didn’t add the TeX Live fonts to the system environment variables such that they are found when fontspec searches the system fonts. (either because you don’t know how or because it isn’t practical e.g. multi-client Version Control System situation) Assuming you are using XeLaTeX: To minimize maintenance with each sequential TeX Live release (2015,2016, etc.), I chose to add \defaultfontfeatures{Extension = .otf} rather than provide an explicit path. This is because XeLaTeX automatically loads $(kpsewhich -var-value TEXMFSYSVAR)/fonts/conf/texlive-fontconfig.conf into its path. texlive-fontconfig.conf from TeX Live 2015

/usr/local/texlive/2015/texmf-dist/fonts/opentype /usr/local/texlive/2015/texmf-dist/fonts/truetype /usr/local/texlive/2015/texmf-dist/fonts/type1

With each release, this gets updated, so you don’t have any maintenance costs ;) So you only need to add the extension parameter to \newfontfamily{\FA}{FontAwesome} indirectly this way. This is of course provided that the fonts you’re using are OTF. \documentclass{article} \usepackage{fontspec} \defaultfontfeatures{Extension = .otf}% adds .otf to end of path when font loaded 133

\usepackage{fontawesome} % Relevant path loaded (TeX Live 2015 expansion): /usr/lo \begin{document} \faTwitter This is a test. \end{document}

As a fun exercise to prove your understanding, you could create a document like this: Skip code block \listfiles \documentclass{article} \usepackage{fontspec} %\defaultfontfeatures{ % Extension = .otf %} %\usepackage{fontawesome} \newfontfamily\fatest{FontAwesome.otf} % Explicitly provide .otf %or %\newfontfamily\fatest[Extension=.otf]{FontAwesome}

\begin{document} %\faTwitter This is a test {\fatest\char"F099} This is a test \end{document} This works because the following are equivalent: • \newfontfamily\fatest{FontAwesome.otf} • \newfontfamily\fatest[Extension=.otf]{FontAwesome} • \defaultfontfeatures{Extension = .otf}\newfontfamily{\fatest}{FontAwesome} because they all yield a platform-independent path. e.g. Unix-based: /usr/local/texlive/2015/texmf-dist/fonts/opentype/FontAwesome.otf 134

and fontspec will try to load a font by adding each prefix listed in this xml file:

ANYTHING IN HERE GETS PREFIXED to the font file

See tex.stackexchange.com/a/313886/13552

Tags: fonts (Prev Q) (Next Q), xetex (Prev Q) (Next Q)

Q: How do I get a list of all font features supported by current font Tags: fonts (Prev Q) (Next Q), opentype (Next Q) With LuaTeX, how do I get a list of OTF features supported by the current font in use printed? For example, with otfinfo, I can get a list of OTF features by otfinfo -f font_file_name. Can I do anything similar with LuaTeX? The goal is to produce such a list for each font I tested. For example, I would like to have such a macro, \def\listfontfeatures{ \directlua{... some lua code to list font features to a string, say ff ...} \directlua{tex.print(ff)} } And use it like the following, Times Ten LT Std: \fontspec{Times Ten LT Std} \listfontfeatures \par Palatino LT Std: \fontspec{Palatino LT Std} \listfontfeatures \par Minion Pro: \fontspec{Minion Pro} \listfontfeatures \par Update 12/01/2017

135

Here’s just a small improvement to michal.h21’s answer, just in case anyone will be interested. fontspec_if_feature actually tests font features for the currently selected font family instead of the currently selected font. Normally this makes little difference and I only noticed this recently. For some fonts, different shapes have different features. For example, the italics may have swashes while the roman fonts lack it. Below is a few macros that I now use for font feature test. It only work for LuaTeX. some modifications to the FontName macro is needed to make it to work with XeTeX. Skip code block \ExplSyntaxOff % remove the necessity to use ~ for space \NewDocumentCommand\FontName{}{% \directlua{ local i = font.current() local f = font.getfont(i) local n = f.fullname tex.sprint(n) }% } \ExplSyntaxOn % Setup a new font family whose "n/m" shape is the current font. % Limitations: The contents of the true/false clauses will be % set in current fonts without any features selected by default, % and it will be set in a group. For myself, this was intentionally. \NewDocumentCommand\FontFeatureTF{m +m +m}{ \group_begin: \fontspec_set_family:Nnn\thisfont:{}{\FontName} \fontfamily\thisfont:\selectfont \fontspec_if_feature:nTF{#1}{#2}{#3} \group_end: } \NewDocumentCommand\FontFeatureT{m +m}{ \FontFeatureTF{#1}{#2}{\prg_do_nothing:} 136

} \NewDocumentCommand\FontFeatureF{m +m}{ \FontFeatureTF{#1}{\prg_do_nothing:}{#2} } Tags: fonts (Prev Q) (Next Q), opentype (Next Q) User: yan-zhou

Answer by michal.h21 You can use fontspec function \fontspec_if_feature:nTF. It will work in both xelatex and lualatex Skip code block

\documentclass{article} \usepackage{fontspec,etoolbox,expl3} \setmainfont{Cambria} \def\fontfeatures{abvf, abvm, abvs, aalt, akhn, nalt, halt, afrc, valt, vhal, blwf % see http://en.wikipedia.org/wiki/OpenType_feature_tag_list#OpenType_Typographic_ \ExplSyntaxOn \newcommand\listfontfeatures{% \renewcommand*{\do}[1]{ \fontspec_if_feature:nTF {##1}{##1,\ }{} } \expandafter\docsvlist\expandafter{\fontfeatures} } \ExplSyntaxOff \begin{document} \listfontfeatures \end{document}

Answer by khaled-hosny This should list all features in the current font, it can even be extended to list supported scripts and languages for every feature:

137

Skip code block \documentclass{article} \usepackage{fontspec} \begin{document} \newcommand\listfontfeatures{% \directlua{ local id = font.current() local font = fonts.identifiers[id] local data = font.shared.otfdata if data then local features = data.luatex.features for i,_ in next, features do for f,_ in next, features[i] do %print(f, table.serialize(features[i][f])) tex.sprint(-1, f.." ") end end end }} \fontspec{TeX Gyre Pagella} \listfontfeatures \end{document}

Answer by herbert On Linux it is simple and I suppose that Windows has a similiar command Skip code block [email protected]:~/.fonts/Junicode> otfinfo -f Junicode.ttf c2sc Small Capitals From Capitals calt Contextual Alternates case Case-Sensitive Forms ccmp Glyph Composition/Decomposition dlig Discretionary Ligatures fina Terminal Forms frac Fractions 138

hist hlig kern liga mark mgrk mkmk onum rtlm salt smcp ss01 ss02 ss04 ss05 ss06 ss07 ss08 ss09 ss14 ss15 ss18 ss19 ss20 subs sups swsh

Historical Forms Historical Ligatures Kerning Standard Ligatures Mark Positioning Mathematical Greek Mark to Mark Positioning Oldstyle Figures

Stylistic Alternates Small Capitals Stylistic Set 1 Stylistic Set 2 Stylistic Set 4 Stylistic Set 5 Stylistic Set 6 Stylistic Set 7 Stylistic Set 8 Stylistic Set 9 Stylistic Set 14 Stylistic Set 15 Stylistic Set 18 Stylistic Set 19 Stylistic Set 20 Subscript Superscript Swash

Tags: fonts (Prev Q) (Next Q), opentype (Next Q)

139

Q: Differences regarding kerning and ligaturing when using the MacTex2013 and MacTeX2014 versions of LuaLaTeX with .ttc fonts Tags: fonts (Prev Q) (Next Q), ligatures (Prev Q) (Next Q) This posting is a follow-up to the postings Can’t generate ligatures with LuaLaTeX under MacTeX2014 and MacTeX2015 when using certain fonts and LuaLaTeX, fontspec, .ttc fonts and kerning (Optima on Mac OS). I have a 13” MacBookPro that runs MacOSX 10.9.4. The issue is that with with the release of MacTeX2104, LuaLaTeX -- but not XeLaTeX -- has apparently ceased to perform kerning and ligaturing for certain fonts with file extension .ttc. Consider the following MWE: Skip code block % !TEX TS-program = LuaLaTeX \documentclass{article} \usepackage{fontspec} \setmainfont{Hoefler Text} \setsansfont{Optima} \listfiles \begin{document} WA AV Test Type off fit fly office baffle \textsf{WA AV Test Type} \end{document} Running this MWE under LuaTeX 0.79.1 (part of MacTeX2014), I get

whereas running it under LuaTeX 0.76 (provided by MacTeX2013), I get

140

In the LuaTeX 0.76 output, note the sophisticated kerning and the presence of various f-ligatures. Unfortunately, both kerning and ligaturing appear to have vanished under LuaTeX 0.79.1, at least for the two particular fonts used in this MWE (Hoefler Text and Optima). In fact, it’s not just these two fonts that are experiencing problems; quite a few fonts with file extension .ttc contained in /Library/Fonts experience this deterioration as well. Among the ones I’ve tested and have have found to exhibit the problem described above are Baskerville, Didot, and Futura Medium. In contrast, I have not (yet!) found a single font with extension .otf that experiences these problems when run with MacTeX2014-version of Lua(La)TeX. Questions: • Is there something that can/should be done to re-enable kerning and ligaturing under MacTeX2014/LuaLaTeX 0.79.1 with these .ttc fonts? • Barring an affirmative answer to the preceding question, what are the step-by-step instructions for converting one or more of the affected fonts into a format (.otf?) that lets LuaLaTeX 0.79.1 performing kerning and ligaturing correctly? By ”correctly”, I mean the way that LuaLaTeX 0.76 as well as the older and current vintages of XeLaTeX manage to get these jobs done. Any software used to perform the font format conversion or adaptation should be open-source and (obviously...) be capable of being run under MacOSX. I’m willing (and able!) to provide a 200 point ”bonus” for every good answer to these two questions.

Addendum, August 2015: I’ve posted a partial solution to the problem, viz., how to manually set up one or more OpenType feature files that provide instructions for LuaLaTeX to generate the ligature substitutions, as an answer to my earlier posting on this subject, Can’t generate ligatures with LuaLaTeX under MacTeX2014 and MacTeX2015 when using certain fonts. 141

For completeness, here are the file lists produced when running the MWE under the two different TeX distributions. When running MacTeX2014: Skip code block This is LuaTeX, Version beta-0.79.1 (TeX Live 2014) (rev 4971) (format=lualatex 2014.7.9) 26 AUG 2014 21:07

*File List* article.cls 2007/10/19 v1.4h Standard LaTeX document class size10.clo 2007/10/19 v1.4h Standard LaTeX file (size option) fontspec.sty 2014/06/21 v2.4a Font selection for XeLaTeX and LuaLaTeX expl3.sty 2014/07/20 v5241 L3 programming layer (loader) expl3-code.tex 2014/07/20 v5241 L3 programming layer etex.sty 1998/03/26 v2.0 eTeX basic definition package (PEB) l3unicode-data.def 2014/06/30 v5166 L3 Unicode data l3pdfmode.def 2014/07/18 v5232 L3 Experimental driver: PDF mode xparse.sty 2014/07/20 v5241 L3 Experimental document command parser luaotfload.sty 2014/08/10 v2.5-4 OpenType layout system luatexbase.sty 2013/05/11 v0.6 Resource management for the LuaTeX macro programme ifluatex.sty 2010/03/01 v1.3 Provides the ifluatex switch (HO) luatex.sty 2010/03/09 v0.4 LuaTeX basic definition package (HO) infwarerr.sty 2010/04/08 v1.3 Providing info/warning/error messages (HO) luatex-loader.sty 2010/03/09 v0.4 Lua module loader (HO) luatexbase-compat.sty 2011/05/24 v0.4 Compatibility tools for LuaTeX luatexbase-modutils.sty 2013/05/11 v0.6 Module utilities for LuaTeX luatexbase-loader.sty 2013/05/11 v0.6 Lua module loader for LuaTeX luatexbase-regs.sty 2011/05/24 v0.4 Registers allocation for LuaTeX luatexbase-attr.sty 2013/05/11 v0.6 Attributes allocation for LuaTeX luatexbase-cctb.sty 2013/05/11 v0.6 Catcodetable allocation for LuaTeX luatexbase-mcb.sty 2013/05/11 v0.6 Callback management for LuaTeX fontspec-patches.sty 2014/06/21 v2.4a Font selection for XeLaTeX and LuaLaTeX fontspec-luatex.sty 2014/06/21 v2.4a Font selection for XeLaTeX and LuaLaTeX fontenc.sty eu2enc.def 2010/05/27 v0.1h Experimental Unicode font encodings eu2lmr.fd 2009/10/30 v1.6 Font defs for Latin Modern 142

xunicode.sty 2011/09/09 v0.981 provides access to latin accents and many other eu2lmss.fd 2009/10/30 v1.6 Font defs for Latin Modern graphicx.sty 2014/04/25 v1.0g Enhanced LaTeX Graphics (DPC,SPQR) keyval.sty 2014/05/08 v1.15 key=value parser (DPC) graphics.sty 2009/02/05 v1.0o Standard LaTeX Graphics (DPC,SPQR) trig.sty 1999/03/16 v1.09 sin cos tan (DPC) graphics.cfg 2010/04/23 v1.9 graphics configuration of TeX Live pdftex.def 2011/05/27 v0.06d Graphics/color for pdfTeX ltxcmds.sty 2011/11/09 v1.22 LaTeX kernel commands for general use (HO) pdftexcmds.sty 2011/11/29 v0.20 Utility functions of pdfTeX for LuaTeX (HO) ifpdf.sty 2011/01/30 v2.3 Provides the ifpdf switch (HO) fontspec.cfg t3cmr.fd 2001/12/31 TIPA font definitions supp-pdf.mkii epstopdf-base.sty 2010/02/09 v2.5 Base part for package epstopdf grfext.sty 2010/08/19 v1.1 Manage graphics extensions (HO) kvdefinekeys.sty 2011/04/07 v1.3 Define keys (HO) kvoptions.sty 2011/06/30 v3.11 Key value format for package options (HO) kvsetkeys.sty 2012/04/25 v1.16 Key value parser (HO) etexcmds.sty 2011/02/16 v1.5 Avoid name clashes with e-TeX commands (HO) epstopdf-sys.cfg 2010/07/13 v1.3 Configuration of (r)epstopdf for TeX Live *********** When running MacTeX2013: Skip code block This is LuaTeX, Version beta-0.76.0-2013061817 (rev 4627) (format=lualatex 2014.3.31) 26 AUG 2014 21:09 *File List* article.cls size10.clo fontspec.sty expl3.sty l3names.sty l3bootstrap.sty luatex.sty infwarerr.sty

2007/10/19 2007/10/19 2013/05/20 2014/01/07 2014/01/04 2014/01/04 2010/03/09 2010/04/08

v1.4h Standard LaTeX document class v1.4h Standard LaTeX file (size option) v2.3c Font selection for XeLaTeX and LuaLaTeX v4646 L3 Experimental code bundle wrapper v4640 L3 Namespace for primitives v4640 L3 Experimental bootstrap code v0.4 LuaTeX basic definition package (HO) v1.3 Providing info/warning/error messages (HO) 143

ifluatex.sty 2010/03/01 v1.3 Provides the ifluatex switch (HO) etex.sty 1998/03/26 v2.0 eTeX basic definition package (PEB) luatex-loader.sty 2010/03/09 v0.4 Lua module loader (HO) pdftexcmds.sty 2011/11/29 v0.20 Utility functions of pdfTeX for LuaTeX (HO) ltxcmds.sty 2011/11/09 v1.22 LaTeX kernel commands for general use (HO) ifpdf.sty 2011/01/30 v2.3 Provides the ifpdf switch (HO) l3basics.sty 2014/01/04 v4642 L3 Basic definitions l3expan.sty 2014/01/04 v4642 L3 Argument expansion l3tl.sty 2013/12/27 v4625 L3 Token lists l3seq.sty 2013/12/14 v4623 L3 Sequences and stacks l3int.sty 2013/08/02 v4583 L3 Integers l3quark.sty 2013/12/14 v4623 L3 Quarks l3prg.sty 2014/01/04 v4642 L3 Control structures l3clist.sty 2013/07/28 v4581 L3 Comma separated lists l3token.sty 2013/08/25 v4587 L3 Experimental token manipulation l3prop.sty 2013/12/14 v4623 L3 Property lists l3msg.sty 2013/07/28 v4581 L3 Messages l3file.sty 2013/10/13 v4596 L3 File and I/O operations l3skip.sty 2013/07/28 v4581 L3 Dimensions and skips l3keys.sty 2013/12/08 v4614 L3 Experimental key-value interfaces l3fp.sty 2014/01/04 v4642 L3 Floating points l3box.sty 2013/07/28 v4581 L3 Experimental boxes l3coffins.sty 2013/12/14 v4624 L3 Coffin code layer l3color.sty 2012/08/29 v4156 L3 Experimental color support l3luatex.sty 2013/07/28 v4581 L3 Experimental LuaTeX-specific functions l3candidates.sty 2014/01/06 v4643 L3 Experimental additions to l3kernel xparse.sty 2013/12/31 v4634 L3 Experimental document command parser luaotfload.sty 2014/02/05 v2.4-3 OpenType layout system luatexbase.sty 2013/05/11 v0.6 Resource management for the LuaTeX macro programme luatexbase-compat.sty 2011/05/24 v0.4 Compatibility tools for LuaTeX luatexbase-modutils.sty 2013/05/11 v0.6 Module utilities for LuaTeX luatexbase-loader.sty 2013/05/11 v0.6 Lua module loader for LuaTeX luatexbase-regs.sty 2011/05/24 v0.4 Registers allocation for LuaTeX luatexbase-attr.sty 2013/05/11 v0.6 Attributes allocation for LuaTeX luatexbase-cctb.sty 2013/05/11 v0.6 Catcodetable allocation for LuaTeX luatexbase-mcb.sty 2013/05/11 v0.6 Callback management for LuaTeX fontspec-patches.sty 2013/05/20 v2.3c Font selection for XeLaTeX and LuaLaTeX fixltx2e.sty 2006/09/13 v1.1m fixes to LaTeX 144

fontspec-luatex.sty 2013/05/20 v2.3c Font selection for XeLaTeX and LuaLaTeX fontenc.sty eu2enc.def 2010/05/27 v0.1h Experimental Unicode font encodings eu2lmr.fd 2009/10/30 v1.6 Font defs for Latin Modern xunicode.sty 2011/09/09 v0.981 provides access to latin accents and many other eu2lmss.fd 2009/10/30 v1.6 Font defs for Latin Modern graphicx.sty 1999/02/16 v1.0f Enhanced LaTeX Graphics (DPC,SPQR) keyval.sty 1999/03/16 v1.13 key=value parser (DPC) graphics.sty 2009/02/05 v1.0o Standard LaTeX Graphics (DPC,SPQR) trig.sty 1999/03/16 v1.09 sin cos tan (DPC) graphics.cfg 2010/04/23 v1.9 graphics configuration of TeX Live pdftex.def 2011/05/27 v0.06d Graphics/color for pdfTeX fontspec.cfg t3cmr.fd 2001/12/31 TIPA font definitions supp-pdf.mkii epstopdf-base.sty 2010/02/09 v2.5 Base part for package epstopdf grfext.sty 2010/08/19 v1.1 Manage graphics extensions (HO) kvdefinekeys.sty 2011/04/07 v1.3 Define keys (HO) kvoptions.sty 2011/06/30 v3.11 Key value format for package options (HO) kvsetkeys.sty 2012/04/25 v1.16 Key value parser (HO) etexcmds.sty 2011/02/16 v1.5 Avoid name clashes with e-TeX commands (HO) epstopdf-sys.cfg 2010/07/13 v1.3 Configuration of (r)epstopdf for TeX Live *********** Tags: fonts (Prev Q) (Next Q), ligatures (Prev Q) (Next Q) User: mico

Answer by khaled-hosny Whether the font is packaged as TTC or not is irrelevant to the issue here. Most (all?) Latin fonts shipped by Apple use AAT layout tables, not OpenType. Older versions of LuaTeX partially supported AAT rather accidentally; as egreg pointed out in his comment above, FontForge that is used as base for the LuaTeX font loader maps some AAT features to equivalent OpenType ones, and that is why simple features like kerning or ligaturing appear to work. However, that code was hardly tested, caused crashes with many Mac OS X system fonts (that packages like luaotfload had to blacklist) and further145

more it outright broke fonts that include both AAT and OpenType layout table (many fonts from SIL, like Charis, do) as the mapped AAT features were duplicating the real OpenType ones, which confused the OpenType processor. Supporting AAT layout table for third parties is rather hard (due to incomplete or outright missing documentation) and I’m not aware if any working implementation other than Apple’s, but LuaTeX can’t use it as it wants to remain system independent. XeTeX of course uses Apple API to get AAT support, but at the price of producing different output when an AAT font is used between Mac OS X and other platforms (and it also meant we had to do quite some changes to port XeTeX to 64-bit Mac OS X systems when Apple deprecated the API that XeTeX was originally using and did not port it to its 64-bit architecture). So the solution is to avoid AAT fonts and use OpenType ones, or write your own feature files to emulate the missing OpenType support.

Tags: fonts (Prev Q) (Next Q), ligatures (Prev Q) (Next Q)

Q: How to enable ligatures for emdash/endash in LuaTeX ? Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q), ligatures (Prev Q) (Next Q) I cannot switch on ligatures for emdash (---) and endash (--) in LuaLaTeX. Here is my test file: Skip code block % !Mode:: "TeX:UTF-8" \documentclass{article} \usepackage{fontspec} \defaultfontfeatures{Ligatures=TeX} \setmainfont{Cambria} \setsansfont[Mapping=tex-text]{Calibri} \usepackage{ifluatex,ifxetex} 146

\begin{document} \ifxetex This is XeTeX \else\ifluatex This is LuaTeX \fi\fi \section{rmfamily} \rmfamily \begin{enumerate} \item by ligatures \verb|| \item «double quotes» by symbols \verb|«double quotes»| \item en--dash by ligatures \verb|en--dash| \item em---dash by ligatures \verb|em---dash| \item en–dash by symbol \verb|en–dash| \item em—dash by symbol \verb|em—dash| \end{enumerate} \section{sffamily} \sffamily \begin{enumerate} \item by ligatures \verb|| \item «double quotes» by symbols \verb|«double quotes»| \item en--dash by ligatures \verb|en--dash| \item em---dash by ligatures \verb|em---dash| \item en–dash by symbol \verb|en–dash| \item em—dash by symbol \verb|em—dash| \end{enumerate} \end{document} When it is compiled with XeLaTeX, \sffamily loaded with the obsolete option Mapping=tex-text \setsansfont[Mapping=tex-text]{Calibri} activates the ligatures --- and --, but in LuaTeX this options seemed to be equivalent to Ligatures=TeX, so that I don’t know how to restore default 147

(in LaTeX) behavior of these two ligatures. Is it bug or a feature, introduced in a recent version of the fontspec package? I’ve checked that the ligatures still work as expected under LuaTeX if I don’t set OTF fonts by the commands \setmainfont{Cambria} \setsansfont[Mapping=tex-text]{Calibri} Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q), ligatures (Prev Q) (Next Q) User: igor-kotelnikov

Answer by ulrike-fischer The TeX-ligatures in luatex are not a font property, they are ”faked” features implemented in the font loader code. The problem could be the bug in the luaotfload/context code reported some month ago: http://archive.contextgarden.net/message/20110310.181448.288f2a38.en. html I think it has been corrected in context but I doubt that the new code has already found its way in luaotfload. You can test the font directly (to exclude a fontspec problem and to test the both modes) Skip code block \documentclass{article} \usepackage{luaotfload} \begin{document} \font\test="Calibri:mode=node;+tlig" \font\testb="Calibri:mode=base;+tlig" \test -- --- abc \testb -- --- abc 148

\end{document}

Answer by alan-munn This is partially a property of the font, and not a problem with fontspec. XeLaTeX and LuaTeX implement the ligature replacement with different mechanisms. XeLaTeX uses a teckit mapping file, whereas LuaTeX uses luaotfload to do the conversion. The latter is somehow dependent on how the font actually implements certain characters. Changing the font to Linux Libertine O, for example, causes the ligatures to appear correctly. Update As noted by Ulrike Fischer, you can change this on a font-by-font basis for fonts that don’t work by specifying a value for the Renderer key when you load the font. There are two possible (relevant) values for this key in LuaLaTeX: Full (default) and Basic. Loading certain fonts with the Basic renderer will allow the ligatures. This will not work for all fonts, however. For more discussion, see the following thread on comp.text.tex: en-dash and em-dash in luatex. The following modified version of your document shows how the problem doesn’t arise with Linux Libertine O, and how it can be fixed for Cambria. (Calibri) works the same way. As Ulrike notes in her answer, a more robust fix will propagate to luaotfload at some point in the future. Skip code block % !Mode:: "TeX:UTF-8" \documentclass{article} \usepackage{fontspec} \defaultfontfeatures{Ligatures={TeX}} \setmainfont{Cambria} \setsansfont{Calibri} \usepackage{ifluatex,ifxetex} \usepackage{expl3} \begin{document}

149

\ifxetex This is XeTeX \else\ifluatex This is LuaTeX \fi\fi \section{Cambria} \begin{enumerate} \item by ligatures \verb|| \item «double quotes» by symbols \verb|«double quotes»| \item en--dash by ligatures \verb|en--dash| \item em---dash by ligatures \verb|em---dash| \item en–dash by symbol \verb|en–dash| \item em—dash by symbol \verb|em—dash| \end{enumerate} \section{Linux Libertine O} \fontspec{Linux Libertine O}\selectfont \begin{enumerate} \item by ligatures \verb|| \item «double quotes» by symbols \verb|«double quotes»| \item en--dash by ligatures \verb|en--dash| \item em---dash by ligatures \verb|em---dash| \item en–dash by symbol \verb|en–dash| \item em—dash by symbol \verb|em—dash| \end{enumerate} \section{Cambria + Basic Renderer} \fontspec[Renderer=Basic]{Cambria}\selectfont \begin{enumerate} \item by ligatures \verb|| \item «double quotes» by symbols \verb|«double quotes»| \item en--dash by ligatures \verb|en--dash| \item em---dash by ligatures \verb|em---dash| \item en–dash by symbol \verb|en–dash| \item em—dash by symbol \verb|em—dash| 150

\end{enumerate} \end{document}

Answer by keks-dose I can’t compete with the level of discussion between Ulrike and Alan. But thanks to the link provided by Alan, I found out how to get an en-dash with another of those Win-fonts: Corbel. I ran into the same problem two weeks ago and thanks to your help I know now how to handle it: \documentclass{article} \usepackage{fontspec} \setmainfont[Renderer=Basic,Ligatures=TeX]{Corbel} \begin{document} -- --- abc \end{document} I get the en-dash and the em-dash this way. Or did I miss something and this way to get dashes is obsolete?

Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q), ligatures (Prev Q) (Next Q)

Q: Specify different fonts for bold and italic with fontspec Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q) The main font I use for my LuaLaTeX document lacks bold and italic variants. I’d like to specify a different font for those variants using the fontspec package. Initially what I had in my preamble was this: \usepackage{fontspec} \setmainfont{GFS Elpis} 151

\setmonofont{Courier} and in order to use a different font for italics and bold, say Minion Pro, I tried putting the following line in the preamble just after the above shown lines: \fontspec[BoldFont={Minion Pro}, ItalicFont={Minion Pro}]{GFS Elpis} Unfortunately it doesn’t seem to have any effect. Italics and bold passages in the document remain in upright font. Could someone please help me with this issue? Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q) User: christosc

Answer by topskip You need to be specific if you declare the bold/italic/bold italic shapes, because fontspec does not automatically expand the font name: Skip code block \documentclass{article} \usepackage{fontspec} \setmainfont[ BoldFont={Minion Pro Bold}, ItalicFont={Minion Pro Italic}, BoldItalicFont={Minion Pro Bold Italic} ]{Linux Libertine O} \begin{document} normal \emph{italic}, \textbf{bold} and \textbf{\emph{bold italic}}. \end{document} Works fine with Minion/Linux Libertine O.

152

Edit: changed to \setmainfont instead of \fontspec so that there is a correct and good example. Thanks Ulrike for pointing this out.

Answer by ulrike-fischer Don’t use \fontspec. It is a command to change locally to another font and its settings will be lost if you switch fonts. If you want to setup the overall document font you should use the optional argument of \setmainfont. \documentclass{article} \usepackage{fontspec} \setmainfont[ItalicFont=Arial]{Linux Libertine O} \begin{document} abc {\itshape abc} \end{document}

Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q)

Q: How do I get a list of all available fonts for luaotfload? Tags: fonts (Prev Q) (Next Q) luaotfload uses an internal database that gets updated with mkluatexfontdb. So it knows about a lot of fonts installed on my computer. How can I query this database? Something like luatexfontdb --list-fonts-on-my-computer-that-are-in-your-database ? Tags: fonts (Prev Q) (Next Q) User: topskip

153

Answer by ulrike-fischer You could open the database in your editor. It is called otfl-names.lua and should be in one of your texmf-trees in \luatex-cache\generic\names. It is also not very difficult to make lists based on otfl-names.lua. E.g. Old version (Texlive 2013?) Skip code block \documentclass{article} \usepackage{luacode,luaotfload} \begin{document} \begin{luacode} myfonts=dofile(fonts.names.path.localdir..'/otfl-names.lua') for i,v in ipairs(myfonts.mappings) do tex.print(-2, v.familyname) tex.print(', ') tex.print(-2, v.fontname) tex.print('\\par') end \end{luacode} \end{document} Edit in may 2013: With a newer luaotfload (as the one in TL2013 (pretest) one should exchange the myfonts line by this one as the name of the database as changed: myfonts=dofile(fonts.names.path.path) Edit for Texlive 2014 I tried again in TL 2014 (june 2014). Now the names file is in a .luc and the access name has changed again. I also added some ”if exist code” to avoid error if a table entry doesn’t exist for a font: 154

Skip code block \documentclass{article} \usepackage{luacode} \usepackage{luaotfload} \begin{document} \begin{luacode} myfonts=dofile(fonts.names.path.index.luc) tex.sprint(fonts.names.path.index.luc) ---[[ for i,v in ipairs(myfonts.mappings) do if v.familyname then tex.print('\\par') tex.print(-2, v.familyname) end if v.fontname then tex.print(', ') tex.print(-2, v.fontname) end tex.print('\\par') end --]] \end{luacode} \end{document} Edit for TeXlive 2015 / MiKTeX in july 2015 The code do get the names file has to be adapted again. Now this here seems to work. Skip code block \documentclass{article} \usepackage{luacode} 155

\usepackage{luaotfload} \begin{document} \begin{luacode} myfonts=dofile(config.luaotfload.paths.index_path_luc) tex.sprint(config.luaotfload.paths.index_path_luc) ---[[ for i,v in ipairs(myfonts.mappings) do if v.familyname then tex.print('\\par') tex.print(-2, v.familyname) end if v.fontname then tex.print(', ') tex.print(-2, v.fontname) end tex.print('\\par') end --]] \end{luacode} \end{document}

Answer by topskip Based on Ulrike’s answer: Because I don’t want to create a TeX document every time I need the font list, here is a simple script for that: Skip code block #!/usr/bin/env texlua kpse.set_program_name("listluatexfonts") cachefile

= kpse.expand_var("$TEXMFVAR") 156

.. "/luatex-cache/generic/names/otfl-na

fontlist = dofile(cachefile) assert(fontlist,"Could not load font name database") local tmp = {} for _,font in ipairs(fontlist.mappings) do tmp[#tmp + 1] = font.fontname end table.sort(tmp) for _,fontname in ipairs(tmp) do print(fontname) end call it with ./listluatexfonts

Update: Replace the cachefile name for TexLive 2014: cachefile

= kpse.expand_var("$TEXMFVAR")

.. "/luatex-cache/generic/names/luaotfl

This one worked for me.

Tags: fonts (Prev Q) (Next Q)

Q: Lualatex: Font table with examples Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q) I wanted to create a table of the fonts on my machine with short examples of each. So I got the function below and tried to modify to print the font in its typeface. (LuaLatex) 157

Skip code block \documentclass[10pt,a4paper]{article} \usepackage{fontspec} \usepackage{luacode,luaotfload,luatextra} \usepackage[margin=18mm]{geometry} \begin{document} \begin{luacode} myfonts=dofile(fonts.names.path.localdir..'/otfl-names.lua') --tex.print('\\begin{verbatim}\\par') for i,v in ipairs(myfonts.mappings) do --tex.print('\\fontspec{' .. v.fontname .. '}') % most recent attempt --tex.print('\\setmainfont{' .. v.fontname .. '}') % first attempt tex.print(v.familyname..', '..v.fontname..'\\par') end --tex.print('\\endverbatim}\\par') \end{luacode} \end{document} Both of the commented lines does not work (fontspec or setmainfont). How should go about doing this with lua? Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q) User: louis

Answer by leo-liu This improves Caramdir’s answer to make the table easier to read: Skip code block \documentclass{article} \usepackage{fontspec} \setmainfont{Latin Modern Mono Light} \usepackage{luacode} 158

\usepackage[margin=18mm]{geometry} \parindent=0pt \usepackage{longtable,makecell} \renewcommand\arraystretch{2}

\begin{document} \begin{luacode} myfonts=dofile(fonts.names.path.localdir..'/otfl-names.lua') -- TeX Live 2012 or e -- myfonts=dofile(fonts.names.path.path) -- TeX Live 2013 teststring = "Sphinx of black quartz, judge my vow." tex.print("\\begin{longtable}{ll}\\hline") for i,v in ipairs(myfonts.mappings) do -- Stop early for testing purposes. if i > 20 then break end tex.print('\\makecell[l]{\\bfseries') tex.print(-2, v.familyname) tex.print('\\\\[-1ex] \\scriptsize') tex.print(-2, v.fontname) tex.print('} & \\LARGE\\fontspec{' .. v.fontname .. '}') tex.print(-2, teststring) tex.print('\\\\ \\hline') end tex.print("\\end{longtable}") \end{luacode} \end{document}

159

Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q)

Q: How to properly install and use a new font with LuaLaTeX? Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q) I have problems trying to get new fonts to work when compiling with LuaLaTeX. I’m working on Mac and use TexShop (with the MacTeX package). It goes like this: I downloaded for example the Cardo font; I installed the Cardo font (it now appears in the Font Book); I tried to compile a simple text that goes like this: Skip code block \documentclass[11pt]{book} 160

\usepackage[no-math]{fontspec} \usepackage[frenchb]{babel} \usepackage{amsmath} \usepackage{unicode-math} \setmainfont{Cardo} \begin{document} Hello world! \end{document} After compiling I obtained the following error message: Skip code block

luaotfload | Font names database loaded: /Users/juan/Library/texlive/2012/texmf -var/luatex-cache/generic/names/otfl-names.lua luaotfload | Updating the font names database: luaotfload | Scanning TEXMF fonts... luaotfload | Scanning OS fonts... luaotfload | Font names database saved: %s : /Users/juan/Library/texlive/2012/texmf-var/luatex-cache/generic/names/otfl-names !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! ./testBembo.tex:6: fontspec error: "font-not-found" ! ! The font "Cardo" cannot be found. ! ! See the fontspec documentation for further information. ! ! For immediate help type H . !............................................... l.6 \setmainfont{Cardo} ? Process aborted • then I checked the otfl-names.lua and Cardo was missing;

161

• I then added the Cardo folder font to this folder: /usr/local/texlive/2012/texmf-dist/fonts/ • I executed the mkluatexfontdb -vvv command in a terminal; • I re-checked the otfl-names.lua and Cardo was finally there; So I naturally tried to compile the text again after resetting the computer and (as you might guess by now) I obtained (again!) the following error message: Skip code block luaotfload | Font names database loaded: /Users/juan/Library/texlive/2012/texmf -var/luatex-cache/generic/names/otfl-names.lua luaotfload | Updating the font names database: luaotfload | Scanning TEXMF fonts... luaotfload | Scanning OS fonts... luaotfload | Font names database saved: %s : /Users/juan/Library/texlive/2012/texmf-var/luatex-cache/generic/names/otfl-na mes.lua !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! ./testBembo.tex:6: fontspec error: "font-not-found" ! ! The font "Cardo" cannot be found. ! ! See the fontspec documentation for further information. ! ! For immediate help type H . !............................................... l.6 \setmainfont{Cardo} ? Process aborted The thing is driving me crazy! I migrated to LuaLaTeX only because I was promised to be able to use almost any font with it. What am I doing wrong? 162

Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q) User: jrojasqu

Answer by void-pointer I came across the same problem as you when I first tried to use XeTeX. If you want fontspec to automatically find the path to the font and load it for you, then you need to have the font installed as a system font. On OS X, you can do this by navigating to Font Book -> Preferences and changing the ”Default Installation Location” from ”User” to ”Computer”. This should allow you to use the \setmainfont{} command without any prior configuration. For Linux distributions, you should consult the documentation for your desktop environment. If you do not want to modify the set of system fonts, or you are working on a project in which you would like all of your resources to exist in one directory structure, you can specify the path to the font explicitly. For example, if you install Cardo as a user font (which is the default behavior on OS X), the font files should be copied to ~/Library/Fonts. Assuming that regular version of the font is supplied in a file called Cardo.ttf, you can load the font as follows. (Be sure to change to your username). \setmainfont[ Path Extension Ligatures ]{Cardo}

= /Users//Library/Fonts/, = .ttf, = TeX

If you have bold, italic, and bold-italic variants of your font, you can use them by adding a few extra lines. In this example, I’m using a font called Crimson, which is supplied in the OTF format. The regular version of the font is called Crimson-Roman.otf; the bold, italic, and bold-italic variants are called Crimson-Bold.otf, Crimson-Italic.otf, and Crimson-BoldItalic.otf, respectively. \setmainfont[ Path Extension Ligatures

= /Users//Library/Fonts/, = .otf, = TeX, 163

BoldFont = Crimson-Bold, ItalicFont = Crimson-Italic, BoldItalicFont = Crimson-BoldItalic ]{Crimson-Roman} All of this information is available in the fontspec manual. Edit Since you still seem to be experiencing problems using other fonts with LuaTeX, I thought that posting my procedure step-by-step might help in identifying the problem. My texlive distribution is obtained from MacPorts; running lualatex -v returns the following: This is LuaTeX, Version beta-0.70.2-2013011221 (TeX Live 2012/MacPorts 2012_5). • I downloaded the Baskerville font from this link. The font files are called LibreBaskerville-Regular.otf, LibreBaskerville-Bold.otf, and LibreBaskerville-Italic.otf. • I installed the fonts as user fonts by double clicking the font files in Finder. • I created a file called baskerville.tex with the following contents. (I replaced my username by ). Skip code block \documentclass[11pt,a4paper]{article} \usepackage{fontspec} \setmainfont[ Path = /Users//Library/Fonts/, Extension = .otf, Ligatures = TeX, BoldFont = LibreBaskerville-Bold, ItalicFont = LibreBaskerville-Italic ]{LibreBaskerville-Regular} \begin{document} This is a test. \end{document} • I compiled the file with the command lualatex baskerville.tex. 164

Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q)

Q: Conflict between microtype, LuaLaTeX, and otf fonts when typesetting material in small-caps Tags: fonts (Prev Q) (Next Q), microtype (Prev Q) (Next Q) I’m using the microtype package (microtype beta 2.5 build 08) to modify my document and I’d like to retain its functionality across all font shapes with the exception of small-caps (\scshape). How do I do this? I’m asking this because microtype is not preserving the (\scshape) of section names listed in my table of contents whenever I use otf fonts (adobe caslon pro, adobe garamond pro, etc) that are loaded via fontspec. Instead, it’s changing them to regular text. Whenever I don’t load micro type, the text reverts to scshape. I’d like to keep the (\scshape) of the section names intact while using microtype without having to abandon use of the aforementioned otf fonts.

Here is what my toc looks like when microtype is enabled:

Here it is with microtype disabled: I’m building my documents with Lualatex to facilitate loading of otf fonts and their usage with microtype. I notice this issue doesn’t occur when using normal latex fonts. Here is my code: Skip code block \documentclass[dotinlabels,nohyper]{tufte-book} 165

\usepackage{amsthm} \usepackage{amsmath} \usepackage{amssymb} \usepackage{fontspec} \setmainfont[Ligatures=TeX]{Minion Pro} \usepackage{fancyhdr} \pagestyle{fancy} \usepackage[unicode=true, bookmarks=true,bookmarksnumbered=true,bookmarksopen=false, breaklinks=false,pdfborder={0 0 1},backref=false,colorlinks=true] {hyperref} \usepackage{titletoc} \usepackage{titlesec} \usepackage{tocloft} % If you do not load micro type below, small caps are preserved. \usepackage[activate={true,nocompatibility},final,tracking=true,factor=1100,stretc \hypersetup{linktocpage=true} \setcounter{secnumdepth}{1} \setcounter{tocdepth}{2} %formatting for toc entries \renewcommand{\cftsecfont}{\large\scshape\MakeLowercase} \renewcommand{\cfttoctitlefont}{\scshape\MakeUppercase} \renewcommand{\cftsecdotsep}{\cftdotsep} \renewcommand{\cftsecpagefont}{\scshape} % \titleformat{\section}{\titlerule\vspace{.8ex}% \Large\bfseries}{\Large\thesection.}{.5em}{} \renewcommand{\sectionmark}[1]{% \markboth{}{\thesection.\ #1}} \newcommand{\hsp}{\hspace{20pt}}

166

%Chapter title Formatting \definecolor{gray75}{gray}{0.75} \titlespacing{\chapter}{0pt}{*0}{*5} \titleformat{\chapter}[hang]{\Huge\bfseries}{\thechapter\hsp\textcolor{gray75}{|}\ % \begin{document} \fancyhf{} % clear all header/footer fields \fancyhead[RO]{\scshape\normalsize\MakeLowercase{\rightmark}} \fancyfoot[R]{\thepage} \tableofcontents{} \chapter{Preliminaries} \section{Mathematical Induction} text goes here... \newpage{} test \newpage{} test \end{document} Tags: fonts (Prev Q) (Next Q), microtype (Prev Q) (Next Q) User: black-milk

Answer by robert The reason why the small caps font is changed to the regular one is that microtype’s tracking feature does not work flawlessly with lualatex. At the moment, the only fix (apart from not using tracking altogether) is to load the font with Renderer=Basic instead of (the default) Full: \setmainfont[Ligatures=TeX,Renderer=Basic]{Minion Pro} Unfortunately, this may have side effects, as switching to the basic renderer means losing some OpenType features. In the case of small caps, for example, less kerning pairs will be defined. While more problems may still be uncovered, there is also the one or the other bug with Renderer=Full. 167

[I was going to suggest to restrict this to the small caps font: \setmainfont[Ligatures=TeX,SmallCapsFeatures={Renderer=Basic}]{Minion Pro} but this does not work.]

Answer by qrrbrbirlbel The microtype package offers to define sets of fonts. There is even a predefined set name called smallcaps, though it is not of much use as one can apparently only include sets for activated micro-typography. Excluding small caps would be the same like including everything else. Code Skip code block \documentclass{article} \usepackage[ protrusion=false, expansion=false, ]{microtype} \DeclareMicrotypeSet{non Small Caps}{shape={it*,up*,sl*}} \microtypesetup{activate=non Small Caps} \usepackage{lipsum} \begin{document} {\scshape\lipsum} {\itshape\lipsum} \end{document} But as I understand it, this would overwrite every default settings made by microtype; therefore it seems easier to just patch \scshape. Code \documentclass{article} \usepackage{microtype} 168

\expandafter\def\expandafter\scshape\expandafter{\scshape\microtypesetup{activate= \usepackage{lipsum} \begin{document} {\scshape\lipsum} {\itshape\lipsum} \end{document}

Answer by mico I’m not sure which aspects of microtype you wish to disable when it comes to dealing with small-caps fonts. I’ll assume that it’s the tracking (inter-letter and inter-word spacing) that you want to disable. (Somehow, I don’t think you want to disable character protrusion optimization for small-caps glyphs.) To disable microtype’s action with regard to tracking for small-caps characters only, you could issue the following command (after loading the microtype package, obviously): \SetTracking[spacing = {0,0,0}]{encoding=*,shape=sc}{0}

Tags: fonts (Prev Q) (Next Q), microtype (Prev Q) (Next Q)

Q: How to set-up LuaTeX, Microtype, with Minion Pro, Myriad Pro Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q), microtype (Prev Q) (Next Q) Since recently I am using LuaLaTeX with the most recent beta version of Microtype, along with the fonts Minion Pro and Myriad Pro. In the manual of Microtype it says: Currently, this package provides protrusion settings for [...] Adobe Garamond (cf. table 3 on page 21)

169

Currently, I just include the fonts like this (with some other font definitions for headings etc. settings left out here): \defaultfontfeatures{Ligatures=TeX, Scale=MatchLowercase}

\setmainfont[SmallCapsFeatures={LetterSpace=6}, Numbers={Proportional,OldStyle}]{M \setsansfont[LetterSpace=3, Numbers={Proportional,OldStyle}]{Myriad Pro} But this way I still get the following message from Microtype: Package microtype Warning: Loading generic settings for font family `MinionPro' How can I load the correct settings? Also, is there a way to avoid all these warnings I get for fonts that are not supported, and Microtype just loads the generic settings? Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q), microtype (Prev Q) (Next Q) User: ingo

Answer by topskip With the current microtype from TeXlive 2011, you can do the following: Skip code block \documentclass{article} \usepackage{fontspec,microtype} \defaultfontfeatures{Ligatures=TeX, Scale=MatchLowercase}

\setmainfont[SmallCapsFeatures={LetterSpace=6}, Numbers={Proportional,OldStyle}]{M \setsansfont[LetterSpace=3, Numbers={Proportional,OldStyle}]{Myriad Pro}

\SetProtrusion [ name = min-eu2 ] { encoding = {EU2}, family = MinionPro {

}

170

{,} = { - = {

,500}, ,500}

}

\begin{document} \hsize 3in

When, while the lovely valley teems with vapour around me, and the meridian sun st foliage of my trees, and but a few stray gleams steal into the inner sanctuary, I trickling stream; and, as I lie close to the earth, a thousand unknown plants are \end{document} LuaTeX with fontspec uses EU2 encoding internally, so all you need to do is the regular microtype setup with encoding EU2.

Answer by alabay Hm, I also use Minion Pro and Myriad Pro … this way: Skip code block

\documentclass[12pt]{scrbook} \usepackage[english]{babel} \usepackage{blindtext} \pdfprotrudechars=2 \pdfadjustspacing=2 \usepackage{fontspec} \defaultfontfeatures{Ligatures=TeX} \newfontfeature{Microtype}{protrusion=default;expansion=default;} \setmainfont[Microtype,Ligatures=TeX,Numbers=OldStyle]{Minion Pro} \setsansfont[Microtype,Scale=MatchLowercase,Ligatures=TeX,Numbers=OldStyle]{Myriad \begin{document} \blindtext[5] \end{document} Than TeX Live 2010 and now 2011.

171

Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q), microtype (Prev Q) (Next Q)

Q: LuaLaTeX: use or don’t use classical font packages? Tags: fonts (Prev Q) (Next Q), packages (Next Q) In the lualatex-doc I am reading under ”switching from LaTeX to LuaLaTeX”: 1. Don’t load inputenc, just encode your source in UTF-8. 2. Don’t load fontenc, but load fontspec. 3. Don’t use any package that changes the fonts, but use fontspec’s commands instead. Consider the following example: % !Mode:: "TeX:UTF-8" \documentclass[paper=a4]{scrartcl} \usepackage{fontspec} \usepackage{lmodern} \renewcommand{\familydefault}{\sfdefault} \begin{document} Hellöö! ßßäü \end{document} It compiles perfectly fine and looks as desired with lualatex from TeXLive 2012. It is in agreement with points (1) and (2) from the list above. However, I am wondering: • Doesn’t \usepackage{lmodern} violate point (3) from above? If yes: • What would be the LuaLaTeX way of using lmodern? • Why does it work then? In which cases is this expected to break? I just took lmodern as an example, the question applies to all such kinds of font packages.

172

Tags: fonts (Prev Q) (Next Q), packages (Next Q) User: jan-philip-gehrcke

Answer by ulrike-fischer Your example works as there exists suitable font definitions files for the ”lmr” and the ”lmss” families for the EU2 font encoding in the euenc package. (If you look in the log-file you will see that a eu2lmss.fd is loaded). If you would replace lmodern by e.g. times it would no longer work. You would see in the log-file a warning: LaTeX Font Info:

No file EU2phv.fd. on input line 14.

LaTeX Font Warning: Font shape `EU2/phv/m/n' undefined (Font) using `EU2/lmr/m/n' instead on input line 14. And the document wouldn’t use helvet but the fallback lmr. To be able to use the helvet font you would have to switch the fontencoding to an encoding for which font definitions for helvet exists, e.g. T1-encoding. But with this encoding you will no longer be able to input non-ascii-chars directly: \documentclass[paper=a4]{scrartcl} \usepackage{fontspec} \usepackage{times} \renewcommand{\familydefault}{\sfdefault} \begin{document} ¼½¾ Hellöö! ßßäü % this gives helvet, but some chars are wrong: \fontencoding{T1}\selectfont ¼½¾ Hellöö! ßßäü \ss \end{document}

Tags: fonts (Prev Q) (Next Q), packages (Next Q)

173

Q: TeX accents do not seem to work with fontspec and xe/lua/latex Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q), xetex (Prev Q) (Next Q) I am using Minion Pro as mainfont and it does not have in its glyph table the character U+1E47 Latin small letter with dot below which I need only once in my document. Rather than change to another font, I thought that I would generate it using \d{n}. I give below a minimal file illustrating the problem: \documentclass{minimal} \usepackage{fontspec} \defaultfontfeatures{Ligatures=TeX} \setmainfont{Minion Pro} % Comment out optionally \begin{document} U+1E47 Latin small letter with dot below: \d{n} U+0101 Latin small letter a with macron: \={a} \end{document} I do not get the desired letter n with dot below although the a with macron exists in the font and is available. Commenting out \usepackage{fontspec} gives the desired output with CMR as default font. The behaviour is the same with xelatex and lualatex although the former indicates the missing letter with a crossed box. I believe that with the Ligatures=TeX setting, I should be able to get missing letters using TeX accents. I do not think I need to load the xunicode package as it is already loaded by fontspec. Can someone tell me what a I am doing wrong, please? Thank you. Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q), xetex (Prev Q) (Next Q) User: chandra

174

Answer by egreg The ”standard way” would be to say \UndeclareUTFcomposite[\UTFencname]{x1E47}{\d}{n} in order to use the combining character instead of the missing character at U+1E47, but unfortunately Minion Pro has nothing in slot U+0323 (COMBINING DOT BELOW). We need to go the hard way: write the following in the preamble \UndeclareUTFcomposite[\UTFencname]{x1E47}{\d}{n} \makeatletter \renewcommand{\d}[1] {\[email protected] \[email protected]{\relax#1\crcr\hidewidth\[email protected]@ft{-1ex}.\hidewidth}\egroup} \makeatother so that you’ll use the standard definition for \d. If other characters of that sort are needed, look in xunicode.sty for their definition; it starts with \DeclareUTFcomposite, it’s sufficient to copy the line in your preamble and to change \Declare... into \Undeclare.... Let’s look also at the ”line below”, which is again missing in Minion Pro. Here’s a similar way to cope with the case, using the macron (U+00AF) for emulating the line below: Skip code block \documentclass{article} \usepackage{fontspec,newunicodechar} \defaultfontfeatures{Ligatures=TeX} \setmainfont{Minion Pro} % Comment out optionally \UndeclareUTFcomposite[\UTFencname]{x1E47}{\d}{n} \UndeclareUTFcomposite[\UTFencname]{x1E49}{\b}{n} \makeatletter \let\d\relax \DeclareRobustCommand{\d}[1] {\[email protected] 175

\[email protected]{\relax#1\crcr\hidewidth\[email protected]@ft{-1ex}.\hidewidth}\egroup} \let\b\relax \DeclareRobustCommand{\b}[1] {\[email protected]\[email protected]{\relax#1\crcr\hidewidth\[email protected]@ft{-3ex}% \vbox to.2ex{\hbox{\char"AF}\vss}\hidewidth}\egroup} \makeatother \newunicodechar{ṇ}{\d{n}} \newunicodechar{ṉ}{\b{n}} \begin{document} U+1E47 Latin small letter n with dot below: \d{n}ṇ U+1E49 Latin small letter n with line below: \b{n}ṉ U+0101 Latin small letter a with macron: \={a}ā \end{document} It’s perhaps better to declare \b and \d as robust commands. Moreover, with newunicodechar we can also input the characters directly.

Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q), xetex (Prev Q) (Next Q)

Q: Bembo, Bembo Book or Garamond Premier Pro? And how to exploit all their features with LuaLaTex? Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q)

176

I am allowed to use one of these fonts (or the three of them if I want) to edit a document. Here is the list of the Bembo fonts I have : Skip code block Bembo-Bold.otf Bembo-BoldExpert.otf Bembo-BoldItalic.otf Bembo-BoldItalicExpert.otf Bembo-BoldItalicOsF.otf Bembo-BoldOsF.otf Bembo-Expert.otf Bembo-ExtraBold.otf Bembo-ExtraBoldExpert.otf Bembo-ExtraBoldItalic.otf Bembo-ExtraBoldItalicExpert.otf Bembo-ExtraBoldItalicOsF.otf

Bembo-ExtraBoldOsF.otf Bembo-Italic.otf Bembo-ItalicExpert.otf Bembo-ItalicOsF.otf Bembo-SC.otf Bembo-Semibold.otf Bembo-SemiboldExpert.otf Bembo-SemiboldItalic.otf Bembo-SemiboldItalicExpert.otf Bembo-SemiboldItalicOsF.otf Bembo-SemiboldOsF.otf Bembo.otf

here is the list of the Bembo Book fonts I have : BemboBookMTPro-Bold.otf BemboBookMTPro-BoldIt.otf

BemboBookMTPro-Italic.otf BemboBookMTPro-Regular.otf

and here is the list of the Garamond Premier Pro fonts available : Skip code block GaramondPremrPro-Bd.otf GaramondPremrPro-BdCapt.otf GaramondPremrPro-BdDisp.otf GaramondPremrPro-BdIt.otf GaramondPremrPro-BdItCapt.otf GaramondPremrPro-BdItDisp.otf GaramondPremrPro-BdItSubh.otf GaramondPremrPro-BdSubh.otf GaramondPremrPro-Capt.otf GaramondPremrPro-Disp.otf GaramondPremrPro-It.otf GaramondPremrPro-ItCapt.otf GaramondPremrPro-ItDisp.otf

GaramondPremrPro-MedCapt.otf GaramondPremrPro-MedDisp.otf GaramondPremrPro-MedIt.otf GaramondPremrPro-MedItCapt.otf GaramondPremrPro-MedItDisp.otf GaramondPremrPro-MedItSubh.otf GaramondPremrPro-MedSubh.otf GaramondPremrPro-Smbd.otf GaramondPremrPro-SmbdCapt.otf GaramondPremrPro-SmbdDisp.otf GaramondPremrPro-SmbdIt.otf GaramondPremrPro-SmbdItCapt.otf GaramondPremrPro-SmbdItDisp.otf 177

GaramondPremrPro-ItSubh.otf GaramondPremrPro-LtDisp.otf GaramondPremrPro-LtItDisp.otf GaramondPremrPro-Med.otf

GaramondPremrPro-SmbdItSubh.otf GaramondPremrPro-SmbdSubh.otf GaramondPremrPro-Subh.otf GaramondPremrPro.otf

Choosing between them is becoming nearly impossible to me because I really like the three of them. So to make my choice, I decided to base it on technicalities. • First question : Which one would you recommend and why? • Second question : Which one do you believe is the most comfortable for reading when printed? • Third question : Which one offers the the biggest amount of exploitable features when using LuaLaTex? • Fourth question : How do I exploit all of their features (swashes, small caps, small italic caps, glyphs I can’t type with the keyboard, etc.)? I ask the fourth question because my university bought them all and they cost an arm & a leg, so I really intend to get the most out of them. For example I can’t get the swashes to work (or any other feature in fact). For swashes I tried this : Skip code block \documentclass{article} \usepackage{fontspec} \newopentypefeature{Contextuals}{NoAlternate}{-calt} \defaultfontfeatures{Kerning=Uppercase,Mapping=tex-text,} \setmainfont{Garamond Premier Pro} \begin{document} Quad Qed \addfontfeatures{Contextuals=NoAlternate} Quad Qed \end{document} But the swash does not work. I also tried to set the options like this : \documentclass{article} \usepackage{fontspec} \setmainfont[Contextuals=Swash]{Garamond Premier Pro} 178

\begin{document} Quad Qed \end{document} But then the console says this : ************************************************* * fontspec warning: "icu-feature-not-exist-in-font" * * OpenType feature 'Contextuals=Swash' (+cswh) not available for font * 'GaramondPremrPro' with script 'Latin' and language 'Default'. ************************************************* Is there something wrong with this font? Also, my document contains a big amount of equations, do you have any advice on the math fonts? Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q) User: jrojasqu

Answer by nils-l There’s a technical and an aesthetical side to most of the questions you’re asking: 1.1) For your purposes, a tech report with maths etc.: none of them. You’ll have trouble finding math supplements that go well with any of these fonts. Yes, there are packages that set out to provide math symbols supposed to look good with »Garamond«, but the huge number fonts with »Garamond« in their names vary considerably in terms of their look. A package providing TeX support for a Garamond will most likely be geared towards one of the free Garamond versions, such as URW’s (an early digitization of the Stempel version from the 1920s). It may be, but IMHO will rather not be suitable for AGPPro ...which is a highly idiosyncratic rendition of C. Garamond’s typefaces. What I suggest, from a technical/practical perspective is: choose a font that comes with sufficient math support out of the box, or one where you’re certain that suitable high-quality math support is available (such as MinionPro).

179

1.2) The three fonts you list are designed as rather faithful renditions of faces created 500 years ago (unlike e.g. TNR, which doesn’t have one specific model). They’re explicitly citing the aesthetics of that time -- this is the case with the two (very different) Bembo renditions, and it is even more the case with AGPPro. Both AGPPro and BBook are, in addition, designed to reproduce the look of letterpress printing to some degree. None of this is a problem per se, but typography is not art for art’s sake, but rather halfway between an art and a craft IMHO. So you have to make sure your typeface choice is appropriate within the context of your product. Questions like: »what’s the message brought across by a document that tries to look like it’s been printed in 1540?«, or »what kind of aesthetics is my audience used to?« are the ones you should consider here. 2) The old (1990s) digital renditions of Bembo were infamous for their thin and anemic look in print. They were horrible digitizations of horrible phototype-izations of a typeface that was, and remains, sublime in hot metal. These digitizations were shunned by most decent typographers, which I understand perfectly well, having compared books set in Bembo from the three typographic eras side by side. Now all this was supposed to change with Bembo Book. It was advertised as a font that would bring back the look of that hot metal legend. It didn’t. It’s about eight (?) years ago IIRC, that MT released BBook, but it still hasn’t caught on. Yes, the strokes are sturdier, the thinness is gone, but like its predecessors it lacks any sparkle, and, unsuprisingly, comes nowhere near the original that it’s (and has to be) measured by. So that’s a strict NO for your Bembo Std, and an if-need-be for Bembo Book, in terms of aesthetics and reading comfort. AGPPro... one guideline (I’m not saying ›rule‹) is that typography is best when it’s invisible. Reading comfort is reduced the more the typography (e.g., the typeface) is making the reader aware of its presence. The more you deviate from what readers are used to, or what just »works«, the more this will be the case. Try setting your text ragged-left (!), for example. For typefaces, the equivalent of a left rag would be choosing a particularly idiosyncratic typeface, i.e. one that draws attention to itself (which is what it all boils down to). Within the range of text faces currently on the market, AGPPro is clearly on the idiosyncratic side of the spectrum (which is why it’s hardly being used for serious book production). 180

The other side of that spectrum we might call »inconspicuous« ones and put, say, TNR or Minion there. The degree of perceived idiosyncracy will of course be dependent on what your readers are used to. Computer Modern will look odd to people from the humanities, but will make maths people feel at home. In Germany, Stempel Garamond (unlike AGPPro) is one of the most inconspicuous choices simply because literally generations have been socialized with it in school, while, conversely, New Century Schoolbook (and classicist or »didone« or »modern« faces in general) look weird to most people over here. I see I need to keep it more concise: 3) what features do you need? I suggest you consider that question first, and then see what fonts might offer it. At the moment, I’m having trouble understanding the role you have in mind for, say, swashes in a tech report ;) 4) as you’re already using LuaLaTeX, you already got the most appropriate tool available in the TeX world. ConTeXt might be another good choice. But choose wisely, as jumping ships between the two might be difficult once your project has taken up speed. Swashes -- I’m afraid you’re trying to do something that, by its very nature, won’t work. A swash is usually defined as a calligraphy-style embellishment, mainly for capital letters. The »calligraphy« part is important here, as it’s the italic cuts of a typeface that make reference to handwriting. And it is, traditionally, only here that you’ll find swashes. So unless AGPPro’s specimen sheet says otherwise, there’ll be no upright swashes in AGPPro. This, on the other hand, works fine (in LuaLaTeX): \documentclass{article} \usepackage{fontspec} \setmainfont[Contextuals=Swash]{Minion Pro} \begin{document} \itshape Quad Qed Jawohl \end{document}

Answer by silke Which one would you recommend and why? 181

This is, of course, a matter of taste. Personally I would use Garamond Premier Pro. Which one do you believe is the most comfortable for reading when printed? This is, again, a matter of taste. I think both Bembo Book and Garamond Premier Pro will do fine. They are both well-crafted fonts. Which one offers the the biggest amount of exploitable features when using LuaLaTex? I’ve made a quick comparison of all the OpenType features the fonts support: Skip code block Feat. Bembo BemboBk aalt x x c2sc x x calt x x case x x cpsp x dlig x x dnom x x fina x frac x x hist x kern x x x liga x x lnum x x numr x x onum x x ordn x x ornm x pnum x x salt x x sinf x size x smcp x x ss01 x ss02 x

Garamond PP Description Access All Alternates Small Capitals From Capitals Contextual Alternates Case-Sensitive Forms Capital Spacing Discretionary Ligatures Denominators Terminal Forms Fractions Historical Forms Kerning Standard Ligatures Lining Figures Numerators Oldstyle Figures Ordinals Ornaments Proportional Figures Stylistic Alternates Scientific Inferiors Optical Size Small Capitals Stylistic Set 1 Stylistic Set 2 182

ss03 sups tnum zero

x x

x x x x

Stylistic Set 3 Superscript Tabular Figures Slashed Zero

It’s clear Garamond Premier Pro has more OpenType features you can use than either Bembo or Bembo Book. (this is based on the fonts I have here, the features present in your fonts may differ) How do I exploit all of their features (swashes, small caps, small italic caps, glyphs I can’t type with the keyboard, etc.)? You can exploit all OpenType features with fontspec. I really recommend reading the documentation. A MWE with the most important bits: Skip code block \documentclass{article} \usepackage{fontspec} \defaultfontfeatures { Ligatures = TeX , Numbers = OldStyle , %Path = /Path/To/Fonts , % Use when fonts aren't installed on your system Extension = .otf } \setmainfont [ UprightFont = * , ItalicFont = *-It , BoldFont = *-Bd , BoldItalicFont = *-BdIt ] {GaramondPremrPro}

\newcommand*\specimen{The Quick brown fox jumps over the sleazy dog, 0123456789.\\ \begin{document} \noindent 183

\specimen \textit{\specimen} \textsc{\specimen} \textsc{\itshape\specimen} \textbf{\specimen} \textbf{\itshape\specimen} \textbf{\scshape\specimen} \textbf{\scshape\itshape\specimen} \noindent Alternates, etc: \\ {\addfontfeature{Style = Historic}\specimen} {\addfontfeature{Style = Alternate}\specimen} \end{document}

Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q)

Q: Can’t generate ligatures with LuaLaTeX under MacTeX2014 and MacTeX2015 when using certain fonts Tags: fonts (Prev Q) (Next Q), opentype (Prev Q) (Next Q), ligatures (Prev Q) (Next Q) (Remark: This question was posted originally when the big news, TeX-wise, was the impending transition from TeXLive2013 to TeXLive2014. Since the issue identified in this posting persists in TeXLive2015, I’ve chosen to update the posting’s title accordingly.) Consider the following MWE: % !TEX TS-program = lualatex \documentclass{article} \listfiles \usepackage{fontspec} \setmainfont[Ligatures={Common,Rare}]{Hoefler Text} \begin{document} ff fi fl ffi ffl fj ct st 184

\end{document} When compiling this program on my system (MacOSX 10.9.2, MacTeX2013, luatex 0.76.0) under LuaLaTeX, I get the expected result, i.e., all ligatures are generated correctly:

However, if I switch to TeXLive2014 (currently in advanced beta), which employs luatex 0.79.1, no ligatures are created:

This problem doesn’t arise under TeXLive2014 if I (i) compile the MWE under XeLaTeX instead of LuaLaTeX or (ii) use a different font, say, Adobe Garamond Pro, Garamond Premier Pro, or Latin Modern Roman. (Of course, the latter font doesn’t feature ligatures for fj, ct, and st, but ligatures are generated for ff, fi, fl, ffi, and ffl.) Is there a setting that needs to be tweaked to enable ligatures when using Hoefler Text? For completeness, here are the files used by the LuaLaTeX/TeXLive2014 run: Skip code block LuaTeX, Version beta-0.79.1 (TeX Live 2014/dev) (rev 4971) *File List* article.cls size10.clo fontspec.sty expl3.sty

2007/10/19 2007/10/19 2013/05/20 2014/01/07

v1.4h v1.4h v2.3c v4646

185

(format=lualatex 2014.

Standard LaTeX document class Standard LaTeX file (size option) Font selection for XeLaTeX and LuaLaTeX L3 Experimental code bundle wrapper

l3names.sty 2014/01/04 v4640 L3 Namespace for primitives l3bootstrap.sty 2014/01/04 v4640 L3 Experimental bootstrap code luatex.sty 2010/03/09 v0.4 LuaTeX basic definition package (HO) infwarerr.sty 2010/04/08 v1.3 Providing info/warning/error messages (HO) ifluatex.sty 2010/03/01 v1.3 Provides the ifluatex switch (HO) etex.sty 1998/03/26 v2.0 eTeX basic definition package (PEB) luatex-loader.sty 2010/03/09 v0.4 Lua module loader (HO) pdftexcmds.sty 2011/11/29 v0.20 Utility functions of pdfTeX for LuaTeX (HO) ltxcmds.sty 2011/11/09 v1.22 LaTeX kernel commands for general use (HO) ifpdf.sty 2011/01/30 v2.3 Provides the ifpdf switch (HO) l3basics.sty 2014/01/04 v4642 L3 Basic definitions l3expan.sty 2014/01/04 v4642 L3 Argument expansion l3tl.sty 2013/12/27 v4625 L3 Token lists l3seq.sty 2013/12/14 v4623 L3 Sequences and stacks l3int.sty 2013/08/02 v4583 L3 Integers l3quark.sty 2013/12/14 v4623 L3 Quarks l3prg.sty 2014/01/04 v4642 L3 Control structures l3clist.sty 2013/07/28 v4581 L3 Comma separated lists l3token.sty 2013/08/25 v4587 L3 Experimental token manipulation l3prop.sty 2013/12/14 v4623 L3 Property lists l3msg.sty 2013/07/28 v4581 L3 Messages l3file.sty 2013/10/13 v4596 L3 File and I/O operations l3skip.sty 2013/07/28 v4581 L3 Dimensions and skips l3keys.sty 2013/12/08 v4614 L3 Experimental key-value interfaces l3fp.sty 2014/01/04 v4642 L3 Floating points l3box.sty 2013/07/28 v4581 L3 Experimental boxes l3coffins.sty 2013/12/14 v4624 L3 Coffin code layer l3color.sty 2012/08/29 v4156 L3 Experimental color support l3luatex.sty 2013/07/28 v4581 L3 Experimental LuaTeX-specific functions l3candidates.sty 2014/01/06 v4643 L3 Experimental additions to l3kernel xparse.sty 2013/12/31 v4634 L3 Experimental document command parser luaotfload.sty 2014/02/05 v2.4-3 OpenType layout system luatexbase.sty 2013/05/11 v0.6 Resource management for the LuaTeX macro progr ammer luatexbase-compat.sty 2011/05/24 v0.4 Compatibility tools for LuaTeX luatexbase-modutils.sty 2013/05/11 v0.6 Module utilities for LuaTeX luatexbase-loader.sty 2013/05/11 v0.6 Lua module loader for LuaTeX luatexbase-regs.sty 2011/05/24 v0.4 Registers allocation for LuaTeX 186

luatexbase-attr.sty luatexbase-cctb.sty luatexbase-mcb.sty fontspec-patches.sty

2013/05/11 v0.6 Attributes allocation for LuaTeX 2013/05/11 v0.6 Catcodetable allocation for LuaTeX 2013/05/11 v0.6 Callback management for LuaTeX 2013/05/20 v2.3c Font selection for XeLaTeX and LuaLaTeX

fixltx2e.sty 2006/09/13 v1.1m fixes to LaTeX fontspec-luatex.sty 2013/05/20 v2.3c Font selection for XeLaTeX and LuaLaTeX fontenc.sty eu2enc.def 2010/05/27 v0.1h Experimental Unicode font encodings eu2lmr.fd 2009/10/30 v1.6 Font defs for Latin Modern xunicode.sty 2011/09/09 v0.981 provides access to latin accents and many othe r characters in Unicode lower plane eu2lmss.fd 2009/10/30 v1.6 Font defs for Latin Modern graphicx.sty 1999/02/16 v1.0f Enhanced LaTeX Graphics (DPC,SPQR) keyval.sty 1999/03/16 v1.13 key=value parser (DPC) graphics.sty 2009/02/05 v1.0o Standard LaTeX Graphics (DPC,SPQR) trig.sty 1999/03/16 v1.09 sin cos tan (DPC) graphics.cfg 2010/04/23 v1.9 graphics configuration of TeX Live pdftex.def 2011/05/27 v0.06d Graphics/color for pdfTeX fontspec.cfg t3cmr.fd 2001/12/31 TIPA font definitions supp-pdf.mkii epstopdf-base.sty 2010/02/09 v2.5 Base part for package epstopdf grfext.sty 2010/08/19 v1.1 Manage graphics extensions (HO) kvdefinekeys.sty 2011/04/07 v1.3 Define keys (HO) kvoptions.sty 2011/06/30 v3.11 Key value format for package options (HO) kvsetkeys.sty 2012/04/25 v1.16 Key value parser (HO) etexcmds.sty 2011/02/16 v1.5 Avoid name clashes with e-TeX commands (HO) epstopdf-sys.cfg 2010/07/13 v1.3 Configuration of (r)epstopdf for TeX Live *********** Tags: fonts (Prev Q) (Next Q), opentype (Prev Q) (Next Q), ligatures (Prev Q) (Next Q) User: mico

Answer by mico

187

With the advent of MacTeX2014 and continuing in MacTeX2015 -- and likely to persist into the indefinite future :-( -- Lua(La)TeX can no longer directly access certain font features, such as ligatures, if the font is a system font whose ligature-related properties are AAT-encoded and not OpenTypeencoded. Hoefler Text, Didot, and Baskerville are three such fonts. (In contrast, XeLaTeX continues to be able to access ligature-related features directly.) By setting up one more or ”feature files” that spell out which ligature substitutions should be performed, it is possible to restore ligatures when working with version of LuaLaTeX more recent than version 0.77. The output of the code shown below has the following characteristics: the first row is generated before the feature file is loaded; note that it’s lacking ligatures even though the option Ligatures=Common option was specified when the font (Hoefler Text in this case) was loaded via a \setmainfont statement. The second row, which is generated after the feature file is loaded via an \addfontfeature instruction, contains all the expected ligatures. Aside: (i) The example uses the filecontents package to be self-contained. In practice, all one needs to do is to create the feature file ”addligs.fea” once and store it in a directory that’s searched by the TeX distribution. (ii) The feature file shown here features (pun intended...) quite a few ligature substitutions, since Hoefler Text features lots and lots of ligatures. For other, less feature-rich, fonts, the ”standard five” ligatures -- ff, fi, fl, ffi, and ffl -- may be all that you need to take of.

Skip code block % !TEX TS-program = lualatex \RequirePackage{filecontents} \begin{filecontents*}{addligs.fea} languagesystem DFLT dflt; languagesystem latn dflt; # Ligatures 188

feature liga { sub f f by f_f; sub f i by f_i; sub f j by f_j; sub f k by f_k; sub f l by f_l; sub f f i by f_f_i; sub f f l by f_f_l; sub s t by s_t; sub c t by c_t; } liga; \end{filecontents*} \documentclass{article} \usepackage{fontspec} \setmainfont[Ligatures=Common]{Hoefler Text} \newcommand\wordlist{off fit fjord Kafka fly office baffle stop act} \begin{document} \wordlist \addfontfeature{FeatureFile=addligs.fea} \wordlist \end{document}

Addendum: Here’s a slightly more sophisticated example, which uses two different feature files depending on whether the font face is upright or italic. It makes use of the ability of fontspec to specify different features for Upright, Bold, Italic, and BoldItalic font faces. The separate treatment of the italic and non-italic cases is necessary because Hoefler Text features additional ligatures (esp. for ”sp” and ”Th”) just for the italic font faces.

189

Skip code block % !TEX TS-program = lualatex \RequirePackage{filecontents} \begin{filecontents*}{AddligsHoeflerUpright.fea} languagesystem DFLT dflt; languagesystem latn dflt; # Ligatures feature liga { sub f b by f_b; sub f f by f_f; sub f h by f_h; sub f i by f_i; sub f j by f_j; sub f k by f_k; sub f l by f_l; sub f f b by f_f_b; sub f f h by f_f_h; 190

sub f f i by f_f_i; sub f f k by f_f_k; sub f f l by f_f_l; sub c t by c_t; sub s t by s_t; } liga; \end{filecontents*} \begin{filecontents*}{AddligsHoeflerItalic.fea} languagesystem DFLT dflt; languagesystem latn dflt; # Ligatures feature liga { sub f b by f_b; sub f f by f_f; sub f h by f_h; sub f i by f_i; sub f j by f_j; sub f k by f_k; sub f l by f_l; sub f f b by f_f_b; sub f f h by f_f_h; sub f f i by f_f_i; sub f f k by f_f_k; sub f f l by f_f_l; sub c t by c_t; sub s t by s_t; sub s p by s_p; sub T h by T_h; sub a s by a_s; } liga; \end{filecontents*} \documentclass{article} \usepackage{fontspec} \setmainfont{Hoefler Text}[ Ligatures = {Common,Rare}, ItalicFont = Hoefler Text Italic, 191

BoldFont BoldItalicFont

= Hoefler Text Black, = Hoefler Text Black Italic]

\newcommand\words{fb ff fh fi fj fk fl ffb ffh ffk ffl ct st, sp Th} \begin{document} ligatures missing: \words\par \textbf{\words}\par \textit{\words}\par \textbf{\textit{\words}} \addfontfeature{% UprightFeatures BoldFeatures ItalicFeatures BoldItalicFeatures

= = = =

{FeatureFile=AddligsHoeflerUpright.fea}, {FeatureFile=AddligsHoeflerUpright.fea}, {FeatureFile=AddligsHoeflerItalic.fea}, {FeatureFile=AddligsHoeflerItalic.fea}}

\medskip ligatures restored/activated: \words\par \textbf{\words}\par \textit{\words}\par \textbf{\textit{\words}} \end{document}

Tags: fonts (Prev Q) (Next Q), opentype (Prev Q) (Next Q), ligatures (Prev Q) (Next Q)

192

Q: How to use OpenType fonts with plain-LuaTeX? Tags: fonts (Prev Q) (Next Q), opentype (Prev Q) (Next Q) Is it possible to have OpenType fonts with LuaTeX using the plain format? I have tried: \font\test="texgyrepagellaregular"\test test\bye but I get ! Font \test=texgyrepagellaregular not loadable: metric data not found or bad.. mtxrun --script fonts --list --all --pattern=pagella shows the above font name when I followed the instructions at http://wiki. contextgarden.net/Fonts_in_LuaTeX. But on actually using the fonts, the page switches to speaking of ConTeXt instead of LuaTeX, which leaves me to wonder if it is possible to use OT-fonts with plain? UPDATE Even though this now works fine for fonts which are located in my home directory (OSX Lion, BasicTeX2012, luatex-plain-format constructed as instructed below), I am unable to use fonts which are located in the system directories. So while the above example works (with texgyrepagellaregular), as the mtxrun-script shows its location as ~/Library/Fonts, the following doesn’t: \font\test="minionproregular" presumably because mtxrun shows its location as /Library/Fonts (the same issue seems to be with fonts inside /System/Library/Fonts). Now, I added to my ~/.zshrc: export OSFONTDIR=/System/Library/Fonts:/Library/Fonts:$OSFONTDIR after which I was able to update the fonts database with mtxrun --script fonts --reload (following these instructions), and indeed now the mtxrun listing does show all of the fonts. It’s just that luatex-plain doesn’t see them. 193

How can I make luatex-plain see the fonts mtxrun sees? Tags: fonts (Prev Q) (Next Q), opentype (Prev Q) (Next Q) User: morbusg

Answer by egreg LuaTeX has the same font support as pdfTeX, natively. However, using the right Lua code one can extend the font support, which is precisely the job of luaotfload.lua. The luaotfload.sty file can be loaded also with the Plain LuaTeX format. Try compiling the following file with luatex (note that ”Linux Libertine O” is in my system fonts, I used it just by way of example. Skip code block \input luaotfload.sty \font\x="texgyrepagella-regular.otf" \font\liber="Linux Libertine O/I=5:+smcp" at 12pt \x abcdef \liber abcdef \bye

194

Tags: fonts (Prev Q) (Next Q), opentype (Prev Q) (Next Q)

Q: Problem while compiling friggeri CV template with: ’ fontspec error: ”font-not-found”’ Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q) I have somme problem while I’m trying to compile template CV from: http:// www.latextemplates.com/template/friggeri-resume-cv . I have install texlivefull package on Ubuntu and tryied to compiled this template with command: lualatex cv_10.tex And I get: Skip code block : /home/lgadawski/.texmf-var/luatex-cache/generic/names/otfl-names.lua !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! ! fontspec error: "font-not-found"

195

! ! The font "HelveticaNeue" cannot be found. ! ! See the fontspec documentation for further information. ! ! For immediate help type H . !............................................... l.53 \newfontfamily\bodyfont[]{Helvetica Neue} I have also trying to do this on Windows with MikTex with same result. I spent some hours but couldn’t find explanation why is that and how could I properly compile it and built my own CV. Regards! Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q) User: lukasz-gadawski

Answer by nils-l That template assumes you have obtained a license for Linotype’s Neue Helvetica (€45 to €1500) and properly installed the font. If you haven’t, try {Arial}, {TeX Gyre Heros}, or whatever you like, instead. Locate friggeri-cv.cls and modify the following lines (l. 53--58): \newfontfamily\bodyfont[]{Helvetica Neue} \newfontfamily\thinfont[]{Helvetica Neue UltraLight} \newfontfamily\headingfont[]{Helvetica Neue Condensed Bold} \defaultfontfeatures{Mapping=tex-text} \setmainfont[Mapping=tex-text, Color=textcolor]{Helvetica Neue Light}

Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q)

196

Q: How does fontspec select fonts ”by name”? Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q), xetex (Prev Q) (Next Q) When loading a font by name, what is the search mechanism being used? How is the matching done? (It’s marked TODO in the documentation) I have many problems, for example: a ”Hoefler Text Engraved” font is replacing the default ”Hoefler Text” with bold \fontspec{Hoefler Text} \textbf{...}. Some of its metadata in fontforge: PS Names Family Name: Hoefler Text Weight: Normal TTF Names Family: Hoefler Text Engraved Styles (Subfamily): Regular Preferred Family: Hoefler Text Preferred Styles: Engraved What does fontspec/fontconfig read in the file to match the requested font? (in this case ”Hoefler Text/Bold” Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q), xetex (Prev Q) (Next Q) User: user7384

Answer by joseph-wright The detail depends on both the engine in use (XeTeX or LuaTeX) and also the operating system in question. However, in general the answer is ’fontspec does not actually do this’. More precisely, fontspec relies on features of the engine to load fonts. XeTeX and LuaTeX use different approaches to font loading. XeTeX contains operating system-dependent code, which therefore uses features of the system (as Windows, Mac OS X and Linux have

197

different approaches to font management). On the other hand, the LuaTeX approach is implemented in Lua, using feature of the LuaTeX engine. Coupled with these considerations, not all fonts are equal. Even if they have the same name, they may not be from the same supplier. Some fonts are regrettably ’faulty’ in their internals, and this tends to show up when loading with fontspec. Thus if you have an issue loading a particular font, then it’s not just a question of saying ’fontspec can’t find the font’, but rather ’using fontspec with on cannot load font from ’.

Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q), xetex (Prev Q) (Next Q)

Q: Reference about ”modern” LaTeX usage for scientific works Tags: fonts (Prev Q) (Next Q), packages (Prev Q) (Next Q) I am looking for a reference (book, free pdf, website) that would summarize the working of ”modern” LaTeX for scientific works (I’m writing my master thesis). I know and have been using LaTeX for some years, but I would like to go ”one step further”: I read about LuaTeX, new fonts, styles, packages, etc. I know to achieve this ”goal” I just have to read the questions/answers here but maybe someone will provide a good reference. This question is not very precise but I hope someone will understand what I’m looking for. Tags: fonts (Prev Q) (Next Q), packages (Prev Q) (Next Q) User: cedric-h.

Answer by geoffrey-jones 198

”Modern” is a somewhat loaded term. You probably want to distinguish between: 1. what’s functionally modern in the sense of the most technologically cutting edge or elegant ways to get TeX et famille to do your bidding. E.g., via LuaTeX, XeTeX, ConTeXt, LaTeX3, fontspec, microtype, etc.; 2. and, contra what’s technologically modern, what’s stylistically modern (in the sense of leading edge ideas for thesis/book/document design). You’ll get lots of very good info about functional ”edge of the envelope” possibilities just by typing some of the keywords mentioned in point 1 above (LuaTeX, etc.) into the searchbox at the top of this page, following links on and off this site, then asking more directed questions here as and when you’d like to learn more. You’ll find that the quality of responses increases the sharper the questions you ask. Another approach might be to search out those users with specialties you’re interested in (Joseph Wright for LaTeX3, Aditya for ConTeXt, Harald and Ulrike for seemingly impossible solutions to raw TeX problems, frabjous, Lev Bishop and Andrew Stacey for academic writing, Stefan and Will for, gosh, everything ...) then ”follow” the line of the questions they’ve answered by chasing them individually through their Users pages. This, I think, would be more fruitful than holding out for a consolidated ”reference (book, free pdf, website) that would summarize the working of ’modern’ latex for scientific works”. As for what’s stylistically modern package-wise, you’ll probably find ClassicThesis about as close to the edge as likely to be accepted in a science-oriented masters thesis (actually, probably closer to postmodern than modern). Otherwise, check out Tufte-Book for a raft of stylistically interesting ideas.

Tags: fonts (Prev Q) (Next Q), packages (Prev Q) (Next Q)

Q: Selecting optical sizes for all fonts in a family Tags: fonts (Prev Q) (Next Q), xetex (Prev Q) (Next Q) 199

XeTeX and LuaTeX are able to assign optical sizes to fonts when they are provided. In those situations where XeTeX or LuaTex are unable to correctly assign optical sizes I am able to specify them but only for the regular font, not for italics, bold, or bold italics. I’m looking for a way to assign all of them. The specific example I’m using is for Minion Pro and I know a package exists for it but I’m looking for a general solution I can apply as a regular user whenever something like this comes up again. Here’s the MWE: Skip code block

\documentclass[openleft,12pt]{memoir} \usepackage{fontspec} \setmainfont[ItalicFont={MinionPro-It},BoldFont={MinionPro-Bold},BoldItalicFont={M \begin{document} Regular\\ \textit{Italic}\\ \textbf{Bold}\\ \textit{\textbf{Bold Italic}}\ {\tiny tiny}\\ {\normalsize normal}\\ {\Large Large}\\ {\LARGE LARGE}\\ {\HUGE HUGE}\\ {\tiny{ \textit{tiny italic} \textbf{tiny bold} \textbf{\textit{tiny bold italic}}}}\\ {\Large{ \textit{Large italic} \textbf{Large bold} \textbf{\textit{Large bold italic}}}}\\ {\HUGE{ \textit{HUGE italic} \textbf{HUGE bold} \textbf{\textit{HUGE bold italic}}}} \end{document} Both XeLaTeX and LuaLaTeX need the italic, bold, and bold italic fonts declared. After that XeLaTeX uses all the correct optical sizes for this example. 200

LuaLaTeX does not use any of them (except as before for the regular font). If you change the \setmainfont section to look like this:

\setmainfont[ItalicFont={MinionPro-It},BoldFont={MinionPro-Bold},BoldItalicFont={M SizeFeatures={ {Size={-8.4},OpticalSize=8}, {Size={8.4-13},OpticalSize=11}, {Size={13-19.9},OpticalSize=19}, {Size={19.9-},OpticalSize=72}} ] {Minion Pro} Then everything still works for XeLaTeX and now the optical sizes (Caption, Regular, SubHeader, Display) work with LuaLaTeX for the regular fonts but not for italics, bold, and bold italics. I had thought that maybe something like:

\setmainfont[ItalicFont={MinionPro-It},BoldFont={MinionPro-Bold},BoldItalicFont={M SizeFeatures={ {Size={-8.4},OpticalSize=8,ItalicFont={MinionPro-ItCapt}, {Size={8.4-13},OpticalSize=11}, {Size={13-19.9},OpticalSize=19,ItalicFont={MinionPro-ItSubH}, {Size={19.9-},OpticalSize=72,ItalicFont={MinionPro-Disp}}} ] {Minion Pro} Would work (obviously filling in the bold and bold italic fonts and the other sizes) but that results in an error. I’ve tried several variations on that idea and nothing works. I keep reading over the fontspec and luaotfload manuals but can find nothing on how to do this thing specifically (I did find a reference to a ”goodies” file for ConTeXt but was unable to figure out how to load it into a LuaLaTeX document). Update Some more experimentation with Adobe fonts. I just did the same experiment with Garamond Premier Pro (also has optical sizes). And the results are similar. LuaLaTeX will just not load the Caption/Subheading/Display versions of Italic/Bold/Bold Italic though it handles the Regular font without even having to specify the optical sizes (thanks to a fix supplied when I asked a similar question before about 201

Garamond specifically). XeLaTeX will but uses the SemiBoldItalic versions for the different optical sizes instead of just BoldItalic. Tags: fonts (Prev Q) (Next Q), xetex (Prev Q) (Next Q) User: bfootdav

Answer by ludenticus You have to specify the font for each feature. See section 5.1.2. of the fontspec manual. A XeTeX MWE: Skip code block \documentclass[12pt]{memoir} \usepackage{fontspec} \setmainfont[% UprightFeatures={ SizeFeatures={ {Size={-8.4},Font=MinionPro-Capt}, {Size={8.4-13},Font=MinionPro-Regular}, {Size={13-19.9},Font=MinionPro-Subh}, {Size={19.9-},Font=MinionPro-Disp} }, }, BoldFeatures={ SizeFeatures={ {Size={-8.4},Font=MinionPro-BoldCapt}, {Size={8.4-13},Font=MinionPro-Bold}, {Size={13-19.9},Font=MinionPro-BoldSubh}, {Size={19.9-},Font=MinionPro-BoldDisp} }, }, ItalicFeatures={ SizeFeatures={ {Size={-8.4},Font=MinionPro-ItCapt}, {Size={8.4-13},Font=MinionPro-It}, {Size={13-19.9},Font=MinionPro-ItSubh}, 202

{Size={19.9-},Font=MinionPro-ItDisp} }, }, BoldItalicFeatures={ SizeFeatures={ {Size={-8.4},Font=MinionPro-BoldItCapt}, {Size={8.4-13},Font=MinionPro-BoldIt}, {Size={13-19.9},Font=MinionPro-BoldItSubh}, {Size={19.9-},Font=MinionPro-BoldItDisp} }, }, ] {Minion Pro} \begin{document} \noindent Regular\\ \textit{Italic}\\ \textbf{Bold}\\ \textit{\textbf{Bold Italic}}\\ \noindent {\tiny tiny}\\ {\normalsize normal, not \textbf{\textit{HUGE bold italic}}}\\ {\Large Large}\\ {\LARGE LARGE}\\ {\HUGE HUGE}\\ \noindent {\tiny{ \textit{tiny italic} \textbf{tiny bold} \textbf{\textit{tiny bold italic}}}}\\ {\Large{ \textit{Large italic} \textbf{Large bold} \textbf{\textit{Large bold italic}}}}\\ {\HUGE{ \noindent HUGE\\ \textit{HUGE italic}\\ \textbf{HUGE bold}\\ 203

\textbf{\textit{HUGE bold italic}}}} \end{document}

Answer by brent.longborough With XeTeX you do not need multiple size declarations, and I believe you should not with LuaTeX. In what follows, I’ll refer to @Ludenticus’ solution as (1), and mine, which follows, as (2): Skip code block \documentclass[12pt,a5paper]{memoir} \setlrmarginsandblock{1cm}{*}{1} \usepackage{fontspec} \setmainfont{Minion Pro}[% SizeFeatures={% {Size={-8.4},Font=* Caption}, {Size={8.4-13},Font=*}, {Size={13-19.9},Font=* Subhead}, {Size={19.9-},Font=* Display} }, BoldFont={* Bold}, BoldItalicFont={* Bold Italic}, ] \setlength{\parindent}{0pt} \nonzeroparskip \begin{document} \noindent Regular \textit{Italic} \textbf{Bold} \textit{\textbf{Bold Italic}}\par \noindent {\tiny tiny}\par {\normalsize normal, not \textbf{\textit{HUGE bold italic}}}\par {\Large Large}\par 204

{\LARGE LARGE}\par {\HUGE HUGE}\par

\noindent {\tiny{ \textit{tiny italic} \textbf{tiny bold} \textbf{\textit{tiny bold italic}}}}\par {\Large{ \textit{Large italic} \textbf{Large bold} \textbf{\textit{Large bold italic}}}}\pa {\HUGE{ \noindent HUGE\par \textit{HUGE italic}\par \textbf{HUGE bold}\par \textbf{\textit{HUGE bold italic}}}} \end{document} (1) and (2) processed with XeLaTeX produce visually identical PDFs (compared with diffpdf, option ’appearance’. (1) and (2) processed with LuaLaTeX are different. The PDF from (1) has a full complement of embedded fonts (16), while (2) only has 10, the extra optical sizes being missing. Notes: • The default Bold association for Minion Pro is not ’bold’, but ’semibold’. I assume this was what made you search for the parameters to change the two bold series. • If you’re happy with semibold, you can just omit the two Bold... lines altogether. • I much prefer to use font names rather than font filenames -- it seems a lot less brittle (once you discover the right names!).

Tags: fonts (Prev Q) (Next Q), xetex (Prev Q) (Next Q)

205

Q: Selecting main math font in LuaTeX? Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q), math-mode (Next Q) I’d to set some fairly simple maths in Minion Pro (and potentially other system fonts), using LuaTeX. I’d hoped that something like the following should work: \documentclass{minimal} \usepackage{fontspec} \setmainfont{Minion Pro} \begin{document} Here’s some text. \end{document}

Now some math: $x^2 + y^2 = z^2$.

However, the x^2 + y^2 + z^2 is set in Computer Modern. Material in \mathit, \mathrm etc. appears in Minion as hoped, and can be further controlled by \setmathrm and so on, but is there any way to control the main math font? I don’t have Minion Math, and trying to use ordinary Minion Pro as the math font via unicode-math doesn’t help—indeed, it puts \mathit material back into CM! MnSymbol also doesn’t help. But in any case, I’d prefer a solution that generalises to other fonts, if possible. Alternatively, changing to XeLaTeX, the mathspec package does the trick, using \setmathfont(Digits,Latin){Minion Pro}. But I’d be sad to give up microtype and the rest of the power of LuaTeX! Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q), math-mode (Next Q) User: peter-lefanu-lumsdaine

Answer by khaled-hosny Simply setting \usemathfont{Minion Pro} with unicode-math will not

206

work since it expects an OpenType math font, but you can use range option to use normal text fonts for certain math alphabets (or any math symbol), check documentation for details. Skip code block \documentclass{minimal} \usepackage{fontspec} \usepackage{unicode-math} \setmainfont{Minion Pro} \setmathfont{Asana Math} % for math symbols, can be any other OpenType math font \setmathfont[range=\mathup] {Minion Pro} \setmathfont[range=\mathbfup]{Minion Pro Bold} \setmathfont[range=\mathbfit]{Minion Pro Bold Italic} \setmathfont[range=\mathit] {Minion Pro Italic} \begin{document} Here’s some text. \end{document}

Now some math: $x^2 + y^2 = z^2$, $\mathrm{x^2 + y^2 = z^2}$, $

Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q), math-mode (Next Q)

Q: Best practice - how can I get my whole document (including math) to only use font X with LuaLaTeX and fontspec? Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q) Considering one uses math symbols in a document, it is desirable to have them all displayed in the serif font one is using for text, or in basically any font x one would like to use for this sort of thing. So for one who just started looking into using LuaLaTeX, the amount of information on how to properly typeset a document with only one font (or good combination of at least 2 fonts) is a bit overwhelming. There are easily 207

hundreds of questions on fontspec, Lua(La)TeX, mathspec and the resulting options to use a font, some of which are 4 years old. Maybe some of the more experienced (and especially more successful) users, who have done this kind of thing before, could share their code for some of the most popular fonts (or their clones and variants)? • Times New Roman • Helvetica/Arial • Palatino • Minion Pro • Garamond • Georgia ... and more Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q) User: henry

Answer by paul-gessler I’m not sure I qualify as experienced and/or more successful :-). But here’s an example of the setup I used for my thesis. Adobe Garamond Pro was used as the text font. Sadly, I needed bold to appease the thesis arbiters at my university, so I used BoldFont=AGaramondPro-Semibold as it looks slightly less out of place than the standard bold weight. For mathematics, I used the mathdesign package with option adobe-garamond. This provided all math symbols I needed for my document, with glyph shapes appropriate for Garamond as a text font. For this to be successful, you must copy the .otf font files to a specific TDS directory, as detailed in the mathdesign README file. I also have shown some additional typographical enhancements in my sample below, which you may be interested in. microtype allows for more pleasing color on the page. The selnolig package breaks ligatures which would otherwise span morpheme boundaries. Of course, only German and English 208

are supported out of the box, so it won’t do much for the Latin text in my example below. Here’s an example using the blindtext package to produce a sample mathematics paper, with explanations in the comments for each font option. I’ve set this in a two-column layout just so that all the math samples fit on one page for the screenshot. Sample Code Skip code block %% compile with LuaLaTeX \documentclass[twocolumn]{article} \usepackage{blindtext} % just for the sample math paper

% here are the font specifications \usepackage[adobe-garamond]{mathdesign} % use the mathdesign package with Garamond \usepackage[no-math]{fontspec} % load fontspec without modifying maths fonts \setmainfont[ Ligatures=TeX, % make ---, --, etc function as in traditional (La)TeX Kerning=Uppercase, % slight tracking adjustment for all-caps material BoldFont={AGaramondPro-Semibold}, % this is a bit of a faux pas, but it was requ Numbers=Proportional, % I also had some code to switch to lining numbers in tabu ]{Adobe Garamond Pro} \setmathrm{Adobe Garamond Pro} % for operators and other text in math

% some additional (optional) typographic enhancements \usepackage{microtype} \usepackage[english]{selnolig} % of course, this won't do much for latin lipsum te \begin{document} \blindmathpaper \end{document} Sample Output

209

Close-up 210

Answer by user56567 In according to unimath-symbols.pdf, the best fonts for math symbols are M Latin Modern Math (1588) X XITS Math (2437) C Cambria Math (2189) A Asana Math (2259) P TeX Gyre Pagella Math (1612) E Neo Euler (579) (IMHO, this is very wrong ...) There are many Times-compatible font with fontspec, like TeX Gyre Termes, FreeSerif and STIX. However, I prefer Latin Modern font to Times. This is my MWE Skip code block \documentclass{article} \usepackage[fleqn]{amsmath} \usepackage[no-math]{fontspec} \defaultfontfeatures[\rmfamily,\sffamily]{Ligatures=TeX} \setmainfont{Latin Modern Roman}[BoldFont={* Demi}] \setsansfont{Latin Modern Sans}[BoldFont={* Demi Cond}] \setmonofont{Latin Modern Mono Light} 211

\usepackage[math-style=ISO,bold-style=ISO]{unicode-math} \setmathfont{Latin Modern Math} \begin{document} \section{Test} Test text $\mathrm{test\ } � + � = �$ \end{document} Note that amsmath is loaded before unicode-math like suggested by unicode-math package documentation.

Answer by darthbith I had some experience with this in my thesis... The Times clone in the TeX Gyre fonts (Termes) can be used quite simply with the unicode-math package. In fact, any of the TeX Gyre fonts can be used this way (at least, the ones with corresponding math fonts) and this should work for XeLaTeX as well. \documentclass{article} \usepackage{unicode-math} \setmainfont{TeX Gyre Termes} \setmathfont{TeX Gyre Termes Math} \begin{document} Test text $\mathrm{test\ math} \alpha \beta x y z$ \end{document}

Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q)

Q: How to find out which glyphs are different in an OpenType style set? Tags: fonts (Prev Q) (Next Q), opentype (Prev Q) (Next Q), symbols (Next Q)

212

With fontspec, and XeTeX or LuaTeX it’s possible to access a font’s OpenType features, including the Style Sets, e.g. like this: \addfontfeatures{RawFeature=+ss01;+ss18} TeX.sx has already taught me how to find out which features are available. Assuming I don’t have proper documentation of my font at hand, is there a way to find out which glyphs (in which contexts) will actually come out differently when I use a certain style set (or another OpenType feature)? It also seems to depend on the script and font family (e.g. small caps). I feel like LuaTeX would be able to do this. A nice font with lots of features to test this is Junicode. For this specific case, however, all the features are neatly described in Specimens and User’s Guide. Tags: fonts (Prev Q) (Next Q), opentype (Prev Q) (Next Q), symbols (Next Q) User: doncherry

Answer by jukka-k.-korpela There’s DTL OTMaster, which can be used for free for inspecting a font (and for a fee, for font editing, too). It takes a little time to find out all the functions in the program, but e.g. the alternate glyphs available in a font can be found out by selecting Tools > ’GPOS’/’GSUB’ Table Viewer and then ’GSUB’ table from the first dropdown (Layout Table), then selecting different options in the Features menu. Then the Subtable view will show the glyphs affected by a feature, as a mapping table under “Report” and as a set of large-size glyphs under “Image”.

213

214

Tags: fonts (Prev Q) (Next Q), opentype (Prev Q) (Next Q), symbols (Next Q)

215

Q: Which fonts can be used with *unicode-math* package? Tags: fonts (Prev Q) (Next Q), xetex (Prev Q) (Next Q), unicode-math (Next Q), math-mode (Prev Q) (Next Q) What can i put into \setmathfont{.otf} for the unicode-math package to make it all work (with XeLaTeX or LuaLaTeX)? There are several suggestions on the GitHub page of unicode-math, but the first option is commercial, and the second and the third do not work with the following example: Skip code block % !TEX TS-program = xelatex \documentclass{article} \usepackage{unicode-math} \setmathfont{latinmodern-math.otf} % \setmathfont{texgyrepagella-math.otf} % \setmathfont{xits-math.otf} \begin{document} $X\setminus Y$ \end{document} I do not get the \setminus character in the output. The \setminus character is also missing if i do not set a math font at all (i do not know which font is used in this case). It works with xits-math, but i do not like it. Is it expected by the way that the \setminus character is left blank without giving any warning? Tags: fonts (Prev Q) (Next Q), xetex (Prev Q) (Next Q), unicode-math (Next Q), math-mode (Prev Q) (Next Q) User: alexey

Answer by david-carlisle 216

It works with \setmathfont{Asana-Math.otf} or as noted in the question, with \setmathfont{xits-math.otf} as mentioned in comments, if it doesn’t work you get a warning in the log, eg with latinmodern:

Missing character: There is no � in font [latinmodern-math.otf]/ICU:script=math ;l

Tags: fonts (Prev Q) (Next Q), xetex (Prev Q) (Next Q), unicode-math (Next Q), math-mode (Prev Q) (Next Q)

Q: How can you check if fontspec (with LuaLaTeX) can load a font? Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q) I want to check if fontspec (with LuaLaTeX) can load a certain font and if not try to load another one. For pdflatex I did by checking if the package file exists; but I don’t find an easy way to do it with fontspec. Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q) User: textnik

Answer by david-carlisle You can trap the error and make it a warning, just setting a flag, then test for that and load something else, see the code below. Note this is poking into internal interfaces so if it breaks at a fontspec update, don’t complain:-) Skip code block \documentclass{article} \usepackage{fontspec} 217

\newif\ifgoodfont \makeatletter \ExplSyntaxOn \cs_set:Nn \__fontspec_load_font: { \__fontspec_font_set:Nnn \l_fontspec_font { \__fontspec_fullname:n {\l_fontspec_fontname_up_tl} } {\[email protected] pt} \__fontspec_font_if_null:NT \l_fontspec_font { \global\goodfontfalse \__fontspec_warning:nx {font-not-found} {\l_fontspec_fontname_up_tl} } \__fontspec_set_font_type: \__fontspec_font_gset:Nnn \l_fontspec_font { \__fontspec_fullname:n {\l_fontspec_fontname_up_tl} } {\[email protected] pt} \l_fontspec_font % this is necessary for LuaLaTeX to check the scripts properly }

\cs_set:Nn \__fontspec_load_fontname:n { \__fontspec_load_external_fontoptions:Nn \l_fontspec_fontname_tl {#1} \prop_get:NVNF \g__fontspec_fontopts_prop \l_fontspec_fontname_tl \l__fontspec { \clist_clear:N \l__fontspec_fontopts_clist } \__fontspec_font_set:Nnn \l_fontspec_font {\__fontspec_fullname:n {\l_fontspec \__fontspec_font_if_null:NT \l_fontspec_font { \global\goodfontfalse \__fontspec_warning:nx {font-not-found} {#1} } }

\ExplSyntaxOff \makeatother {\scrollmode\global\goodfonttrue \setmainfont{zzzz} } \ifgoodfont \typeout{(zzzz found (strange:-)} 218

\else \typeout{zzzz not found, trying TeX Gyre Bonum} \global\goodfonttrue \setmainfont{TeX Gyre Bonum} \ifgoodfont \typeout{OK} \else \typeout{not found that either, stopping} \stop \fi \fi

\begin{document} zzz \end{document}

Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q)

Q: Prevent LuaLaTeX from splitting umlauts Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q), unicode (Next Q) Here’s a minimal example: \documentclass{minimal} \usepackage{fontspec}\setmainfont{Cambria} \begin{document}aöz\end{document} Compiling this into a PDF using lualatex and extracting the text using pdftotext, I get the string aö z, that is: U+0061(a) U+006f(o) U+0308(combining diaeresis) U+0020(space) U+007a(z) Two problems with this: there’s an unnecessary space (due to some PDF formatting trickery, the uncompressed datastream shows Tm[125-124]TJ), 219

and I don’t want the umlaut to be split into base and combining character because for some reason that renders weirdly when changing the font size. I want the output to be U+0061(a) U+00f6(ö) U+007a(z) And the worst thing: with \setmainfont{Lucida Grande}, I get exactly that. Just not with Cambria. Both are in TTF format. Checking the fonts in fontforge shows that both their U+00f6 glyphs are defined as composed of U+006f U+0308, only difference being that Cambria defines its OTF Class as “Base Glyph” while in Lucida Grande it’s “Automatic” (no idea what that means).

It is a fontspec specific problem: \documentclass{minimal} \usepackage{luaotfload} \font\foo={name:Cambria} at 10pt \begin{document} aöz \foo aöz \end{document} generates what I expect, first umlaut missing as expected, too: U+0061(a) U+007a(z) U+0020(space) U+0061(a) U+00f6(ö) U+007a(z) but \documentclass{minimal} \usepackage{fontspec} \begin{document} aöz \fontspec{Cambria} aöz \end{document} generates U+0061(a) U+00f6(ö) U+007a(z) U+0020 U+0061(a) U+006f(o) U+0308 U+0020 U+007a(z)

Same when using \DeclareUTFcharacter{x00F6}{\foo} and replacing ö with \foo{}, so I guess it’s not xunicode’s fault? 220

Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q), unicode (Next Q) User: pascal

Answer by pascal From this answer I learned there is a Renderer=Basic option that causes an unknown number of side-effects. \documentclass{minimal} \usepackage{fontspec} \defaultfontfeatures{Renderer=Basic} \begin{document} aöz \fontspec{Cambria} aöz ffi \end{document} The font doesn’t seem to use ligatures anyway, where I want to use special features like VerticalPosition=Numerator for vulgar fractions, I can just switch to Renderer=Full. A way to keep it from messing around in my unicode while keeping all functionality would be better though…

I’ve been using the Basic renderer since and it seems to support the font’s built in ligatures after all (for Cambria look at ti), no TeX-ligatures like --for dashes though, need to enter those as unicode —

Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q), unicode (Next Q)

221

Q: How to generate compounded diacritical fonts for Sanskrit with XeTeX and LuaTeX? Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q), xetex (Prev Q) (Next Q) I’m trying to use diacritical marks for Sanskrit with a font that does not natively support all the marks (Minion Pro). So they are compounded somehow by XeTeX. This works almost fine in using: Skip code block \documentclass{scrartcl} \usepackage{xunicode,xltxtra} \usepackage{fontspec,newunicodechar} \defaultfontfeatures{Ligatures=TeX} \setmainfont{Minion Pro} \newunicodechar{Ṛ}{\d{R}} \newunicodechar{ṛ}{\d{r}} \newunicodechar{Ṝ}{\={\d{R}}} \newunicodechar{ṝ}{\={\d{r}}} \newunicodechar{Ḷ}{\d{L}} \newunicodechar{ḷ}{\d{l}} \newunicodechar{Ḹ}{\={\d{L}}} \newunicodechar{ḹ}{\={\d{l}}} \newunicodechar{ṃ}{\d{m}} \newunicodechar{ḥ}{\d{h}} \newunicodechar{Ṭ}{\d{T}} \newunicodechar{ṭ}{\d{t}} \newunicodechar{Ḍ}{\d{D}} \newunicodechar{ḍ}{\d{d}} \newunicodechar{Ṅ}{\.{N}} \newunicodechar{ṅ}{\.{n}} \newunicodechar{Ṇ}{\d{N}} \newunicodechar{ṇ}{\d{n}} \newunicodechar{Ṣ}{\d{S}} \newunicodechar{ṣ}{\d{s}}

222

\begin{document} a A ā

Ā

i

I

ī

Ī

u

U

ū

Ū

















e

E

ai o

Ai O

au

Au

ṃ ḥ k

K

c

C





t

T 223

p

P

kh

Kh

ch

Ch

ṭh

Ṭh

th

Th

ph

Ph

g

G

j

J





d

D

b

B

gh

Gh

jh

Jh

ḍh

Ḍh

dh

Dh

bh

Bh





ñ

Ñ



Ṇ 224

n

N

m

M

y

Y

r

R

l

L

v

V

ś

Ś





s

S

h

H

\end{document} But the macrons above Ḹ, ḹ, Ṝ, and ṝ are misplaced and thiner than the ones above ā, ī and so on. What can I do about that? Second problem: This fails completely in LuaTeX. xltxtra seems to be essential for this to work. But this is not supported in LuaTeX. I tried this using this code: https://tex.stackexchange.com/a/20791/19458 But the dots below are bigger than the i-dot. This is not the case with the solution above using XeTeX. Any idea how to do this in a better way in LuaTeX? Is it possible at all? Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q), xetex (Prev Q) (Next Q) User: psychic-birdy

225

Answer by egreg Here is something that seems to work: Skip code block \documentclass{scrartcl} \usepackage{fontspec,newunicodechar} \defaultfontfeatures{Ligatures=TeX} \setmainfont{Minion Pro} \UndeclareUTFcomposite[\UTFencname]{x1E0C}{\d}{D} \UndeclareUTFcomposite[\UTFencname]{x1E0D}{\d}{d} \UndeclareUTFcomposite[\UTFencname]{x1E25}{\d}{h} \UndeclareUTFcomposite[\UTFencname]{x1E36}{\d}{L} \UndeclareUTFcomposite[\UTFencname]{x1E37}{\d}{l} \UndeclareUTFcomposite[\UTFencname]{x1E43}{\d}{m} \UndeclareUTFcomposite[\UTFencname]{x1E46}{\d}{N} \UndeclareUTFcomposite[\UTFencname]{x1E47}{\d}{n} \UndeclareUTFcomposite[\UTFencname]{x1E5A}{\d}{R} \UndeclareUTFcomposite[\UTFencname]{x1E5B}{\d}{r} \UndeclareUTFcomposite[\UTFencname]{x1E62}{\d}{S} \UndeclareUTFcomposite[\UTFencname]{x1E63}{\d}{s} \UndeclareUTFcomposite[\UTFencname]{x1E6C}{\d}{T} \UndeclareUTFcomposite[\UTFencname]{x1E6D}{\d}{t} \UndeclareUTFcomposite[\UTFencname]{x1E44}{\.}{N} \UndeclareUTFcomposite[\UTFencname]{x1E45}{\.}{n} \makeatletter \let\d\relax \DeclareRobustCommand{\d}[1] {\[email protected] \[email protected]{\relax#1\crcr\hidewidth\[email protected]@ft{-1ex}.\hidewidth}\egroup} \let\.\relax \DeclareRobustCommand{\.}[1]{\accent"02D9#1} \DeclareRobustCommand{\MACRON}[1]{\accent"AF#1} \makeatother

226

\newunicodechar{Ḍ}{\d{D}} \newunicodechar{ḍ}{\d{d}} \newunicodechar{ḥ}{\d{h}} \newunicodechar{Ḷ}{\d{L}} \newunicodechar{ḷ}{\d{l}} \newunicodechar{ṃ}{\d{m}} \newunicodechar{Ṇ}{\d{N}} \newunicodechar{ṇ}{\d{n}} \newunicodechar{Ṛ}{\d{R}} \newunicodechar{ṛ}{\d{r}} \newunicodechar{Ṣ}{\d{S}} \newunicodechar{ṣ}{\d{s}} \newunicodechar{Ṭ}{\d{T}} \newunicodechar{ṭ}{\d{t}} \newunicodechar{Ṅ}{\.{N}} \newunicodechar{ṅ}{\.{n}} \newunicodechar{Ḹ}{\d{\MACRON{L}}} \newunicodechar{ḹ}{\d{\MACRON{l}}} \newunicodechar{Ṝ}{\d{\MACRON{R}}} \newunicodechar{ṝ}{\d{\MACRON{r}}} \begin{document} \parbox{.5\textwidth}{ a A ā Ā i I ī Ī u U ū Ū ṛ Ṛ ṝ Ṝ ḷ Ḷ ḹ Ḹ e E ai Ai o O 227

au Au ṃ ḥ k K c C ṭ Ṭ t T p P kh Kh ch Ch ṭh Ṭh th Th ph Ph g G j J ḍ Ḍ d D b B gh Gh jh Jh ḍh Ḍh dh Dh bh Bh ṅ Ṅ ñ Ñ ṇ Ṇ n N m M y Y r R l L v V ś Ś ṣ Ṣ s S h H } \end{document}

228

As you see it’s necessary to undo some of the work done by xunicode (which is automatically loaded by fontspec and needn’t to be loaded explicitly). Also some of the standard accents must be redefined, or they wouldn’t use the main document font. Update 2017 The macros above work provided fontspec is loaded with the euenc option. On the other hand, the new default TU encoding doesn’t declare composites with \d or \.N and \.n, so the code is simpler. Skip code block \documentclass{scrartcl} \usepackage{fontspec} \usepackage{newunicodechar} \setmainfont{Minion Pro} \makeatletter \let\d\relax \DeclareRobustCommand{\d}[1] {\[email protected] \[email protected]{\relax#1\crcr\hidewidth\[email protected]@ft{-1ex}.\hidewidth}\egroup} \let\.\relax \DeclareRobustCommand{\.}[1]{\accent"02D9#1} \DeclareRobustCommand{\MACRON}[1]{\accent"AF#1} \makeatother \newunicodechar{Ḍ}{\d{D}} 229

\newunicodechar{ḍ}{\d{d}} \newunicodechar{ḥ}{\d{h}} \newunicodechar{Ḷ}{\d{L}} \newunicodechar{ḷ}{\d{l}} \newunicodechar{ṃ}{\d{m}} \newunicodechar{Ṇ}{\d{N}} \newunicodechar{ṇ}{\d{n}} \newunicodechar{Ṛ}{\d{R}} \newunicodechar{ṛ}{\d{r}} \newunicodechar{Ṣ}{\d{S}} \newunicodechar{ṣ}{\d{s}} \newunicodechar{Ṭ}{\d{T}} \newunicodechar{ṭ}{\d{t}} \newunicodechar{Ṅ}{\.{N}} \newunicodechar{ṅ}{\.{n}} \newunicodechar{Ḹ}{\d{\MACRON{L}}} \newunicodechar{ḹ}{\d{\MACRON{l}}} \newunicodechar{Ṝ}{\d{\MACRON{R}}} \newunicodechar{ṝ}{\d{\MACRON{r}}} \begin{document} \parbox{.5\textwidth}{ a A ā Ā i I ī Ī u U ū Ū ṛ Ṛ ṝ Ṝ ḷ Ḷ ḹ Ḹ e E ai Ai o O au Au 230

ṃ ḥ k K c C ṭ Ṭ t T p P kh Kh ch Ch ṭh Ṭh th Th ph Ph g G j J ḍ Ḍ d D b B gh Gh jh Jh ḍh Ḍh dh Dh bh Bh ṅ Ṅ ñ Ñ ṇ Ṇ n N m M y Y r R l L v V ś Ś ṣ Ṣ s S h H Ḹ ḹ Ṝ ṝ } \end{document} 231

Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q), xetex (Prev Q) (Next Q)

Q: How do I combine fonts for different scripts? Tags: fonts (Prev Q) (Next Q), xetex (Prev Q) (Next Q), cjk (Next Q) I want to combine Helvetica World (for roman, cyrillic, greek and arabic) and Hei Std (for simplified chinese) in one document with LuaLaTeX. Hei Std probably hasn’t all the glyphs from Helvetica World and Helvetica World certainly hasn’t all characters from Hei Std. Can I get LuaLaTeX to automatically choose the right font based on the input, i.e. can I combine fonts into one ”virtual font”? I don’t want to switch the fonts manually. Out of curiosity I’m also interested in a solution for XeLaTeX, but I need one for LuaLaTeX. Tags: fonts (Prev Q) (Next Q), xetex (Prev Q) (Next Q), cjk (Next Q) User: martin-schröder

Answer by leo-liu

232

Yes, for XeLaTeX, you should use our xeCJK package. For Chinese typesetting in xeCJK, see my previous answers tagged cjk. A simple example: Skip code block % UTF-8 encoding, compile with XeLaTeX \documentclass{article} \usepackage{xeCJK} \setmainfont{Arial} \setCJKmainfont{Microsoft YaHei} \begin{document} Arial font and ���� \end{document}

And for LuaLaTeX, you can use luatexja-fontspec package from luatexja bundle. luatexja is originally designed for Japanese, but also useful for Chinese (due to Ma Qiyuan’s work). A simple example, very similar to xeCJK: Skip code block % UTF-8 encoding, compile with LuaLaTeX \documentclass{article} \usepackage{luatexja-fontspec} \setmainfont{Arial} \setmainjfont{Microsoft YaHei} \begin{document} Arial font and ���� \end{document} The English document of luatexja: http://mirror.ctan.org/macros/luatex/ generic/luatexja/doc/luatexja-en.pdf

233

In ctex bundle, we shall also support luatexja as one of the background package. The new version has not been released.

Tags: fonts (Prev Q) (Next Q), xetex (Prev Q) (Next Q), cjk (Next Q)

Q: Why does LuaLaTeX produce smaller files than pdfLaTeX in this example? Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q), file-size (Next Q) I am discovering LuaLaTeX... I want to produce pdf files from my tex sources as small as possible. If I compile the following code with LuaLaTeX, the size of the generated pdf is 9 kB. Skip code block \documentclass{article} \usepackage{titlesec} \usepackage{titling} \usepackage{fontspec} % Specify different font for section headings \newfontfamily\headingfont[]{Gill Sans} \titleformat*{\section}{\LARGE\headingfont} \titleformat*{\subsection}{\Large\headingfont} \titleformat*{\subsubsection}{\large\headingfont} \renewcommand{\maketitlehooka}{\headingfont} \author{An author} \title{The title of the article} \date{\today} \begin{document} \maketitle \section{A section} \subsection{A subsection} 234

\subsubsection{A subsubsection} \end{document} If I compile the same code with LaTeX but with a difference of font, the resulted files is 49 kB large. I guess the difference doesn’t come from LaTeX ou LuaLaTeX but from the fonts. Something like : ”my pdf system knows better about the Gill Sans font than the default LaTeX fonts”. Skip code block \documentclass{article} \usepackage{titlesec} \usepackage{titling} %\usepackage{fontspec} %% Specify different font for section headings %\newfontfamily\headingfont[]{Gill Sans} %\titleformat*{\section}{\LARGE\headingfont} %\titleformat*{\subsection}{\Large\headingfont} %\titleformat*{\subsubsection}{\large\headingfont} %\renewcommand{\maketitlehooka}{\headingfont} \author{An author} \title{The title of the article} \date{\today} \begin{document} \maketitle \section{A section} \subsection{A subsection} \subsubsection{A subsubsection} \end{document} Can someone confirm this? Is there a rule to learn from this if one wants to produce very light files?

PS : If I use the same font, I get the same size ! PPS : Strangely, if I apply ghostscript on the pdf file generated by LuaLaTex, the size gets bigger (from 9 kB to 12 kB !). The file generated by LaTex : from 49 kB to 13 kB. PPPS : In my naive way of understanding things, using a custom font, such 235

as Gill Sans would normally produce a bigger file than if using the standard font. Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q), file-size (Next Q) User: colas

Answer by keks-dose I’m using Linux Libertine heavily and each PDF, made with pdfLaTeX, had a size of some hundred KB. pdfTeX (as far as I know called by pdfLaTeX) embeds the fonts in the PDF, but it does not compress them. There was a wonderful tool called pdfsizeopt, written by Peter Szabo and published at Google Code. It compressed the fonts inside the PDF heavily; mine usually by factor 10! Well, sadly enough, the page http://pdfsizeopt.googlecode.com/ was taken down for alleged copyright issues. New home is here: https://github.com/ pts/pdfsizeopt (Thank you, giordano). There you will find a paper Szabo published about the compression going down to a very detailed level. In short: The difference between LuaLaTeX and PDFLaTeX seems to be the way of embedding the fonts, namely the used compression. So as a result to those batshit crazy laws you’d better not publish you code with googlecode.

Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q), file-size (Next Q)

Q: How is a TeX document written when using LuaLaTeX? Tags: fonts (Prev Q) (Next Q)

236

I am new to the LaTeX world and would like to start off with a book project. My target is specifically creating books for print and online. My requirements are • • • •

UTF-8, Arabic, custom fonts, to output PDF/X-1a compliant PDFs.

I have read that LuaTeX is the new engine. How does using LuaLaTeX affect the .tex document structure? For example, if I follow the LaTeX Beginner’s Guide, would I be able to use LuaLaTeX? Is only the preamble different when using LuaLaTeX? I am using TeXStudio under Windows 8.1. Tags: fonts (Prev Q) (Next Q) User: ibn-saeed

Answer by stephan-lukasczyk LuaLaTeX shouldn’t affect your document too much. The main thing you’ll have to change is the preamble. There’s no need to load packages like fontenc or inputenc. LuaLaTeX supports UTF-8 by default, so you should encode your files with UTF-8 (this should be possible with TeXStudio). Instead of having a preamble like \documentclass{article} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} there now is the package fontspec to set the document’s fonts: \documentclass{article} \usepackage{fontspec} \setmainfont[Ligatures=TeX]{Linux Libertine O} \setsansfont[Ligatures=TeX]{Linux Biolinum O} 237

and so on. Please read the documentation of the fontspec package for details on this. Also the LuaTeX reference might be useful, as well as Manuel Pégourié-Gonnard’s Guide to LuaLaTeX, which I really recommend reading. It basically gives you the main differences (see p. 3 of the PDF file): 1. Don’t load inputenc; just encode your source in UTF-8. 2. Don’t load fontenc or textcomp; load fontspec. 3. babel works with LuaLaTeX but you can load polyglossia instead. 4. Don’t use any package that changes the fonts; use fontspec commands instead. Basically, everything that works with normal pdfTeX should also work with LuaTeX, but be aware that LuaTeX is still in development and it could change from release to release. For distinct questions and problems, please have a look around this website for an answer to your question, or ask a question yourself.

Tags: fonts (Prev Q) (Next Q)

Q: In LuaTex is it possible to change font/language according to the script/glyphs used? Tags: fonts (Prev Q) (Next Q), hyphenation (Next Q) I am a XeLaTeX user and I often have to typeset english-greek documents. Packages like xgreek or polyglossia are great but in order to apply the correct hyphenation rules you have to declare the text that belongs to the secondary language. On the long run, this can become cumbersome. In XeLaTeX I am using the XeTeXinterchartoks mechanism that allows me to change automatically the hyphenation rules and/or the font without explicitingly declaring them. The procedure involves grouping together the glyphs of a Unicode Block and then automatically applying tex commands when transitioning from a group to another one.

238

For those not familiar with the XeTeXinterchartoks, more info can be found at xetex-reference pages 13-14. Lately I got interested in Lua(La)Tex. I want to know if there is a way to achieve similar results in LuaTex. As was pointed in a previous question, in LuaTeX there is not a direct analogue to XeTeXinterchartoks but it was suggested that there are other, more powerful ways to achieve the same goal. So the questions are 1. How can I change the hyphenation rules/font automatically according to the glyphs used without declaring them? 2. Can someone provide a minimum working example or at least point me to some references? 3. One of the drawbacks of XeTeXinterchartoks is that the settings are global. Is there a way in LuaTeX to set this feature (if it exists) on and off, thus providing more flexibility? Tags: fonts (Prev Q) (Next Q), hyphenation (Next Q) User: pmav99

Answer by taco-hoekwater Here is a proof of concept at doing the equivalent of \XeTeXinterchartoks in luatex. First, a style file: Skip code block % luatexinterchartoks.sty \newcount\XeTeXinterchartokenstate \newcount\charclasses \def\newXeTeXintercharclass#1% {\global\advance\charclasses1\relax \newcount#1 \global#1=\the\charclasses }

239

\newcount\cchone \newcount\cchtwo \def\dodoXeTeXcharclass {\directlua{setcharclass(\the\cchone,\the\cchtwo)}} \def\doXeTeXcharclass% {\afterassignment\dodoXeTeXcharclass\cchtwo } \def\XeTeXcharclass% {\afterassignment\doXeTeXcharclass\cchone } \protected\def\XeTeXdointerchartoks% {\directlua{setinterchartoks(\the\cchone,\the\cchtwo,\the\allocationnumber)}} \protected\def\dodoXeTeXinterchartoks% {\newtoks\mytoks\afterassignment\XeTeXdointerchartoks\global\mytoks } \protected\def\doXeTeXinterchartoks% {\afterassignment\dodoXeTeXinterchartoks\cchtwo } \def\XeTeXinterchartoks% {\afterassignment\doXeTeXinterchartoks\cchone } \luatexdirectlua{dofile('luatexinterchartoks.lua')} \endinput And a matching lua file: Skip code block % luatexinterchartoks.lua charclasses = charclasses or {} function setcharclass (a,b) charclasses[a] = b end 240

local i = 0 while i < 65536 do charclasses[i] = 0 i = i + 1 end interchartoks =

interchartoks or {}

function setinterchartoks (a,b,c) interchartoks[a] = interchartoks[a] or {} interchartoks[a][b] = c end local nc, oc oc = 255

function do_intertoks () local tok = token.get_next() if tex.count['XeTeXinterchartokenstate'] == 1 then if tok[1] == 11 or tok[1] == 12 then nc = charclasses[tok[2]] newchar = tok[2] else nc = 255 newchar = '' end local insert = '' if interchartoks[oc] and interchartoks[oc][nc] then insert = interchartoks[oc][nc] local newtok = tok if insert 0) then tex.sprint("{\\OD\\char" .. glyphs[i].unicode .. "}"); end tex.print(" {\\small(") tex.print(-2, glyphs[i].name ) tex.sprint(')}\\\\') end fontloader.close(f) \end{luacode*} \end{multicols} 258

\end{document}

Tags: fonts (Prev Q) (Next Q), xetex (Prev Q) (Next Q), context (Next Q), symbols (Prev Q) (Next Q)

Q: Fixing fonts with LuaTeX feature files Tags: fonts (Prev Q) (Next Q) Bringhurst urges us in Chapter 10 of The Elements of Typographic Style: Version 4.0 to fix the font files if needed. See below a summary of the chapter using the section titles. Bringhurst suggests to modify the font file so the fixes are done forever. But I think that for some fixes we can use feature files in LuaTeX. This can make easier to transfer projects from computers with fonts installed system-wide. I ask for help to identify what can be corrected using feature files and show an example file. (Would it be better to make this question a comunity wiki?) List of possible issues to be fixed 1. Letterform Sometimes the glyphs are completely wrong. Usually due to missing glyphs taken from other fonts. In this case the only possibility is to use a font editor. Not possible with feature files. 2. Hinting 259

Hinting is not an easy process and sometimes is wrong or missing Altogether. In this case the only possibility is to use a font editor. Not possible with feature files. 3. Vertical position Some characters’ vertical position (specially +, -, dashes, ...) could be improved. Is it posible to fix it with feature files? 4. Sidebering This is the blank space at the right and left of the outline of the glyph insie the box. Bringhurst says that he has to fix these values usually to fix the space between letters and puntuation symbols (He describes his style in this regards as a halfway between british and french typographic traditions). Can/Should it be done with feature files? (The microtype package can do the french typeseting style. Does it use kerning correction for that?) 5. Character substitution Some characters could be in an inappropriate encoding position. I guess this can be fix with a GSUB rule. 6. Kerning What to say about bad kerning, that the audience of this forum doesn’t already know! This is an easy one; I can even answer myself :-) Summary of Chapter 10 10 Grooming the font 10.1 Legal considerations 10.1 Check the license before tuning a digital font 10.2 Ethical & aesthetic considerations !0.2.1 If ain’t broken... 10.2.2 If the font is out of tune, fix it once and for all 10.2.3 Respect the font first of all, the letterform second, the type designer third, the foundry fourth

260

10.2.4 Keep on fixing 10.3 Honing the character set 10.3.1 If there are defective glyphs, meal them 10.3.2 If text figures, ligatures or other glyphs you need on a regular basis don’t reside on the base font, install them there 10.3.3 if glyphs you need are missing altogether, make them 10.3.4 Check and correct the sidebering 10.3.5 Refine the kerning table 10.3.6 Check the kerning of the word space 10.4 Hinting 10.4.1 If the font looks poor at low resolutions, check the hinting 10.5 Naming convention Tags: fonts (Prev Q) (Next Q) User: textnik

Answer by georgd A little guide to feature files With feature files you can define two types of operation in lookups: substitute (sub) glyphs by others and position (pos) glyphs. What is impossible, is to modify the letterforms or add missing glyphs. Also, wrong encoding can’t be corrected by feature files. The only thing one can do in this case is to a glyph by another from the font so at least the visual appearance is as expected. Simple lookups The simplest positioning is kerning:

261

lookup mykern { pos A V -70; # 'pos' is short for the keyword 'position' pos T e -100; } mykern; Substitution is possible as 1:1, n:1 (ligature), 1:n Skip code block

lookup mysmallcaps { sub u by v.sc; # have a v shaped smallcap glyph instead of a u-shaped one; with } mysmallcaps; lookup myligatures { sub a e by ae; # 'sub' is short for the keyword 'substitute' } myligatures; lookup unligate { sub f_f_l by f f l; } unligate; Contextual lookups More complex lookups can define in which context an operation takes place: lookup myordinals { sub one s' by s.sups; sub s.sups t' by t.sups; } myordinals; lookup kernwithdiacritics { pos T' 50 e acutecomb; # this is accumulative to a previous kern of T e } kernwithdiacritics; With the keyword ignore one can exclude contexts from the substitution. The following will substitute e with a final form if it’s not followed by one of the letters A-Z or a-z: lookup finals { ignore sub e' [A-Z a-z]; # the content inside the brackets is a "glyph class" 262

sub e' by e.fina; } finals; Advanced positioning The two kinds of position parameters in the kern lookups are short formats. The full format is . So, for example adjust the vertical position of a superscript glyph with: lookup mysuperscript { pos e.sups ; } mysuperscript;

# e.sups is positioned 50 design-units higher

To illustrate let’s adjust the greek letter Η with polytonic accents. In the first example it’s Eta with grave (Ὴ, needs space to the left), in the second we add a iota adscriptum (� needs space to the right. xplacement shifts the image of the glyph by the given value without changing its box, xadvance changes the size of the glyph’s box: lookup greekaccents1 { pos Eta' gravecomb.grk; } greekaccents1; lookup greekaccents2 { pos Eta' ypogegrammeni.cap; pos Eta' ypogegrammeni.cap gravecomb.grk; } greekaccents1; Important: • Lookups are accessible via features, where one feature can activate one or more lookups and different features can activate the same lookup: feature gacc { # featurenames are four-letter tags lookup greekaccents1; lookup greekaccents2; } gacc; • Lookups are applied to a language-system which needs to be defined, but make sure that that system exists in the font. The language263

systems can be defined at the beginning of the feature-file, they will be applied to lookups in all subsequent features. If one needs to apply a lookup only in specific language-systems on has to do so explicitly inside the feature: languagesystem languagesystem languagesystem languagesystem

DFLT grek latn latn

dflt; dflt; dflt; TRK ;

feature mkrn { lookup mykern; # This will be applied to all above language-systems } mkrn; feature itrk { script latn; language TRK exclude_dflt; lookup turkish_i { sub i.sc by i.sc dotaccent; # this will only be applied to Turkish in } turkish_i; } itrk; • As you can see above, lookups can be defined separately or nested inside features. • For bigger tasks, you can define glyphclasses (eg. before the lookups): @letters = [a-z aacute eacute adieresis odieresis]; @LETTERS = [A-Z Aacute Eacute Adieresis Odieresis]; • Make sure that you use the glyphnames as they appear in the font. This can be tricky and you might need to open the font in a font-editor or dump it with some tool (does somebody know a more direct way?) For example, the glyphname Delta can refer either to the greek letter or to the symbol in different versions of the same Adobe spec. Also, font-designers can name the glyphs different from Adobes proposals.

Answer by thérèse Here are three examples from my experience: 264

Sometimes a font has oldstyle figures in both its roman and its italic, but the onum feature is defined only for the roman. Didot LT Pro is one such font, and its oldstyle italic figures can be made easily accessible this way: Skip code block \documentclass{article} \usepackage{filecontents,fontspec} \begin{filecontents*}{didot.fea} languagesystem DFLT dflt; languagesystem latn dflt; # fix for italic feature inum { sub zero by zero.onum; sub one by one.onum; sub two by two.onum; sub three by three.onum; sub four by four.onum; sub five by five.onum; sub six by six.onum; sub seven by seven.onum; sub eight by eight.onum; sub nine by nine.onum; } inum; \end{filecontents*} \setmainfont[FeatureFile={didot.fea}, UprightFeatures={Numbers=OldStyle}, ItalicFeatures={RawFeature={+inum}}] {Didot LT Pro} \begin{document} 1234567890 \textit{1234567890} \end{document} Sometimes a font has ligatures, but the liga feature is not defined. Freundschafts Antiqua is a case in point. You can use the ligatures this way: Skip code block 265

\documentclass{article} \usepackage{filecontents,fontspec} \begin{filecontents*}{frnd.fea} languagesystem DFLT dflt; languagesystem latn dflt; feature liga { sub \f \i by \fi; sub \f \l by \fl; } liga; \end{filecontents*} \setmainfont[FeatureFile={frnd.fea}, ItalicFont={FreundschaftsKursivA}] {FreundschaftsAnt} \begin{document} fine flowers \end{document} Notice that you don’t have to say RawFeature={+liga}, because fontspec enables that feature by default. Hermecito is a font with neither liga nor sups defined, though it has ligatures and superior figures. Its small caps are adversely affected by the kind of fix used for Freundschafts Antiqua, but a more verbose approach works: Skip code block \documentclass{article} \usepackage{filecontents,fontspec,realscripts} \begin{filecontents*}{herm.fea} languagesystem DFLT dflt; languagesystem latn dflt; feature liga { sub \f \f by \ff; sub \f \i by \fi; sub \f \l by \fl; 266

sub \f \f \i by \ffi; sub \f \f \l by \ffl; } liga; feature sups { sub \zero by \zerosuperior; sub \one by \onesuperior; sub \two by \twosuperior; sub \three by \threesuperior; sub \four by \foursuperior; sub \five by \fivesuperior; sub \six by \sixsuperior; sub \seven by \sevensuperior; sub \eight by \eightsuperior; sub \nine by \ninesuperior; } sups; \end{filecontents*} \setmainfont[FeatureFile={herm.fea}, SmallCapsFont={HermecitoSpecial SC}, RawFeature={+liga}, SmallCapsFeatures={RawFeature={-liga}}] {HermecitoSpecial} \begin{document} finest,\footnote{One} fluffiest\footnote{Two} felines\footnote{Three} \end{document}

Answer by textnik The kerning between two letter can be modified using this feature file: mykern.fea languagesystem DFLT dflt; languagesystem latn dflt; feature kern { pos \V \A -800; } kern; 267

The unit is em/1000.

Tags: fonts (Prev Q) (Next Q)

Q: Accent positioning on ’oe’ character with feature file in fontspec Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q), opentype (Prev Q) (Next Q) There is no accented glyph for the ’oe’ character in Linux Libertine. When trying to form this character, the (acute) accent is centred over the ’e’ half. I’m trying to get the accent over the centre of the whole ligature. I have tried to add a feature file to position the accent but have not got it to do anything yet. I wonder if my syntax is at fault - or anything else. This is the minimal test I am using (with 2 ways of naming the character) with lualatex: \documentclass{article} \usepackage{fontspec} \setmainfont[FeatureFile=linlib.fea,RawFeature=+mlig;]{Linux Libertine O} \begin{document} \'{\oe} \'œ \end{document} And the feature file is: Skip code block #linlib.fea languagesystem DFLT dflt; languagesystem latn dflt; lookup markMarkPositioninglookup100 { lookupflag 0; markClass [\acutecomb \uni0341 ] @TOP_MARK; pos base [\oe ] mark @TOP_MARK; 268

} markMarkPositioninglookup100; feature mlig { script DFLT; # tested with and without these script/language lines language latn dflt ; lookup markMarkPositioninglookup100; } mlig; I have also tried the code for accenting a ligature instead: lookup markLigPositioninglookup100 { lookupflag 0; markClass [\acutecomb \uni0341 ] @TOP_MARKS; position ligature oe

# no mark above the 'o' half ligComponent # specify mark for 'e' half mark @TOP_MARKS # mark above left side of 'e' ; } markLigPositioninglookup100; All to no avail: the accent continues firmly centred over the ’e’. Any ideas? Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q), opentype (Prev Q) (Next Q) User: bernard

Answer by topskip You can use kerning in the feature file if you don’t mind writing the glyph like this ´œ: \documentclass{article} \usepackage{fontspec} \setmainfont[FeatureFile=linlib.fea,RawFeature=+mlig;]{Linux Libertine O} \begin{document} hell´œworld \end{document}

269

with this feature file: languagesystem DFLT dflt ; languagesystem latn dflt ; feature kern { position acute oe ; } kern;

Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q), opentype (Prev Q) (Next Q)

Q: Replacing greek glyphs in math mode Tags: fonts (Prev Q) (Next Q), pdftex (Prev Q) (Next Q), math-mode (Prev Q) (Next Q) I want to switch fonts, away from computer modern. I’m pretty sure that I will end up with a mixture of fonts. I can’t provide a full list of required features, but Linux Libertine’s feature set pretty much covers it. It is, at the moment, my base font for text work, together with Linux Biolinum. I need to adjust the math glyphs, though. They are still taken from the cm fonts and obviously don’t fit. As a start, I want to use those provided by GFS, like GFS Bodoni (too playful), or GFS Didot (all available as OTF). To achieve this glyph replacement, I started with one of the mathastext examples:

270

Skip code block \documentclass{article} \usepackage[T1]{fontenc} \renewcommand{\rmdefault}{bodoni} \usepackage[LGRgreek,defaultmathsizes,italic]{mathastext} \usepackage{libertine} \let\varphi\phi \linespread{1.06} \begin{document} ff fi fj fi ffj fl ffl äÄ öÖ üÜ ß\\ 01234567890\\ \begin{equation} abcdefghijklmnopqrstuvwxyz \end{equation} \begin{equation} \alpha \beta \gamma \delta \end{equation} \end{document} This compiles without any errors, and the math glyphs are replaced by those from GFS Bodoni, I get ligatures, correct Umlauts (the next problem arises here: LL provides an alternative O-umlaut, which I prefer). However, I don’t know how to access text figures from either LL or GFS Bodoni, while both provide them. My plan was to translate the above mwe to valid code for LuaLaTeX, gaining more control over the font selection. I failed: \documentclass{article} \usepackage[no-math]{fontspec} \renewcommand{\rmdefault}{bodoni} \usepackage[LGRgreek,defaultmathsizes,italic]{mathastext} \setmainfont{Linux Libertine O} \setsansfont{Linux Biolinum O} This sets mathnormal, mathrm, mathbf and mathit to computer modern (bad), but uses greek glyphs (which is good). The symbols used are still taken from the CM fonts, but I have not yet tried to replace them. I will 271

need to, because the default int-symbol’s terminals are - as an example ball-shaped. I then found the unicode-math package, but from what I read it is meant to be used for fonts which provide a full unicode math alphabet, which the GFS fonts do not. I tried to use unicode-math, but with less success than with the examples given above. Ultimately, I need a font selection procedure which is not hacked to fit one specific situation. I want to see how the different glyphs work together on the same page, and I might even buy a font that suits the text and its purpose, and not the technical limitations caused by my lack of skill. How can I develop a procedure of selecting fonts and glyphs that is robust and gives me the required flexibility? Is unicode-math the way to go?

Regarding \setmainfont instead of \renewcommand: I now used \documentclass{article} \usepackage{fontspec} \setmainfont[% ]{GFSBodoni} \usepackage[LGRgreek,defaultmathsizes,italic]{mathastext} as you suggested, with and without the no-math option for fontspec, and lualatex complains:

! Font \LGR/GFSBodoni(0)/m/it/7=grmn0700 at 7pt not loadable: metric data not foun ! Font \LGR/GFSBodoni(0)/m/it/5=grmn0500 at 5pt not loadable: metric data not foun These errors occur in \begin{equation} abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ \end{equation} This could either be caused by my usage of the font or by an error in my miktex 2.9 installation. However, a pdf is produced, with the following features: • The main fonts are GFS Bodoni,

272

• The greek glyphs in math mode are upright, not CM anymore, but not to be found in the GFS Bodoni Specimen sheet either. I don’t know where they come from. The preamble above is what I used, it is directly followed by \begin{document}. I then downloaded the otf files from the GFS website, and told fontspec to use them directly. I even renamed them to make sure that lualatex does not find any other Bodoni files elsewhere: \setmainfont[% ItalicFont=GFS-Bodoni-Italic.otf, BoldFont=GFS-Bodoni-Bold.otf, BoldItalicFont=GFS-Bodoni-Bold-Italic.otf ]{GFS-Bodoni.otf} I’m puzzled. I’ll now start trying the same thing with unicode-math, as you suggested.

unicode-math: After switching back and forth between different combinations of options, this is what I first came up with: Skip code block \documentclass{article} \usepackage{unicode-math} \setmathfont{XITS Math} \setmainfont{Linux Libertine O} \setsansfont{Linux Biolinum O} \setmathfont[ math-style=ISO, range=\mathit/{greek,Greek}, ]{GFSBodoni-Italic} \setmathfont[ math-style=ISO, range=\mathrm/{greek,Greek}, ]{GFSBodoni} Greek glyphs are now replaced, as intended. I can change the latin characters to Linux Libertine with the same trick, using two new blocks and {latin,Latin}

273

in the range option. My original question has been answered, in the sense that I was encouraged to use unicode-math. Thanks Ulrike! However, the quest goes on. Using a unicode math font left me with undesired figures, which I could also replace by figures from GFS Bodoni or Linux Libertine. Unfortunately, none of the following ideas work (the first is taken from the unicode-math documentation): Skip code block \setmathfont[ math-style=ISO, range=\mathit/{num}, ]{Linux Libertine O} \setmathfont[ math-style=ISO, range=\mathrm/{num}, ]{Linux Libertine O} \setmathfont[ math-style=ISO, range=\mathit/{"0030-"0039}, ]{Linux Libertine O} \setmathfont[ math-style=ISO, range=\mathrm/{"0030-"0039}, ]{Linux Libertine O} A major drawback is that I need to use a unicode math font, as above. My choice is at the moment limited to XITS, Asana Math, and (partially) Neo Euler. Neo Euler seems to have problems with scaling parentheses. Apart from that, I don’t really like any of these choices, judging just by the more prominent math symbols (like int, parentheses, n-ary sum and n-ary product sign), but that’s not the point of this question. Tags: fonts (Prev Q) (Next Q), pdftex (Prev Q) (Next Q), math-mode (Prev Q) (Next Q) User: christoph 274

Answer by ulrike-fischer In your lualatex example the \renewcommand{\rmdefault}{bodoni} won’t work. It will look for an eu2bodoni.fd which doesn’t exist. Switch to the font you want mathastext to pick up by using (as described in documentation) a suitable \setmainfont before loading mathattext. Apart from this: The font selection depends a lot of the actual font. It is rather easy to replace the font for letters and numbers, but when it comes to symbols you need one or more fonts which contains them and you will perhaps have to adjust various fontdimens. If you really want to use another open type font for the symbols your best bet is at my opinion unicode-math, but it can’t do wonders if a symbol doesn’t exist: \documentclass{article} \usepackage{unicode-math} \setmainfont{Arial} \setmathfont{Arial} \begin{document} $ a = \sin{0} \int \boxtimes \mp$ \end{document}

Tags: fonts (Prev Q) (Next Q), pdftex (Prev Q) (Next Q), math-mode (Prev Q) (Next Q)

Q: LuaTeX cannot find existing font Tags: fonts (Prev Q) (Next Q), errors (Next Q) My Fedora 17 LuaLaTeX (2012) system just keeps complaining about some particular (of course existing) font not existing. It can’t spit out any PDF from a TeX file using that font. This is the error I am getting: !LuaTeX error: cannot find OpenType font file for reading () ==> Fatal error occurred, no output PDF file produced! 275

I am 100% positive the otf font file exists and that the path I am giving to setmainfont is correct. After perusing TeX StackExchange searching for help, I couldn’t find any recommendation that worked. Can anyone help? Tags: fonts (Prev Q) (Next Q), errors (Next Q) User: escudito

Answer by escudito I just found a solution. It turned out it was all about cleaning my LuaTeX font cache.

Try that if you face the same problem. Go to your home folder. Activate viewing of hidden files (Ctrl+H). Look for .texlive2012/texmf-var/luatex-cache/generic/fonts/o and delete the .lua file(s) that more closely match your ”existing but not found” fontname. That did the trick in my case, and forever. I suppose an interrupted PDF compilation was the culprit.

Tags: fonts (Prev Q) (Next Q), errors (Next Q)

Q: Sans-serif to go with EB Garamond (no math)? Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q) Suggestions for a good sans-serif font to go with (complement) EB Garamond? Math and non-Western European support are not required. Text is fiction, not academic or scientific. English with an occasional word or phrase in French.

276

I’m using LuaLaTeX from TexLive 2013 on Windows 7 but that should not matter. Too many choices, too little time. Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q) User: bill-meahan

Answer by willadams Assuming the usage will be for headers or elements like folios, my choice would be Optima, which has a classical structure and so won’t clash too much. If that’s not to your liking, Syntax is a choice advocated on Typophile for this sort of thing, but its higher x-height would require some scaling down.

Answer by christian-clason If you don’t mind an organic sans serif, you could use Linux Biolinum which is part of the libertine package; Libertine is a more modern (but still classical) typeface than Garamond, but the pairing still works rather well in my opinion (and if you want to pair a Garalde typeface with a sans serif, you probably don’t care that much about period accuracy) -- although I wouldn’t use bold sans (a double anachronism) for headers:

\documentclass{article} \usepackage[sf,scale=0.95]{libertine} % sets biolinum as sf only \usepackage{ebgaramond} \begin{document} \section*{\sffamily\mdseries Lorem Ipsum Redux} Cras viverra metus rhoncus sem. \textsf{Nulla et lectus vestibulum} urna fringilla \end{document}

The current libertine package automatically uses otf by loading fontspec if the document is compiled using xelatex or lualatex, but the above works 277

using pdflatex as well. If you prefer a more classical sans serif, or really would like to use bold sans, you can try Pablo Impallari’s Quattrocento Sans: \usepackage[sf,scaled=0.9]{quattrocento} ... \section*{\sffamily Lorem Ipsum Redux}

I think the typeface is okay for headings even in bold, but too wide to use in the text body.

Answer by joseph Another good choice could be Myriad or Frutiger. Myriad and Minion come with Adobe Reader, and work quite well together (see What best combination of fonts for Serif, Sans, and Mono do you recommend?). There are plenty of nice choices, though. If you don’t need bold, Calluna Sans is free, as well as Fontin Sans.

EB Garamond With Myriad Pro

278

Minion and Myriad (bold)

Minion and Myriad (regular):

Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q)

Q: uneven line spacing Tags: fonts (Prev Q) (Next Q) This is something that is already annoying me for quite a while. (I use LuaLaTeX) The line spacing of the Arabic text is uneven (see pic and/or MWE below). In particular, I think, lines 2, 7, and 10. It would very unpleasant if a book got printed like this. I use Khaled Hosny’s font Amiri Font -- but it’s not the font’s fault. I also get this with Microsoft’s Arabic Typesetting, for example. Nonetheless, I contacted Khaled (because I knew him from TeX.sx) and he said:

279

”This may be due to the way TeX calculates line spacing, lines with high/deep glyphs will cause bigger line spacing. Since Arabic prefers more generous interline spacing than Latin, the solution is usually to make the line spacing big enough by default. If this does not suit you (e.g. the main text is in Latin script), then I think there are ways to force TeX to do fixed line spacing (I don’t use LaTeX my self, but in ConTeXt I just set the text on a grid).” So he suggests two solutions, I make three out of them: 1. increase the line spacing of all text (i.e. Arabic and Latin) -- not suitable, but maybe: 2. increase the line spacing of Arabic text only 3. force fixed line spacing of all text Any ideas of how to accomplish this? Any further ideas? Pic (looks better than here displayed when you download it):

280

MWE: Skip code block % !TEX TS-program = lualatex \documentclass[paper=a4,fontsize=11pt,DIV=calc]{scrartcl} \usepackage{fontspec} \setmainfont[Ligatures=TeX]{Times New Roman} 281

\newfontfamily\arabicfont[Script=Arabic,Numbers=Arabic]{Amiri} \usepackage{csquotes} \newcommand{\arabtext}[1] % Arabic inside LTR {\bgroup\luatextextdir TRT\arabicfont #1\egroup} \newcommand{\aq}[2] % {\blockquote{\arabtext{#1\hfill}\\{#2}}} \begin{document}

\aq{����� �� ��� ������� ����������� ���� �� ���� ��� ��� ����� ���������� ������ ���������� ����� ������ �� ������ �� ����� �� ��� {Facientes autem elementa esse plura uno, ut Empedocles et Anaxagoras et Leucippus \end{document} Tags: fonts (Prev Q) (Next Q) User: clinteastwood

Answer by clinteastwood Today I returned to this question which I could not previously solve to my full satisfaction. But today, while exploring once more barbara beeton’s suggestion in her very first comment, I could find a solution. Setting the value of \lineskiplimit to -\maxdimen forces LaTeX to adopt a single fixed line height throughout the document. On this basis, then, I can increase the line height of a given paragraph through changing the value of \baselinestretch, for example: \renewcommand{\baselinestretch}{1.50}\normalsize. However, the Latin text underneath the quotation in my example would also have the same increased line height (which would be too high for Latin text). So I turned my command \aq (which before consisted of one \blockquote command for one block quote) into a command \aqq (which now consist of two \blockquote commands for two blockquotes to which I can apply \baselinestretch individually with a reduced space between them). This is sofar the best solution to my issue. I will have to see how it turns out in the end. When I apply it to my entire document. But the particular 282

question seems to be more or less answered now. A grid in Adobe Acrobat with the height of 20,33 pt confirms this:

MWE: Skip code block % !TEX TS-program = lualatex \documentclass[paper=a4,fontsize=11pt,DIV=16]{scrartcl} \usepackage{fontspec} \setmainfont[Ligatures=TeX]{Times New Roman} \newfontfamily\arabicfont[Script=Arabic,Numbers=Arabic]{Amiri} \usepackage{csquotes} \newcommand{\arabtext}[1] % Arabic inside LTR {\bgroup\luatextextdir TRT\arabicfont #1\egroup} \newcommand{\aq}[2] % {\blockquote{\arabtext{#1\hfill}\\{#2}}} % The magic begins here: 283

\lineskiplimit=-\maxdimen \newcommand{\myvariablelineheight}[1]% {\renewcommand{\baselinestretch}{#1}\normalsize} \newcommand{\aqq}[2] % {\blockquote{\myvariablelineheight{1.5}\arabtext{#1\hfill}}\vspace{-2em}\block \begin{document}

\aq{����� �� ��� ������� ����������� ���� �� ���� ��� ��� ����� ���������� ������ ���������� ����� ������ .� ������ �� ����� �� ��� {Facientes autem elementa esse plura uno, ut Empedocles et Anaxagoras et Leucippus

\aqq{����� �� ��� ������� ����������� ���� �� ���� ��� ��� ����� ���������� ������ ���������� ����� ������ .� ������ �� ����� �� �� {Facientes autem elementa esse plura uno, ut Empedocles et Anaxagoras et Leucippus \end{document}

Tags: fonts (Prev Q) (Next Q)

Q: How can I replace a character (zero)? Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q), pdftex (Prev Q) (Next Q) Is it possible to replace characters in pdflatex? I use the Minion Pro and Myriad Pro font and the zero looks like a small ’O’. I want to replace the zero by a zero with a dot or slash in the middle (Inserting slashed zero in non-OpenType supporting LaTeX). Is it possible to replace the character globally (I just want to write 0 instead of something like \zero)? Is it possible in pdflatex or should I switch to lualatex (I have no experience in Lualatex but I have heard it has better font handling)? Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q), pdftex (Prev Q) (Next Q) User: user4811 284

Answer by mico If switching to LuaLaTeX is something you’re considering doing anyway, then you’ll find that using a ”slashed zero” is very straightforward: it’s a simple option provided by the command \setmainfont (and \setsansfont) of the fontspec package.

Skip code block % !TEX TS-program = lualatex \documentclass{article} \usepackage{fontspec} \setmainfont[Numbers=SlashedZero]{Minion Pro} \setsansfont[Numbers=SlashedZero]{Myriad Pro} \begin{document} Minion Pro: 1001 007 \sffamily Myriad Pro: 1001 007 \end{document} This program can be run under XeLaTeX as well. Incidentally, do note that the slashed zeros in the example above are being produced in text mode. There is apparently no such thing as a unicode-compliant slashed zero in math mode. Aside: The most recent version -- released within just the past few days -- of the luaotfload package (which is loaded by fontspec) contains at least one serious bug that makes it crash with a cryptic and fairly useless error message. If you have TeXLive2013 on your system -- sorry, I don’t have MikTeX and thus don’t know what MikTeX users should do -- and you’ve recently run the TeXLive Manager program to update your distribution’s packages, you can

285

revert to the previous version of luaotfload by executing the command sudo tlmgr restore luaotfload 31286 at a command prompt. Hopefully, a bug fix for this important package will be pushed to the CTAN soon.

Answer by fran One option with pdflatex (and without Minion font, sorry I do not have this font installed) for small chunks of simple text (without any LaTeX command) could be the package xstring: Skip code block \documentclass{article} \usepackage{xstring} \usepackage{mathtools} \newcommand\zero{\rlap{0}/} \begin{document} \StrSubstitute{% 102030 is a big number But 1020030004000 is bigger }{0}{\zero} \end{document} Edit As Mico commented, \rlap{0}/ is not a very beautiful slashed zero, but the tuning of the slash position is not easy inside a string substitution. An easy alternative could be $\emptyset$ but unfortunately is clearly bigger than the normal 0. But it is possible to select a character much more similar: Skip code block \documentclass{article} \usepackage{xstring} \font\zerofont = cmsy7 at 9.3pt 286

\newcommand\zero{{\zerofont \char 59}} \begin{document} \StrSubstitute{% 102030 is a big number But 1020030004000 is bigger }{0}{\zero} Zeroes comparison: $\emptyset${\zerofont \char 59}0$\rlap{0}/$ \end{document}

Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q), pdftex (Prev Q) (Next Q)

Q: How to use fakeslant as slanted but not italic font with fontspec? Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q) Using fontspec with Luatex it is possible to create a fake slant and use that as italic should no italics be around: \setmainfont[ AutoFakeSlant=0.15 ] {FontName}

287

However, also if an italic version exist this faked slant will be used both for \itshape and \slshape. How can I keep using the shipped italic font defined by the ItalicFont= parameter to \setmainfont but use fake slant for \slshape? Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q) User: jonalv

Answer by egreg An example is Linux Libertine, that has no slanted version: Skip code block \documentclass{article} \usepackage{fontspec} \setmainfont[ SlantedFont={Linux Libertine O}, SlantedFeatures={FakeSlant=0.15}, BoldSlantedFeatures={FakeSlant=0.15}, ]{Linux Libertine O} \begin{document} \textit{abc}\textsl{abc}\textbf{\textsl{abc}} \end{document}

Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q)

288

Q: Embedding Type 1C fonts using LuaLaTeX Tags: fonts (Prev Q) (Next Q), file-size (Prev Q) (Next Q) As pointed out in the answer to PDF file size with LuaLaTeX vs XeLaTeX, the difference between using Type 1 and Type 1C fonts in two documents made a big difference in file size. File size is important in the PDF files I’m working with. So my question is can you force LuaLaTeX to embed a Type 1C font instead of Type 1? This is something XeLaTeX can do (and in the case of the question cited above, did automatically). The font I’m working with is Gill Sans MT (I believe it comes with Adobe CS). While I’m not opposed to changing fonts, I’d still like to know how LuaLaTeX decides how to embed fonts and how it can be changed. Tags: fonts (Prev Q) (Next Q), file-size (Prev Q) (Next Q) User: scribblemacher

Answer by scottku I do not know how to make lualatex output Type 1C fonts. However, you may be able to use ps2pdf to convert a PDF containing Type 1 fonts to another PDF containing Type1C fonts. You should carefully choose parameters to ps2pdf. For example: Skip code block newell:~/latex/help $ du -h plain.pdf 60K plain.pdf newell:~/latex/help $ pdffonts plain.pdf name type ------------------------------------ ----------------BZAAVM+NimbusSanL-Bold Type 1 YCENSD+LMMathItalic12-Regular Type 1 KDKAQG+CMSS12 Type 1 IDSSCN+NimbusSanL-Regu Type 1 ZIJBJP+NimbusSanL-ReguItal Type 1

289

emb --yes yes yes yes yes

sub --yes yes yes yes yes

uni object ID --- --------no 17 0 no 18 0 no 19 0 no 20 0 no 21 0

SEAJVD+NimbusSanL-BoldItal Type 1 yes yes no 22 0 SQTJQN+LMMathSymbols10-Regular Type 1 yes yes no 23 0 newell:~/latex/help $ ps2pdf -dPDFSETTINGS=/prepress -dAutoRotatePages=/None -dEmb newell:~/latex/help $ du -h new.pdf 36K new.pdf newell:~/latex/help $ pdffonts new.pdf name type emb sub uni object ID ------------------------------------ ----------------- --- --- --- --------OJEPRS+NimbusSanL-BoldItal Type 1C yes yes no 23 0 OJIXHX+LMMathSymbols10-Regular Type 1C yes yes no 25 0 CYORGJ+NimbusSanL-Bold Type 1C yes yes no 13 0 MZVUTG+LMMathItalic12-Regular Type 1C yes yes yes 15 0 PWIYDZ+CMSS12 Type 1C yes yes no 17 0 QBTHSF+NimbusSanL-Regu Type 1C yes yes no 19 0 XMYGAL+NimbusSanL-ReguItal Type 1C yes yes no 21 0

Answer by taco-hoekwater Luatex never writes Type1C fonts. You will get smaller pdfs if you use OpenType/TrueType fonts instead of Type1 (luatex writes CIDType0 fonts for those) but otherwise pstopdf is the alternative. Unless someone supplies a patch, this situation is unlikely to change.

Tags: fonts (Prev Q) (Next Q), file-size (Prev Q) (Next Q)

Q: Reduce compilation time for opentype fonts (otf) Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q) I have some opentype fonts (otf) which I use with fontspec. Everything works fine. During the compilation LuaLaTeX load the otf-files in a temporary file. For example: 290

(load: /home/marco/.texlive2011/texmf-var/luatex-cache/generic/fonts/otf/temp-FONT Is it possible to install the font via LuaLaTeX or fontspec that the compilation will be reduced? I know the script otfins.py but maybe there is an easier way. Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q) User: marco-daniel

Answer by topskip Short answer: no you can’t. Long answer: fontspec uses luaotfload to load fonts. And luaotfload (which is based on ConTeXt’s fontloader) needs a lot of information when you are in node-mode. This information is stored in big Lua tables that get loaded (created) when processing the document. And processing these tables take time. That said: it is possible to create your own font loader in LuaTeX which speeds up things. When you restrict yourself to the TeX way of handling fonts (no contextual ligatures AFAIK, no language dependent font usage), the required table is much smaller and therefore when using a cache, loading a font should only take a fraction of the time it takes with luaotfload.

Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q)

Q: Measuring the true height of a character Tags: fonts (Prev Q) (Next Q), xetex (Prev Q) (Next Q) Suppose you have got a character that sits above the reference point. When you measure its height, the empty space above reference point gets also included in its height measurement but that is not the true height of the character itself. Thus How do you measure the correct height of a character. To see this better, please see the output of the following document: 291

\documentclass{minimal} \usepackage{fontspec} \usepackage{showcharinbox} \newfontfamily\testfont{XB Zar} \begin{document} \begin{center} \ShowCharInBox{\fontsize{500}{510}\testfont \char"0640} \end{center} \end{document} XB Zar font can be obtained from here. Tags: fonts (Prev Q) (Next Q), xetex (Prev Q) (Next Q) User: vafa-khalighi

Answer by egreg With XeTeX the primitive \XeTeXglyphbounds is available. Skip code block \documentclass{article} \usepackage{fontspec} \newfontface{\geeza}{Geeza Pro} \begin{document} \edef\gid{\the\XeTeXcharglyph`- } Top: \the\XeTeXglyphbounds2 \gid Bottom: \the\XeTeXglyphbounds4 \gid

-\,\vrule width\dimexpr\fontcharwd\font`- -\XeTeXglyphbounds1 \gid -\XeTeXglyphbounds3 \gi height \XeTeXglyphbounds2 \gid depth \XeTeXglyphbounds4 \gid \,\vrule width \fontcharwd\font`- height \fontcharht\font`- depth \fontchardp\font`292

\ Real height \the\dimexpr\XeTeXglyphbounds2 \gid + \XeTeXglyphbounds4 \gid\relax \edef\gid{\the\XeTeXcharglyph`; }

;\,\vrule width\dimexpr\fontcharwd\font`- -\XeTeXglyphbounds1 \gid -\XeTeXglyphbounds3 \gi height \XeTeXglyphbounds2 \gid depth \XeTeXglyphbounds4 \gid \,\vrule width \fontcharwd\font`; height \fontcharht\font`; depth \fontchardp\font`; \ Real height \the\dimexpr\XeTeXglyphbounds2 \gid + \XeTeXglyphbounds4 \gid\relax {\geeza \edef\gid{\the\XeTeXcharglyph"0640 }

\char"0640 \,\vrule width\dimexpr\fontcharwd\font"0640 -\XeTeXglyphbounds1 \gid -\XeTeXglyphbounds3 height \XeTeXglyphbounds2 \gid depth \XeTeXglyphbounds4 \gid \,\vrule width \fontcharwd\font"0640 height \fontcharht\font"0640 depth \fontchardp\font" \xdef\therealheight{\the\dimexpr\XeTeXglyphbounds2 \gid + \XeTeXglyphbounds4 \gid\ }\ Real height \therealheight \end{document}

293

In the examples each character is followed by a rule drawn using the “real” dimensions and by a rule using the bounding box data. The first two lines show how the bounding box data are represented for the hyphen.

Tags: fonts (Prev Q) (Next Q), xetex (Prev Q) (Next Q)

Q: LuaTeX with unicode-math, how to get the font id of current math font Tags: fonts (Prev Q) (Next Q), unicode-math (Prev Q) (Next Q) How can I query informations about the current math font? I tried the following in a document using unicode-math and Cambria Math font Skip code block \documentclass{article} \usepackage{unicode-math} \setmathfont{Cambria Math}

294

\begin{document} Try to get math font name inside math mode. \[ \directlua{ local font = fonts.identifiers[font.current()] local fullname = font.fullname tex.sprint(fullname) } \] \end{document} However, it is the font name of surrounding text font being printed in the

math font, as seen in the following picture. It seems that font.current() returns the current text font id instead of the math font even the code is inside math mode. Next, I serialized the fonts.identifiers table and get the id of math font. I replaced font.current() with an explicit number, 28 in this example, and the above code print the math font name correctly, as seen in the following.

So I guess the math font does have an ID in the fonts.identifiers table. But how do I get this ID automatically? Tags: fonts (Prev Q) (Next Q), unicode-math (Prev Q) (Next Q) User: yan-zhou

295

Answer by egreg There is no concept of ”current math font” in TeX and the same is true for LuaTeX and XeTeX. The symbols are typeset using fonts assigned at the end of the formula using the concept of math family. However, it’s possible to access at the math font chosen via \setmathfont making it the current text font in a slighly tricky way: Skip code block \documentclass{article} \usepackage{unicode-math} \setmathfont{XITS Math} \begin{document} \sbox0{$$}\the\textfont2 \directlua{ local font = fonts.identifiers[font.current()] local fullname = font.fullname tex.sprint(fullname) } \end{document} This will print ”XITS Math-2”. This is because \the\textfont2 produces a font identifier that makes the font in family 2 the current text font. In traditional TeX, \textfont2 is the font used for the most common symbols in text size; unicode-math uses it for all the known symbols, but for technical reasons it has to maintain a copy of it also as \textfont3, hence the suffix ”2”. The \sbox0{$$} is needed because LaTeX doesn’t actually assign fonts to math families until it has to typeset a formula. It would be possible also to say \makeatletter\[email protected]\makeatother because \[email protected] is the command used to assign fonts to families based on the current context. Other Lua facilities can be used to access the font number in the internal 296

tables, I guess.

Tags: fonts (Prev Q) (Next Q), unicode-math (Prev Q) (Next Q)

Q: Select a font via luaotfload on lua side Tags: fonts (Prev Q) (Next Q) I’m creating a glyph node (a capital A) on lua side: \directlua{% n = node.new('glyph') n.font = font.current() n.char = 65 % ASCII code for capital A } I know how to select current font (font.current()). How can I access other fonts that are in luaotfload database (say texgyreschola-regular.otf as an example)? Tags: fonts (Prev Q) (Next Q) User: cjorssen

Answer by philipp-gesang How can I access other fonts that are in luaotfload database (say texgyreschola-regular.otf as an example)? In order to use a font with Luatex, it needs to be defined first. The fontloader has a function fonts.definers.read() for that which has the same signature as the define_font callback. Its font lookup calls into Luaotfload’s font index functionality so you can pass it any valid definition string. On success, you will receive an object that satisfies the description in the Luatex manual, ch. 5 “Font structure” so you can feed it directly into

297

font.define(). It returns the font id that was assigned by TeX to this particular font which you can use in the situation you describe. An example that assigns the font in a callback would be: Skip code block local glyph_t

= nodes.nodecodes.glyph

local fontify = function (id) return function (hd) for n in node.traverse (hd) do if n.id == glyph_t then n.font = id end end return hd end end local main = function () local tfmdata = fonts.definers.read ("file:iwona-regular.otf:mode=base", 42*2^16) local id = font.define (tfmdata) luatexbase.add_to_callback("pre_linebreak_filter", fontify (id), "userdata.stackexchange.fontify") tex.sprint "some text" end return main () -- vim:ft=lua:sw=2:et The entire TeX document: \input luaotfload.sty \directlua {dofile "\jobname.lua"} \bye

298

Tags: fonts (Prev Q) (Next Q)

Q: How to get \copyright when mixing T1 fonts and fontspec? Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q) This example: Skip code block \documentclass{minimal} 299

\usepackage{fontspec} \usepackage[T1]{fontenc} \usepackage[osf]{mathpazo} \begin{document} \copyright 2011 \end{document} Gives: ! LaTeX Error: Command \copyright unavailable in encoding T1. See the LaTeX manual or LaTeX Companion for explanation. Type H for immediate help. ... l.9 \copyright 2011 ? What can I do to get a copyright symbol? Is there another command I should use perhaps? Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q) User: jonalv

Answer by leo-liu Quick solution: Use \textcopyright instead of \copyright. Now the copyright sign will be ouput in cmsy font, and there will be a font warning. This approach is somewhat bad because it produces a font substitution warning, and the use of CM fonts. The advantage is, you don’t need to modify the code much. And the font is exacly Palatino with its mathematical support provided by PSNFSS bundle. 300

Quick solution 2: \renewcommand*\copyright{{% \usefont{EU1}{lmr}{m}{n}\textcopyright}} It use the sign in Latin Modern fonts. This prevents the warnings. And use LMR font for this sign. The font command can be changed as you wish. e.g. \fontfamily{lmr}\selectfont. textcomp package uses an old set of fonts, in TS1 font encoding.

Suggested solution: Skip code block \documentclass{minimal} \usepackage{unicode-math} \setmainfont[Ligatures=TeX,Numbers=OldStyle]{TeX Gyre Pagella} \setmathfont{Asana Math} \begin{document} Test \copyright 2011 \end{document} Now all fonts are changed to OpenType ones. The result is somewhat similar with pdfLaTeX + pxfonts package.

Answer by egreg I’d load mathpazo before fontspec; moreover fontenc isn’t needed, since you’ll want to set the fonts with fontspec. \usepackage[osf]{mathpazo} \usepackage{fontspec} 301

\setmainfont[Ligatures=TeX,Numbers=OldStyle]{TeX Gyre Pagella} \begin{document} \copyright 2011 \end{document}

Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q)

Q: Why is \setmainfont case sensitive with XelateX but not with LuaLaTeX? Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q), xetex (Prev Q) (Next Q) Consider the following MWE \documentclass{article} \usepackage{lipsum} \usepackage{fontspec} \setmainfont{tex Gyre Pagella} \begin{document} \lipsum[1] \end{document} If I compile it with LuaLaTeX all is fine. But, if I compile it with XeLaTeX I get the error Skip code block !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! ! ! fontspec error: "font-not-found" ! ! The font "tex Gyre Pagella" cannot be found. ! 302

! See the fontspec documentation for further information. ! ! For immediate help type H . !............................................... l.7 \setmainfont{tex Gyre Pagella} ? This is because I’ve written tex Gyre Pagella instead of TeX Gyre Pagella in the argument of \setmainfont. If I change it to TeX Gyre Pagella then XeLaTeX compiles it. Why this behavior? Do LuaLaTeX and XeLaTeX load different fontspec packages or there is something else that I’m missing? Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q), xetex (Prev Q) (Next Q) User: sterry

Answer by paul-gessler CW from the comments: luaotfload normalizes all names supplied by the font. Apart from lowercasing you can also leave out spaces if you wish. So, for XeLaTeX, spacing and casing are significant, while for LuaLaTeX, they are not. This is not engine-dependent, just how luaotfload (and, incidentally, ConTeXt) treat things. The rationale is simple: Font names are a horrible mess that will haunt you and your descendants to the fifth generation if you attempt to uncover a system behind them. Since capitalization of identifiers can vary even within a font family, the only sane approach is to eliminate it completely. For info about luaotfload read texdoc luaotfload and man 1 luaotfload-tool.

303

Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q), xetex (Prev Q) (Next Q)

Q: Problem with � (\cyrishrt) in LuaLaTeX Tags: fonts (Prev Q) (Next Q) Initially I’ve asked a different question, but digging up I’ve found a true reason. The problem occurs when Cyrillic letter � is used with maths in another font in the same paragraph. Here is the minimal example: \documentclass{minimal} \usepackage{fontspec} \setmainfont{Cambria} \begin{document} � $xy$ \end{document} The compilation stops and the error is following: error: ...s/MiKTeX 2.9 /tex/luatex/luaotfload/otfl-node-inj.lua:225: attempt to index local 'tm' (a nil value) . \newpage ...k \@nobreakfalse \everypar {}\fi \par \vfil \penalty -\@M l.6 \end{document} When they are in different paragraphs e.g. the document body is \begin{document} � $xy$ \end{document}

304

then there is no problem. Also there is no problem as well if I use the same math font e.g. with \usepackage{unicode-math} \setmathfont{Cambria Math} But still the compilation stops if I use a symbol from a different font (e.g. \Box from amssymb). UPD: I get the same problem with other accented letters, not only Cyrillic: à, �, �, �, �, � etc, except i. UPD2: Happens only with Cambria. Tags: fonts (Prev Q) (Next Q) User: georgiy

Answer by georgiy This was a problem with my Cambria font installation. In the Windows/Fonts folder, there were Cambria Italic.ttf, Cambria Bold.ttf, Cambria Bold Italic.ttf containing the corresponding fonts and Cambria.ttc containing both Cambria Regular and Cambria Math. So with bold and italic there was no problem, but somehow using regular lead to a problem when LuaLaTeX used Cambria Regular from Cambria.ttc. When I copied Cambria.ttf from Vista installation DVD and deleted luatex-cache folder, the problem had gone.

Tags: fonts (Prev Q) (Next Q)

Q: Why does LuaTeX not generate some fonts automatically, in contrast with TeX? Tags: fonts (Prev Q) (Next Q)

305

Consider the following example, using font lhr10 (texlive-lang-cyrillic package in debian): \font\myfont=lhr10 \myfont A \bye Compile it with LuaTeX: Skip code block $ dviluatex test.tex This is LuaTeX, Version beta-0.80.0 (TeX Live 2015/Debian) (rev 5238) restricted \write18 enabled. (./test.tex ! Font \myfont=lhr10 not loadable: metric data not found or bad.

\myfont l.2 \myfont ? Now compile it with TeX: Skip code block $ tex test.tex This is TeX, Version 3.14159265 (TeX Live 2015/Debian) (preloaded format=tex) (./test.tex kpathsea: Running mktextfm lhr10 mktextfm: Running mf-nowin -progname=mf \mode:=ljfour; mag:=1; nonstopmode; input This is METAFONT, Version 2.7182818 (TeX Live 2015/Debian) (preloaded base=mf)

kpathsea: Running mktexmf lhr10 mf: /usr/local/share/texmf/fonts/source/lh/lh-lcy/lhr10.mf: successfully generated (/usr/local/share/texmf/fonts/source/lh/lh-lcy/lhr10.mf (/usr/share/texlive/texmf-dist/fonts/source/lh/base/fikparm.mf (/usr/share/texlive/texmf-dist/fonts/source/public/cm/cmbase.mf) (/usr/share/texlive/texmf-dist/fonts/source/lh/base/lcyrbeg.mf) 306

(/usr/share/texlive/texmf-dist/fonts/source/lh/base/lkligtbl.mf) >> 10 >> "input cmr10" (/usr/share/texlive/texmf-dist/fonts/source/public/cm/cmr10.mf ) (/usr/share/texlive/texmf-dist/fonts/source/lh/lh-lcy/lhcodes.mf) (/usr/share/texlive/texmf-dist/fonts/source/lh/base/lcyrdefs.mf) (/usr/share/texlive/texmf-dist/fonts/source/lh/base/ldroman.mf (/usr/share/texlive/texmf-dist/fonts/source/lh/base/lxpseudo.mf) (/usr/share/texlive/texmf-dist/fonts/source/public/cm/romanu.mf [65] [66] [67] [68] [69] [70] [71] [72] [73] [74] [75] [76] [77] [78] [79] [80] [81] [82] [83] [84] [85] [86] [87] [88] [89] [90]) (/usr/share/texlive/texmf-dist/fonts/source/public/cm/romanl.mf [97] [98] [99] [100] [101] [102] [103] [104] [105] [106] [107] [108] [109] [110] [111] [112] [113] [114] [115] [116] [117] [118] [119] [120] [121] [122]) (/usr/share/texlive/texmf-dist/fonts/source/public/cm/greeku.mf [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10]) (/usr/share/texlive/texmf-dist/fonts/source/public/cm/romand.mf [48] [49] [50] [51] [52] [53] [54] [55] [56] [57]) (/usr/share/texlive/texmf-dist/fonts/source/public/cm/romanp.mf [36] [38] [63] [62]) (/usr/share/texlive/texmf-dist/fonts/source/public/cm/romspl.mf [16] [17] [25] [26] [27] [28]) (/usr/share/texlive/texmf-dist/fonts/source/public/cm/romspu.mf [29] [30] [31]) (/usr/share/texlive/texmf-dist/fonts/source/public/cm/punct.mf [33] [60] [35] [37] [39] [40] [41] [42] [43] [44] [46] [47] [58] [59] [61] [64] [91] [93] [96]) (/usr/share/texlive/texmf-dist/fonts/source/public/cm/accent.mf [18] [19] [20] [21] [22] [23] [24] [32] [94] [95] [125] [126] [127]) (/usr/share/texlive/texmf-dist/fonts/source/public/cm/romlig.mf [11] [12] [13] [14] [15]) (/usr/share/texlive/texmf-dist/fonts/source/public/cm/comlig.mf [34] [45] [92] [123] [124]) (/usr/share/texlive/texmf-dist/fonts/source/lh/base/lgcyru.mf (/usr/share/texlive/texmf-dist/fonts/source/lh/base/lgrusu.mf [128] [129] [130] [131] [132] [133] [134] [135] [136] [137] [138] [139] [140] [141] [142] [143] [144] [145] [146] [147] [148] [149] [150] [151] [152] [153] [154] [155] [156] [157] [158] [159] [240]) (/usr/share/texlive/texmf-dist/fonts/source/lh/base/lgt2comu.mf [246] [248] [242] [250] [244])) (/usr/share/texlive/texmf-dist/fonts/source/lh/base/lgcyrl.mf (/usr/share/texlive/texmf-dist/fonts/source/lh/base/lgrusl.mf [160] [161] [162] [163] [164] [165] [166] [167] [168] [169] [170] [171] [172] [173] 307

[174] [175] [224] [225] [226] [227] [228] [229] [230] [231] [232] [233] [234] [235] [236] [237] [238] [239] [241]) (/usr/share/texlive/texmf-dist/fonts/source/lh/base/lgt2coml.mf [247] [243] [249] [251] [245])) (/usr/share/texlive/texmf-dist/fonts/source/lh/base/lgcyrsym.mf [196] [252] [197] [255] [253] [254]) (/usr/share/texlive/texmf-dist/fonts/source/lh/base/lgcyracc.mf) (/usr/share/texlive/texmf-dist/fonts/source/lh/base/llvligtb.mf) (/usr/share/texlive/texmf-dist/fonts/source/lh/lh-lcy/lhliker.mf) ) ) ) (some charht values had to be adjusted by as much as 0.07101pt) Font metrics written on lhr10.tfm. Output written on lhr10.600gf (210 characters, 41768 bytes). Transcript written on lhr10.log. mktextfm: /usr/local/share/texmf/fonts/tfm/lh/lh-lcy/lhr10.tfm: successfully gener [1] ) Output written on test.dvi (1 page, 252 bytes). Transcript written on test.log. Why LuaTeX does not generate this font automatically? EDIT If we run dviluatex after the font is generated by tex, it works without problems. If we run luatex in pdf mode after the font is generated by tex (it gives the same ”metric data not found or bad” error if we do not generate the font with tex before), it gives this error: Skip code block This is LuaTeX, Version beta-0.80.0 (TeX Live 2015/Debian) (rev 5238) (./test.tex [1{/usr/local/share/texmf/fonts/map/pdftex/updmap/pdftex.map}]){/usr /share/texmf/fonts/enc/dvips/lm/lm-rm.enc} kpathsea: Running mktexpk --mfmode / --bdpi 72 --mag 1+0/72 --dpi 72 lhr10 mktexpk: Mismatched mode ljfour and resolution 72; ignoring mode. mktexpk: Can't guess mode for 72 dpi devices. mktexpk: Use a config file or option to specify the mode; see: mktexpk: http://tug.org/texinfohtml/kpathsea.html#Unable-to-generate-fonts kpathsea: Appending font creation commands to missfont.log. !LuaTeX error (file lhr10): Font lhr10 at 72 not found 308

==> Fatal error occurred, no output PDF file produced! If we specify \pdfpkresolution=600, it works without problems: This is LuaTeX, Version beta-0.80.0 (TeX Live 2015/Debian) (rev 5238) (./test.tex [1{/usr/local/share/texmf/fonts/map/pdftex/updmap/pdftex.map}]){/usr /share/texmf/fonts/enc/dvips/lm/lm-rm.enc} Fatal error occurred, no output PDF file produced! If I add the \starttext ... \stoptext and compile it using context instead of luatex, it works all right. So, at this point I am quite puzzled. How can I use the msbm10 font in plain LuaTeX? Edit: The problem was that I was using luatex from a ConTeXt installation. With luatex from TeXlive, it works all right. Thanks. Tags: fonts (Prev Q) (Next Q)

373

User: yann

Answer by topskip Note: you are not using ”plain”, but something that is related to ConTeXt. luatex-plain.tex is only in the ConTeXt distribution, and it surely has a very special way of dealing with fonts. If you really want plain TeX, then use plain TeX. Just call luatex foo.tex and you are fine. Even with the msbm10 font. If this answer is not what you are looking for, please write what you want to achieve.

Tags: fonts (Prev Q) (Next Q)

Q: Avoid update font name database by luaotfload Tags: fonts (Prev Q) (Next Q) I am using LuaLaTeX to typesetting documents with system fonts. Compiling needs much time to update the font database: luaotfload | Updating the font names database:. I think this update is not necessary, because I do not change the fonts every time. If my assumption is correct, is it possible to avoid this update? A minimal example that shows the problem: \documentclass[paper = a4]{scrartcl} \usepackage{blindtext, fontspec}

% Typewriter (\ttfamily) \setmonofont[BoldFont = VeraMoBd, ItalicFont = VeraMoIt, Scale = MatchLowercase]{V \begin{document} 374

\blinddocument \end{document} I used different fonts set by \setmainfont and \setsansfont, but only the mono-spaced VeraMono hangs on updating the font names database. The free font Bitstream Vera is available here. Tags: fonts (Prev Q) (Next Q) User: dirk

Answer by ulrike-fischer To sum up the discussion in the comments: luaotfload updated the font name databases at each run because the font names where wrong and so luaotfload couldn’t find the font by name in the database (it did find it in the end as VeraMono is the file name). The correct call is:

\setmonofont[BoldFont = BitstreamVeraSansMono-Bold, ItalicFont = BitstreamVeraSans The correct font name can be found e.g. in the font selection dialog of some other office application, or in the database created by luaotfload (otfl-names.lua with the older versions of luaotfload (TL2012/current miktex) and luaotfload-names.lua in TL2013). A list of fonts can printed as described in https://tex.stackexchange.com/a/ 14171/14200 (the actual code depends on the luaotfload version).

Tags: fonts (Prev Q) (Next Q)

Q: When using unicode math, the math glyphs disappear Tags: fonts (Prev Q) (Next Q), unicode-math (Prev Q) (Next Q)

375

Recently, I wanted to use unicode-math to introduce better distinguishable greek letters (e.g. boldface) at some point. However, I cannot seem to make things work. Here is my MWE: Skip code block \documentclass{standalone} \usepackage{unicode-math} % Must be loaded after amsmath. %\setmathfont{Asana Math} % No matter what I select here \setmathfont{XITS Math} \begin{document} $$ \alpha, \beta, \lambda $$ \end{document} No matter, which math font I choose, the greek letters are not shown and the log contains lines like: Missing character: There is no ript=latn;+trep;+tlig;"!

(U+1D6FC) in font "file:lmroman10-regular:sc

(ironically, my terminal does show the alpha). Why is the lookup being done in lmroman10-regular:sc (and how do I fix this)? edit: lualatex --version: This is LuaTeX, Version beta-0.80.0 (TeX Live 2016/dev) (rev 5238) Filelist: Skip code block standalone.cls ifluatex.sty ifpdf.sty ifxetex.sty xkeyval.sty xkeyval.tex standalone.cfg ass article.cls

2015/07/15 v1.2 Class to compile TeX sub-files standalone 2010/03/01 v1.3 Provides the ifluatex switch (HO) 2011/01/30 v2.3 Provides the ifpdf switch (HO) 2010/09/12 v0.6 Provides ifxetex conditional 2014/12/03 v2.7a package option processing (HA) 2014/12/03 v2.7a key=value parser (HA) 2015/07/15 v1.2 Default configuration file for 'standalone' cl 2014/09/29 v1.4h Standard LaTeX document class 376

size10.clo 2014/09/29 v1.4h Standard LaTeX file (size option) unicode-math.sty 2015/09/09 v0.8b Unicode maths in XeLaTeX and LuaLaTeX expl3.sty 2015/09/11 v6002 L3 programming layer (loader) expl3-code.tex 2015/09/11 v6002 L3 programming layer l3unicode-data.def 2015/07/20 v5676 L3 Unicode data l3pdfmode.def 2015/09/10 v5983 L3 Experimental driver: PDF mode ucharcat.sty 2015/08/23 v0.02 ucharcat for luaLaTeX (DPC) xparse.sty 2015/09/11 v6001 L3 Experimental document command parser l3keys2e.sty 2015/09/11 v6001 LaTeX2e option processing using LaTeX3 keys fontspec.sty 2015/07/22 v2.4d Font selection for XeLaTeX and LuaLaTeX luaotfload.sty 2014/08/10 v2.5-4 OpenType layout system luatexbase.sty 2013/05/11 v0.6 Resource management for the LuaTeX macro progr ammer luatex.sty 2010/03/09 v0.4 LuaTeX basic definition package (HO) infwarerr.sty 2010/04/08 v1.3 Providing info/warning/error messages (HO) etex.sty 2015/09/02 v2.4 eTeX basic definition package (PEB,DPC) luatex-loader.sty 2010/03/09 v0.4 Lua module loader (HO) luatexbase-compat.sty 2011/05/24 v0.4 Compatibility tools for LuaTeX luatexbase-modutils.sty 2013/05/11 v0.6 Module utilities for LuaTeX luatexbase-loader.sty 2013/05/11 v0.6 Lua module loader for LuaTeX luatexbase-regs.sty 2011/05/24 v0.4 Registers allocation for LuaTeX luatexbase-attr.sty 2013/05/11 v0.6 Attributes allocation for LuaTeX luatexbase-cctb.sty 2013/05/11 v0.6 Catcodetable allocation for LuaTeX luatexbase-mcb.sty 2013/05/11 v0.6 Callback management for LuaTeX fontspec-patches.sty 2015/07/22 v2.4d Font selection for XeLaTeX and LuaLaTeX fontspec-luatex.sty 2015/07/22 v2.4d Font selection for XeLaTeX and LuaLaTeX fontenc.sty eu2enc.def 2010/05/27 v0.1h Experimental Unicode font encodings eu2lmr.fd 2009/10/30 v1.6 Font defs for Latin Modern xunicode.sty 2011/09/09 v0.981 provides access to latin accents and many othe r characters in Unicode lower plane eu2lmss.fd 2009/10/30 v1.6 Font defs for Latin Modern graphicx.sty 2014/10/28 v1.0g Enhanced LaTeX Graphics (DPC,SPQR) graphics.sty 2014/10/28 v1.0p Standard LaTeX Graphics (DPC,SPQR) trig.sty 1999/03/16 v1.09 sin cos tan (DPC) graphics.cfg 2010/04/23 v1.9 graphics configuration of TeX Live pdftex.def 2011/05/27 v0.06d Graphics/color for pdfTeX 377

ltxcmds.sty 2011/11/09 v1.22 LaTeX kernel commands for general use (HO) fontspec.cfg catchfile.sty 2011/03/01 v1.6 Catch the contents of a file (HO) etexcmds.sty 2011/02/16 v1.5 Avoid name clashes with e-TeX commands (HO) fix-cm.sty 2015/01/14 v1.1t fixes to LaTeX ts1enc.def 2001/06/05 v3.0e (jk/car/fm) Standard LaTeX file filehook.sty 2011/10/12 v0.5d Hooks for input files unicode-math-luatex.sty lualatex-math.sty 2014/08/18 v1.4 Patches for mathematics typesetting with Lu aLaTeX etoolbox.sty 2015/08/02 v2.2a e-TeX tools for LaTeX (JAW) unicode-math-table.tex t3cmr.fd 2001/12/31 TIPA font definitions supp-pdf.mkii pdftexcmds.sty 2011/11/29 v0.20 Utility functions of pdfTeX for LuaTeX (HO) epstopdf-base.sty 2010/02/09 v2.5 Base part for package epstopdf grfext.sty 2010/08/19 v1.1 Manage graphics extensions (HO) kvdefinekeys.sty 2011/04/07 v1.3 Define keys (HO) kvoptions.sty 2011/06/30 v3.11 Key value format for package options (HO) kvsetkeys.sty 2012/04/25 v1.16 Key value parser (HO) epstopdf-sys.cfg 2010/07/13 v1.3 Configuration of (r)epstopdf for TeX Live Tags: fonts (Prev Q) (Next Q), unicode-math (Prev Q) (Next Q) User: choeger

Answer by egreg Without the varwidth option, standalone typesets the document in a horizontal box and there $$ just means an empty math formula. Thus \alpha, \beta and \gamma are being typeset in text mode. By a precise choice of the LuaTeX team, a math symbol in text mode doesn’t raise an error and tries to typeset the (character corresponding to the) symbol in the current font. In other words, you have discovered another good reason for never using $$ in LaTeX. With \[...\] you get a different error message: ! LaTeX Error: Bad math environment delimiter.

378

See the LaTeX manual or LaTeX Companion for explanation. Type H for immediate help. ... l.9 \] Not really very helpful, but perhaps it could lead you to a real solution. However, using \[...\] with the varwidth option will not give the wanted result. Here’s the right way: Skip code block \documentclass{standalone} \usepackage{unicode-math} % Must be loaded after amsmath. %\setmathfont{Asana Math} \setmathfont{XITS Math} \begin{document} $\displaystyle \alpha, \beta, \lambda $ \end{document}

Tags: fonts (Prev Q) (Next Q), unicode-math (Prev Q) (Next Q)

Q: Does lualatex embed fonts for compatibility? Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q) I am using fonts installed on my computer in LaTeX document as \documentclass{article} \usepackage{fontspec} \newfontfamily\fontx{Ubuntu} \begin{document} 379

The default font {\fontx New font} The default font \end{document} I create the pdf file with lualatex command. How custom fonts are embedded in the pdf document for the sake of compatibility? Readers probably does not have this custom font; does this make a problem in displaying the pdf document? My knowledge about fonts is very limited. Sorry if it is a basic question. I just want to be sure about the compatibility of my pdf document when using rare fonts, and how to guarantee the document compatibility in different systems. Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q) User: googlebot

Answer by topskip Fonts are always embedded, unless explicitly forced not to. Only the glyphs used in the font are put into the PDF (called subsetting). There are two ways to use fonts in LuaTeX. The first is via the classical mechanism of tfm files and pdftex.map: You can edit the file pdftex.map on your TeX system to a) force the whole font to be included (license issues might have to be considered) or to b) stop LuaTeX from putting any font information in the PDF file at all, but 99.999% of the users probably leave the settings The second way with LuaTeX (that is what you use) is to directly include Type1/TrueType/OpenType fonts via the interface provided by luaotfload/fontspec. I am not sure if luaotfload allows a different setting than subsetting the fonts. In theory, it could be configured.

Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q)

380

Q: Changing numbers font features while changing shape Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q) I am writing a document with the main font set up with old numbers, but I would like to have the ”normal” style in the tables. This works but one particular table has some of the numbers in italic and somehow I cannot find a way of changing the font feature for these. It turns out that the table is irrelevant and using \itshape or \em or \textit{} in normal text give the same result: Skip code block \documentclass[preview,border=2px,12pt]{standalone} \usepackage{fontspec} \setmainfont [Numbers = {Proportional,OldStyle}]{Linux Libertine O} \begin{document}

2189 89283 98239 8098 2983 098023 \textit{1392843902984u29830} {\itshape 198198709

{ \addfontfeatures{Numbers={Lining,Monospaced}, ItalicFeatures={Numbers={Lining,Mono 2189 89283 98239 8098 2983 098023 \textit{1392843902984u29830} \itshape 1981987092 } \end{document}

Any idea what I am doing wrong? Or have I hit a bug? Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q) User: artourter

Answer by egreg

381

With XeLaTeX I get the warning ************************************************* * fontspec warning: "icu-feature-not-exist-in-font" * * OpenType feature 'Numbers=Lining,Monospaced' (+tnum) not available for font * 'Linux Libertine O/BI' with script 'Latin' and language 'Default'. ************************************************* that’s probably the cause for this. I get the expected result by defining a new font family, instead of adding features on the fly: Skip code block \documentclass[varwidth,border=2pt,12pt]{standalone} \usepackage{fontspec} \defaultfontfeatures{Ligatures=TeX} \setmainfont [Numbers = {Proportional,OldStyle}]{Linux Libertine O} \newfontfamily{\libertinelf}{Linux Libertine O} \begin{document}

2189 89283 98239 8098 2983 098023 \textit{1392843902984u29830} {\itshape 198198709

{\libertinelf 2189 89283 98239 8098 2983 098023 \textit{1392843902984u29830} \itshape 1981987092 } \end{document}

Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q)

382

Q: Macro to calculate \baselineskip for given font Tags: fonts (Prev Q) (Next Q), macros (Next Q), latex3 (Next Q) I want to write a macro that returns the \baselineskip multiplied with a fixed value for a given font spec. That seems to be harder than I would imagine... after some fiddling I came up with this: Skip code block \ExplSyntaxOn \box_new:N \baseline_box \newcommand{\threeLineSkip}[1]{ %\box_new:N \baseline_box \hbox_set:Nn \baseline_box { #1 \rule{1pt}{\baselineskip} g } 3\box_ht:N \baseline_box } \ExplSyntaxOff \newlength{\test} \setlength{\test}{\threeLineSkip{\Huge}} \typeout{\the\test} Obviously, this doesn’t work yet, otherwise I wouldn’t be asking the question. The error is on the \setlength line: ! Illegal unit of measure (pt inserted). But I don’t understand why. I would even love to have a LuaTeX solution, but I don’t even know how to begin with that one. Tags: fonts (Prev Q) (Next Q), macros (Next Q), latex3 (Next Q) User: mib

Answer by clemens Setting a box is not expandable and so \threeLineSkip cannot expand to a length. Because of that \setlength chokes as it demands a length as 383

argument. You can circumvent this by defining a new command for setting the length: Skip code block \documentclass{article} \usepackage{expl3,xparse} \ExplSyntaxOn \box_new:N \l_MiB_baseline_box \NewDocumentCommand \SetThreeLineSkip { mm } { \MiB_set_three_line_skip:Nn #1 { #2 } } \cs_new_protected:Npn \MiB_set_three_line_skip:Nn #1#2 { \hbox_set:Nn \l_MiB_baseline_box { #2 \rule {1pt} {\baselineskip} g } \skip_set:Nn #1 { 3\box_ht:N \l_MiB_baseline_box } } \ExplSyntaxOff \newlength{\test} \SetThreeLineSkip\test{\Huge} \begin{document} \the\test \end{document}

Tags: fonts (Prev Q) (Next Q), macros (Next Q), latex3 (Next Q)

384

Q: Using Iwona as a math font with lualatex Tags: fonts (Prev Q) (Next Q) I would like to use Iwona as a math font, but this setup doesn’t get all math symbols right. (Multiline bracket, the sum symbol, etc.) \setmathfont{Iwona} \setmathfont[range=\mathup] {Iwona} \setmathfont[range=\mathbfup]{Iwona Bold} \setmathfont[range=\mathbfit]{Iwona Bold Italic} \setmathfont[range=\mathit] {Iwona Italic} I guess that Iwona doesn’t have all the math symbols that are necessary, so what should I do? (But at this link, http://www.tug.dk/FontCatalogue/iwona/, I notice that the math symbols are available). I am a bit puzzled. Edit my preamble Skip code block

documentclass[12pt,a4paper,twoside,openright,oneside,openany,titlepage,frontespizi \usepackage{fontspec} \PassOptionsToPackage{protrusion=true,final}{microtype} \newfontfeature{Microtype}{protrusion=default;expansion=default;} \usepackage{polyglossia} \usepackage{subfig} \usepackage[eulerchapternumbers,subfig,pdfspacing,listings]{classicthesis} \usepackage{arsclassica} \usepackage{amsmath,amssymb,amsthm} \usepackage{unicode-math} \usepackage[math]{iwona} \setmainfont[Microtype,Ligatures=TeX]{Minion Pro} \setsansfont{Iwona} \setmathfont{Iwona} % \setmathfont[range=\mathup] {Iwona} \setmathfont[range=\mathbfup]{Iwona Bold} 385

\setmathfont[range=\mathbfit]{Iwona Bold Italic} \setmathfont[range=\mathit] {Iwona Italic} Tags: fonts (Prev Q) (Next Q) User: thunder1123

Answer by egreg I find no reason whatsoever for having math in Iwona when the main text font is Minion Pro. However, here’s how you can do it: Skip code block \documentclass[ 12pt, a4paper, twoside, openright, oneside, openany, titlepage, headinclude, footinclude, BCOR5mm, cleardoublepage=empty, tablecaptionabove, ]{scrreprt} \PassOptionsToPackage{protrusion=true,final}{microtype} \usepackage{subfig} \usepackage[eulerchapternumbers,subfig,pdfspacing,listings]{classicthesis} \usepackage{arsclassica} \usepackage{amsmath} \usepackage[math]{iwona} \usepackage{fontspec} \usepackage{polyglossia}

386

\newfontfeature{Microtype}{protrusion=default;expansion=default;} \setmainfont[Microtype,Ligatures=TeX]{Minion Pro}

\ExplSyntaxOn \SetSymbolFont{operators}{iwona}\g_fontspec_encoding_tl\g__fontspec_mathrm_tl\md \SetSymbolFont{operators}{iwonabold}\g_fontspec_encoding_tl\g__fontspec_mathrm_t \ExplSyntaxOff \begin{document} \[ \sqrt{2\arcsin 1}=\sqrt[4]{6\sum_{k\ge1}\frac{1}{k^{2}}}= \int_{-\infty}^{\infty}e^{-x^{2}}\,dx \quad\text{text} \] \end{document} Note that there is no OpenType math font for Iwona, so using unicode-math is out of the question. The lines between \ExplSyntaxOn and \ExplSyntaxOff are to use the text font for operators and digits, otherwise Iwona would be used.

Tags: fonts (Prev Q) (Next Q)

Q: How to use TeX Gyre Pagella in pdflatex for arXiv Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q), pdftex (Prev Q) (Next Q) Since arXiv still doesn’t seem to support LuaLaTeX, I need to make my document work with pdfLaTeX instead. The only LuaLaTeX-specific stuff is

387

\usepackage{fontspec} \usepackage{unicode-math} \setmainfont[Ligatures=TeX]{TeX Gyre Pagella} \setmathfont{TeX Gyre Pagella Math} If I want the document to look as close to the one I compile with LuaLaTeX as possible, what do I need to do in terms of fonts? What differences can I expect? Is there anything in particular I should be on the lookout for? Are there subtleties that I really need to check in detail? There is no other LuaLaTeX-specific stuff in my document, and it does compile fine with pdflatex once I replace some unicode symbols (but, of course, it looks entirely different). Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q), pdftex (Prev Q) (Next Q) User: gspr

Answer by david-carlisle If you remove the lines you quote and add \usepackage{mathpazo} then you will be using a different but more or less similar Palatino clone usable in pdftex.

Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q), pdftex (Prev Q) (Next Q)

Q: LuaLaTeX: Font table with examples of font files (not system or TEXMF installed) Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q)

388

Looking at the answer to the question here, it is very close to what I wanted. What I wanted is to create font table with samples for font files that are not system installed or in TEXMF trees, but font files that reside in a path or on CD (no sub-folders, just the current folder will do). I am still learning and appreciate your help! Using MiKTeX 2.9 and Windows 7, with LuaLaTeX.

EDIT: Inspired by Taco’s answer, I have come out with the following (modified from Leo’s Code): Skip code block \documentclass{article} \usepackage{fontspec} \setmainfont{Latin Modern Mono Light} \usepackage{luacode} \usepackage[margin=18mm]{geometry} \parindent=0pt \usepackage{longtable,makecell} \renewcommand\arraystretch{2} \begin{document} \begin{luacode} teststring = "0123456789 ABCDEFabcdef" tex.print(-2, os.getenv('FONTSPEC')) tex.print('\\\\') tex.print("\\begin{longtable}{ll}\\hline") for i,v in ipairs(dir.glob(os.getenv('FONTSPEC'))) do -- get rid of './' in front of filenames, fontspec don't like that local f = string.gsub(v, "^./", "") -- font name local info = fontloader.info(v) tex.print('\\makecell[l]{\\bfseries') tex.print(-2, info.fontname) -- font name here tex.print('\\\\[-1ex] \\scriptsize') tex.print(-2, f) -- filename 389

tex.print('} & \\large\\fontspec{') tex.print(-2, f) tex.print('}') tex.print(teststring) tex.print('\\\\ \\hline') end tex.print("\\end{longtable}") \end{luacode} \end{document} It utilises an environment variable, FONTSPEC to specify the font files search pattern, eg. *.ttf for TrueType files in the current directory. Note that the TEX file needs to be at the same directory where the font files is and the glob pattern is CASE SENSITIVE! Sample run: set FONTSPEC=*.ttf lualatex fontsampler.ltx

390

Result: Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q) User: kf-leong

Answer by taco-hoekwater I am a context user and I am sure I could come up with a macro-based context hack to do what you want in an hour or so if I tried hard enough. Because of that, I am sure similar hackery can be done by a knowledgeable lualatex user, but ... why spend time creating a complicated hack if a trivial script /batch file can do the same simply by running luatex with an adjusted TEXMF or OSFONTDIR environment variable? 391

In fact, you could probably even change OSFONTDIR on the fly inside the document by putting something like \directlua { os.setenv('OSFONTDIR', '') } in the document preamble (untested, not behind a pc right now) Edit: it is even easier than that (at least in ConTeXt). I just tried some simple things, and absolute path names work in a font specification in ConTeXt, so this runs ok for me: Skip code block

\starttext \startluacode context.starttabulate{"|p|"} for i,v in ipairs(dir.glob('/home/taco/tmp/itc/*.otf')) do local info = fontloader.info(v); context.NC() context(string.format('\\mono{%s}\\crlf %s\\crlf\\definedfont[%s]',v,info.fontna context("Sphinx of black quartz, judge my vow.") context.NC() context.NR() end context.stoptabulate() \stopluacode \stoptext

Tags: fonts (Prev Q) (Next Q), fontspec (Prev Q) (Next Q)

Q: Can I downsize lua tables generated by luaotfload? Tags: fonts (Prev Q) (Next Q) luatex loads a lot of otf fonts at every luaLaTeX run with my custom class (Minion Pro, Myriad Pro, Minion Math, Latin Modern Mono, Latin Modern Math, XITS). This is an extract taken from my custom class: 392

Skip code block \RequirePackage{fontspec}

\RequirePackage[math-style = TeX]{unicode-math} \setmathfont[version=bold]{MinionMath-Bold} \setmathfont[Extension = .otf, Scale = 1, Script = Math, SizeFeatures = {% {% Size = -6, Font = MinionMath-Tiny, Style = MathScriptScript}, {% Size = 6-8.4, Font = MinionMath-Capt, Style = MathScript}, {% Size = 8.4-, Font = MinionMath-Regular}, } ]{MinionMath-Regular} \setmathfont[range={\mathfrak}]{latinmodern-math.otf} \setmathfont[range={\mathcal}]{latinmodern-math.otf} \setmathfont[range={\mathscr}]{xits-math.otf} \setmathfont[range={}]{MinionMath-Regular.otf} \usepackage{unicode-minionmath} \setmainfont{MinionPro}[ Extension = .otf, UprightFont = *-Regular, BoldFont = *-Bold, ItalicFont = *-It, BoldItalicFont = *-BoldIt, ] 393

\setsansfont{MyriadPro}[ Extension = .otf, UprightFont = *-Regular, BoldFont = *-Semibold, ItalicFont = *-It, BoldItalicFont = *-SemiboldIt, ] \setmonofont{LatinModernMono} On my system (linux, SSD, core i3), each run takes at least 10 seconds. If I understand correctly, much of the time is spent reading byte compiled lua tables storing all the information needed to take care of an otf font.

Having a look at those tables (stored in ~/.texlive2016/texmf-var/luatex-cache/generic/font it seems to me that most of the elements (unicode characters) there are nearly never used in my documents (written in French: I need ASCII + some accented letters, probably less than 200 characters). Questions 1. Would luaotfload work if I build some lightweighted lua table files ? 2. Is there a tool to tweak those lua table files? If not, how can I do it manually and tell luaotfload to load it? 3. Will it speed up my compilation time? EDIT The answer to 2 might be building an appropriate subset of my fonts at font level with a tool like fontforge, thus creating a ”new” lightweight font. As far as my googling can tell, this technique is used with web ttf fonts to minimize font size for downloads. So I add an item 4 to my questions: ”Is subsetting a font a good way to downsize lua table files? Can I use fontforge to do the work with otf fonts? How? Is there any licence restriction?” Tags: fonts (Prev Q) (Next Q) User: cjorssen

Answer by philipp-gesang 394

luatex loads a lot of otf fonts at every luaLaTeX run with my custom class […] On my system (linux, SSD, core i3), each run takes at least 10 seconds. Are you referring to one entire pass of Luatex? I can’t say anything regarding Latex, but in Context that’s reached easily with more complex documents. If I understand correctly, much of the time is spent reading byte compiled lua tables storing all the information needed to take care of an otf font. Lua is a very efficient language. Parsing Lua programs is very efficient. Loading byte-compiled programs even more. It’s unlikely that this is the bottleneck you’re facing. You can verify that easily: Determine the cache path (last line of luaotfload-tool -h), list the subdirectory otl/ and select a bytecode file. The extension is .luc. I choose one that is among the largest I know: kozminpr6n-regular.luc with 2,388,708 Bytes. These files are valid Lua programs so we can load them directly with Luatex. For maximum IO penalty we also clear the OS caches first:

$ sudo bash -c "echo 3 >/proc/sys/vm/drop_caches" $ time texlua /home/phg/.local/texlive/2016/texmf-var/luatex-cache/generic/fonts/o real user sys

0m0.240s 0m0.100s 0m0.017s

EDIT Some further measurements: I decided to check whether passing the font loaded from cache to Luatex had a significant performance impact. Turns out it’s negligible. Here’s a test setup that loads a list of fonts and measures the runtime. For more exact measurements it relies on the luaposix library. The timings are split into the cache retrieval per se (fonts.definers.read()) and feeding the result into font.define(). 395

To summarize the results: Forcing the 38 fonts through the loader adds 1.9 seconds to the runtime on my aged system; if the OS caches are hot this figure shrinks to around 1.5 s. Complex fonts from Adobe take around 50 ms to load. The huge kozminpr6n-regular.otf is an outlier at ca. 300 ms for retrieval plus 50 ms for passing through font.define(). END EDIT

240s to load the Luatex binary, spawn the Lua interpreter, and load one gigantic font table. On a low-end desktop from 2012. Not bad, especially considering that fonts are usually loaded on demand, not merely by virtue of being defined at some point. Would luaotfload work if I build some lightweighted lua table files? Those are cache files. They will be overwritten without asking next time anything changes. You will have to hack on the fontloader in order to make your changes stick. Is there a tool to tweak those lua table files? As shown above, you can load them with Lua and manipulate them like any 396

ordinary table. The corresponding text representation (in the .lua files) is plain text so you can use your editor. But they need to be byte-compiled (texluac(1)) for use with the loader. If not, how can I do it manually and tell luaotfload to load it? The fontloader will look up a font file in the cache first, but it will also rewrite the cache if it doesn’t match the font file. Thus you’ll have to hack the loader to avoid this. Will it speed up my compilation time? Very unlikely. Loading byte code is very efficient and once the tables are in memory, only those parts will be used that are needed for processing the input. The answer to 2 might be building an appropriate subset of my fonts at font level with a tool like fontforge Throw out the tables you don’t like. That will reduce the table size. Make sure you don’t violate the vendors’ license terms. Some of them preclude any modification to the files. Having a look at those tables […] it seems to me that most of the elements (unicode characters) there are nearly never used in my documents (written in French: I need ASCII + some accented letters, probably less than 200 characters). If you only typeset Latin based copy, a more promising approach would be to stick with base mode instead of node which Luaotfload defaults to. That can speed up paragraph processing drastically.

Tags: fonts (Prev Q) (Next Q)

Q: LuaLaTeX: german special character ß with ‘newpxtext‘ Tags: fonts (Prev Q) (Next Q) 397

I use the font Palatino from the package newpxtext in combination with LuaLaTeX. With this package it is not possible to set the german special character ß directly: Skip code block % Magic comments for TeXstudio % !TeX spellcheck = de_DE % !TeX program = lualatex \documentclass{scrartcl} %\usepackage{fontspec} % Font: Palatino \usepackage{newpxtext} \begin{document} Draußen währt am längsten. Drau\ss en währt am längsten. \end{document} The result from the MWE is: DrauSSen währt am längsten.. It works when I switch to fontspec. How is it possible to use the sign ß instead of \ss to set a text? Tags: fonts (Prev Q) (Next Q) User: dirk

Answer by ulrike-fischer You can make the ß active and define it: Skip code block \documentclass{scrartcl} \usepackage{newpxtext} 398

\catcode`\ß=13 \defß{\ss} \begin{document} Draußen währt am längsten. Drau\ss en währt am längsten. \end{document} That’s more or less what luainputenc does. But it is much better to use fontspec instead: \documentclass{scrartcl} \usepackage{fontspec} \setmainfont{TeX Gyre Pagella} %palatino clone \begin{document} Draußen währt am längsten. \end{document}

Answer by franck-pastor Which input encoding are you using? If you don’t use fontspec, whatever the input encoding is you must indicate it to LuaLaTeX. E.g. if your editor is configured with utf8-unicode, you must insert the line \usepackage[utf8]{luainputenc} in the preamble of your program. In that case your file works perfectly for me.

Tags: fonts (Prev Q) (Next Q)

399

Q: Can I use Wolfram Mathematica fonts in XeTeX / LuaTeX? Tags: fonts (Prev Q), xetex (Prev Q) (Next Q), unicode-math (Prev Q) (Next Q) Wolfram Mathematica comes with full (?) set of math fonts. Is it possible to use these fonts in XeLaTeX and LuaLaTeX? I mean something like \usepackage[math-style=ISO,bold-style=ISO]{unicode-math} \setmathfont[range=...]{Mathematica1} \setmathfont[range=...,Bold]{Mathematica1b} \setmathfont[range=...,???]{Mathematica1m} \setmathfont[range=...,???]{Mathematica1mb} \setmathfont[range=...]{Mathematica2} . . . \setmathfont[range=...]{Mathematica7} Tags: fonts (Prev Q), xetex (Prev Q) (Next Q), unicode-math (Prev Q) (Next Q) User: igor-kotelnikov

Answer by joseph-wright Math typesetting is complex, and needs a lot of structures inside the font. OpenType math fonts have these, but TrueType ones don’t. I suspect that Mathematica relies on ’knowing’ details of the fonts, in the same way that traditional TeX math fonts are made up of several files with a known relationship (to TeX). So you won’t be able to use these fonts with LuaTeX, or I suspect with the Word 2007/2010 equation editor (which also uses OpenType).

Tags: fonts (Prev Q), xetex (Prev Q) (Next Q), unicode-math (Prev Q) (Next Q)

400

Fontspec Skip to questions, Wiki by user will-robertson This tag should be used for questions that relate to the fontspec package, which is used for loading OpenType fonts in XeLaTeX and LuaLaTeX. (Actually, fontspec can be used to load other sorts of fonts, too, but loading OpenType fonts is the main use case.)

Questions Q: How to suppress a ”Rare” ligature that pre-empts a ”Common” ligature for the same character pair? Tags: fontspec (Prev Q) (Next Q), opentype (Prev Q) (Next Q), ligatures (Prev Q) (Next Q) In several documents I’m creating with LuaLaTeX (using MacTeX2012 on a Mac that’s running MacOS X 10.7.5), I primarily use the Adobe-issued font Garamond Premier Pro as the main text font. I use this font because it provides a slew of • ”Common” ligatures: These comprise not only the five TeX-standard f-ligatures, viz., ff, fi, fl, ffi, and ffl, but also ligatures for ft, fft, fb, ffb, and a few more; and • ”Rare” (aka ”Discretionary”) ligatures: For this particular font, ”rare” ligatures are available for the character pairs ct, st, sp, and ft (but not fft; see also below) in both upright and italic shapes, as well as for the character pairs as, is, us, at, et, th and a few more in the italic font shape only. If just the ”Common” ligature set is enabled (via the option Ligatures=Common), the ft and fft groups, in both upright and italic shapes, are typeset like this: 401

Just in case this matters, the Unicode character representations for these ligatures are U+E18D and U+E187, respectively. In the upright font shape, the ”glyph id” numbers are 277 and 271 and the ”character codes” are 57742 and 57735, respectively. In the italic font shape, the Unicode character representations are the same, but the ”glyph id” and ”character code” numbers are 283 and 276, and 57864 and 57857, respectively. However, if the ”Rare” ligature set is enabled -- irrespective of whether the ”Common” ligature set is enabled as well -- the ft and fft character groups are rendered as follows:

(Aside: For another rendering of the ”rare”-style ft-ligature, check out the web page Garamond type ft-ligature.) Not only does the ”Rare”-style ft ligature look rather different from its ”Common”-style counterpart, the fft ligature no longer exists at all: the fft character triple is now rendered as a plain ”f” followed by the ”Rare”style ft ligature. For my purposes, the absence of a ligature for the fft character triple if ”Rare” ligatures are enabled is rather unfortunate. The fact that the crossbars of the ”f” and ”ft” glyphs don’t line up properly in the italic font shape is also rather problematic. Separately, I also prefer the look 402

of the ”Common”-style ft-ligature to that of its ”Rare”-style counterpart, but that’s only a secondary concern. (Incidentally, the Unicode character representation for the ”Rare” ft-ligature is U+E18E. In the upright font shape, its ”glyph id” and ”character number” codes are 278 and 57742, resp.; in the italic font shape the latter two numbers are 283 and 57864, resp.) My question is: Is there a way -- preferably using macros provided by the fontspec package -- to disable the ”Rare”-style ft ligature globally in order to re-enable the ”Common”-style ft ligature -- while still being able to use all other ”Rare” ligatures as well as the ”Common” ligatures? Just for completeness, here’s the code that generates the first example above: % !TEX TS-program = lualatex \documentclass{article} \usepackage{fontspec} \setmainfont[Ligatures=Common, ItalicFont={Garamond Premier Pro Italic}] {Garamond Premier Pro} \begin{document} ft fft \em ft fft \end{document} To generate the second example, replace the option Ligatures=Common with Ligatures={Common,Rare}. Tags: fontspec (Prev Q) (Next Q), opentype (Prev Q) (Next Q), ligatures (Prev Q) (Next Q) User: mico

Answer by khaled-hosny Some thing like this using feature files should work: First the feature file: Skip code block # scripts and languages, if the font use others they should be defined here too languagesystem DFLT dflt; languagesystem latn dflt; 403

# this undoes the effect of rare ligature on ft feature liga { sub f_t.alt by f t; } liga; # move rare ft to historic ligatures feature hlig { sub f t by f_t.alt; } hlig; # apply feature sub f sub f } liga;

the regular ligature on ft and fft liga { f t by f_f_t; t by f_t;

The order of the above is important, this way regular “ft” and “fft” are used even with Rare ligatures, but not with Historic. The glyph names should match those in the font with f_t.alt being the name of the unwanted “ft” ligature, and f_t & f_f_t being the names of the wanted ones. The full feature file syntax is documented by Adobe (but LuaTeX supports v1.6 f the syntax + FontForge extension, not the current one, so there are some differences). Then it can be applied to the font by using FeatureFile fontspec option: Skip code block \documentclass{article} \usepackage{fontspec} \begin{document} \fontspec[Ligatures={Common,Rare},FeatureFile=test.fea]{Garamond Premier Pro} ft fft \em ft fft \fontspec[Ligatures={Common,Rare,Historic},FeatureFile=test.fea]{Garamond Premier ft fft \em ft fft 404

\end{document}

Tags: fontspec (Prev Q) (Next Q), opentype (Prev Q) (Next Q), ligatures (Prev Q) (Next Q)

Q: An example of changing kerning of a font in LuaLaTeX Tags: fontspec (Prev Q) (Next Q) LuaLaTeX, through the luaotfload package, is able to dynamically add and modify features and properties of a font. This is performed by using the FeatureFile option in fontspec when loading a font; e.g., \setmainfont[FeatureFile=times-nr.fea]{Times New Roman} where times-nr.fea is given as a listing in the fontspec manual (see §11). The syntax of these feature files is given by Adobe. Unfortunately, I haven’t had the chance to look into this myself and I’m not sure what’s possible nor how to do it. I’d like to add some more examples to the fontspec manual, especially for adjusting the side-bearings around single glyphs and adjusting the kerning between adjacent glyphs and so on. The ability to define custom kerning for your fonts would truly make LuaLaTeX a world-class typesetting engine—no other TeX program is able to do this sort of thing so easily. I’d like to perform an experiment: the source for fontspec is on GitHub. I’ll offer a bounty on this question for the best patch to the fontspec manual adding more documentation for the FeatureFile option, specifically for sidebearing and/or kerning but hopefully for anything else that you also might happen to see that’s fun. So, can anyone help?

P.S. If you’re stuck on the fact that to compile fontspec.pdf requires a whole bunch of pre-built PDFs for the examples, you can grab them from CTAN. 405

Tags: fontspec (Prev Q) (Next Q) User: will-robertson

Answer by khaled-hosny I did not want to interfere with this experiment, but since nobody posted an answer so far, I just pushed an update to the feature file section of the documentation on github. It is not the most clear way to document it, but I tried my best (as far as my English permits :) )

Answer by user3432 Adjusting the kerning of the glyph pair fh in TeX Gyre Bonum would require something like the this ... bonum.fea languagesystem DFLT dflt; languagesystem latn dflt; feature kern { pos \f \h 125; } kern; test.tex \documentclass{article} \usepackage{fontspec} \setmainfont[FeatureFile=bonum.fea]{TeX Gyre Bonum} \begin{document} fh \end{document} There is a problem with the babel package, though ... test2.tex \documentclass{article} \usepackage[ngerman]{babel} \usepackage{fontspec} \setmainfont[FeatureFile=bonum.fea]{TeX Gyre Bonum} 406

\begin{document} fh aufhalten \end{document} As you can see, the adjusted kerning only applies to the first instance of the glyph pair. When the glyph pair occurs inside a word, the adjusted kerning is not applied. When babel is not loaded, everything is fine.

Tags: fontspec (Prev Q) (Next Q)

Q: Bad interaction between fontspec and some lua code that performs string-related search and replace operations Tags: fontspec (Prev Q) (Next Q), programming (Next Q) Update 2013/05/28: The selnolig package is now on the CTAN. Comments and critiques always welcome! If you wish to contact me about any aspects of the package, please use the email address that’s given at the bottom of the title page of the package’s user guide. (Relative to the state of the package described in the question below, I’ve managed to squash at least one bug, and I suggest better work-arounds for the remaining bugs -- at least the ones I’m aware of!)

I’m in the process of readying a LuaLaTeX package for ”official” release to the CTAN, but I need to squash a few remaining bugs first. The bug described in this question concerns incorrect behavior of my package that occurs if the fontspec package is loaded; if fontspec is not loaded, none of the problems described here occur. Obviously, asking potential users of my package not to load fontspec is not an option. Incidentally, the identifier string of the LuaTeX version on my system is ”beta-0.70.2-2012062819”, distributed with MacTeX2012. For much more information about the full selnolig package, which does automated, selective suppression of typographic ligatures, please see New package, selnolig, that automates suppression of typographic ligatures. 407

The MWE (see image below, and code provided below image) illustrates several instances of failure to perform ligature suppression if -- and apparently also only if -- fontspec is loaded. Specifically, ligature suppression fails for: • a word that’s followed immediately by a comment (%) sign • the last word in the argument of a command such as \footnote and \section • a word that immediately precedes the start of an environment such as enumerate and itemize • the final word of an \item statement, i.e, the final word before the next \item statement and/or the environment’s closing \end{enumerate/itemize} directive A common theme of these problems is that they occur if the word in question (plus any trailing punctuation characters) is at the very end of some environment, group, or argument to some macro. In all cases, a ”remedy” of sorts is to insert either a space, a blank line, or a space plus something like \vphantom{x} [!]. Clearly, these remedies are not real solutions but merely kludgy hacks, and I certainly wouldn’t contemplate asking users of my package to do implement these hacks. My questions are, then: • How can I make my lua code more robust to whatever is being done by the fontspec pacakge (or some package that’s loaded by fontspec)? • Is there a way to load either fontspec (or some of the packages called by fontspec) to suppress the interference with my lua code? • Or, have I discovered a bug in fontspec (or one or more of the packages loaded by fontspec) that needs to be fixed anyway?

408

Skip code block % !TEX TS-program = lualatex \documentclass{article} % If the next line is commented out, everything works fine! \usepackage{fontspec} \RequirePackage{luatexbase,luacode,expl3} % Load lua code \directlua{ require("ld-orig.lua") } % see below for contents of ld-orig.lua % Define the user macro "nolig" \providecommand\nolig[2]{ \directlua{ suppress_liga( "\luatexluaescapestring{#1}", "\luatexluaescapestring{#2}" )}} % Provide a ligature suppression rule % (the full package obviously provides many more such macros) \nolig{lfful}{lf|ful} % shelfful -> shelf|ful

409

% Just for this MWE: \usepackage[textheight=8cm]{geometry} \setlength\parindent{0pt} \pagestyle{empty} \begin{document} Two shelffuls of \TeX-related books: it works! \bigskip % word to be de-ligated is followed immediately by % (comment character) Ligature suppression doesn't work here: shelfful% % leaving a space between word and % makes it work even if fontspec is loaded But it does work in this case: shelfful %

\bigskip bad\footnote{This doesn't work: shelfful.} % w/o space good\footnote{But this does work: shelfful. \vphantom{x}} % w/ space and \vphantom \bigskip % Two more problem cases: (i) last word before start of an % itemize/enumerate environment, (ii) last word of an \item one shelfful, two shelffuls % no ligature suppression for "shelffuls" \begin{itemize} \item shelfful % no ligature suppression here either \item shelfful \vphantom{x} % inserting space and \vphantom does the trick... \end{itemize} % problem also occurs in arguments of sectioning commands \section*{sad shelfful} % again no ligature suppression \subsection*{happy shelfful } % adding space at end of argument makes it work! \end{document}

Contents of ld-orig.lua: Skip code block --- Credits to Patrick Gundlach, Taco Hoekwater, and Steffen Hildebrandt! 410

local local local local

glyph = node.id('glyph') glue = node.id("glue") whatsit = node.id("whatsit") userdefined

for n,v in pairs(node.whatsits()) do if v == 'user_defined' then userdefined = n end end local identifier = 123456 -- any unique identifier local noliga={} debug=false -- default: don't write debugging info to log file function debug_info(s) if debug then texio.write_nl(s) end end local blocknode = node.new(whatsit, userdefined) blocknode.type = 100 blocknode.user_id = identifier function process_ligatures(nodes,tail) local s={} local current_node=nodes local build_liga_table = function(strlen,t) local p={} for i = 1, strlen do p[i]=0 end for k,v in pairs(t) do -- debug_info("Match: "..v[3]) local c= string.find(noliga[v[3]],"|") local correction=1 while c~=nil do -- debug_info("Position "..(v[1]+c)) p[v[1]+c-correction] = 1 411

c = string.find(noliga[v[3]],"|",c+1) correction=correction+1 end end -- debug_info("Liga table: "..table.concat(p, "")) return p end local apply_ligatures=function(head,ligatures) local i=1 local hh=head local last=node.tail(head) for curr in node.traverse_id(glyph,head) do if ligatures[i]==1 then -- debug_info("Current glyph: "..unicode.utf8.char(curr.char)) node.insert_before(hh,curr, node.copy(blocknode)) hh=curr end last=curr if i==#ligatures then -- debug_info("Leave node list on position: "..i) break end i=i+1 end if(last~=nil) then -- debug_info("Last char: "..unicode.utf8.char(last.char)) end--]] end for t in node.traverse(nodes) do if t.id==glyph then

s[#s+1]=string.lower(unicode.utf8.char(t.char)) elseif t.id== glue then local f=string.gsub(table.concat(s,""),"[\\?!,\\.]+","") -- add all interpun local throwliga={} for k, v in pairs(noliga) do local count=1 local match= string.find(f,k) 412

while match do count=match -- debug_info("pattern match: "..f .." - "..k) local n = match + string.len(k)-1 table.insert(throwliga,{match,n,k}) match= string.find(f,k,count+1) end end if #throwliga==0 then -- debug_info("No ligature substitution for: "..f) else -- debug_info("Do ligature substitution for: "..f) local ligabreaks=build_liga_table(f:len(),throwliga) apply_ligatures(current_node,ligabreaks) end s={} current_node=t end end end function suppress_liga(s,t) noliga[s]=t end

function drop_special_nodes (nodes,tail) for t in node.traverse(nodes) do if t.id == whatsit and t.subtype == userdefined and t.user_id == identifier t node.remove(nodes,t) node.free(t) end end end luatexbase.add_to_callback("ligaturing", process_ligatures,"Filter ligatures", 1)

Postscript: The solution to the bug described in this posting. The key 413

sequence in the lua code given above is that caused the bug was: for t in node.traverse(nodes) do if t.id==glyph then s[#s+1]=string.lower(unicode.utf8.char(t.char)) elseif t.id==glue then ... All that was required to fix the bug is to change this code snippet to: for t in node.traverse(nodes) do if t.id==glyph then s[#s+1]=string.lower(unicode.utf8.char(t.char)) end if ( t.id==glue or t.next==nil or t.id==kern or t.id==rule ) then ... The point is that the sequence of characters that needs to be processed by selnolig can end in ways other than just with some amount of (TeX) ”glue” (e.g., whitespace). Another way for the sequence to end if the word is the very last item being processed, e.g., if it’s the last word in the argument of a command such as \section{}; if that’s the case, the variable t.next will be equal to nil. Finally, the two remaining if conditions -- t.id==kern and t.id==rule -- are provided in case a user has inserted a ”kern” or ”rule” item manually. The bug fix is incorporated in version 0.220 of the package. Tags: fontspec (Prev Q) (Next Q), programming (Next Q) User: mico

Answer by topskip Let me try to analyze the problem: You call the ligaturing over and over again, but sometimes the callback doesn’t seem to have any effect. I’d like to take a look at two cases: the footnotes:

bad\footnote{This doesn't work: shelfful.} % w/o space good\footnote{But this does work: shelfful. \vphantom{x}} % w/ space and \vphantom

414

I’ll have a look at the node list that is passed to the ligaturing callbacks with my small module viznodelist. I change the lua code slightly at the entrance point to process_ligatures(): ... require("viznodelist") function process_ligatures(nodes,tail) counter = counter or 0 counter = counter + 1 viznodelist.nodelist_visualize(nodes,string.format("liga%d.gv",counter)) The first footnote (’bad’) looks like this:

with the detail (top right)

while the ”good” nodelist looks like this:

Now looking at the code:

415

Skip code block for t in node.traverse(nodes) do if t.id==glyph then s[#s+1]=string.lower(unicode.utf8.char(t.char)) elseif t.id== glue then ... (process ligatures) ... end end makes it clear that only a glue activates the ligature processing. I’d suggest using a different kind of looping for ligature processing. The difference between fontspec activated or not is the following: with fontspec deactivated, the ligaturing callback disables all ligaturing. What you see is not the effect of the command \nolig, but a general ”no ligature” mode. Try words like fluffiest fish and you see that. With fontspec enabled, the result is ”always ligatures” unless you block them with the code you use. So the ligaturing callback is not the perfect way to deal with the situation, I am afraid. You could however call node.ligaturing() at the beginning of the callback and then do what you are doing. But that would probably interfere with fontspec.

Tags: fontspec (Prev Q) (Next Q), programming (Next Q)

Q: How can I access a specific glyph in LuaLaTeX/Fontspec? Tags: fontspec (Prev Q) (Next Q), xetex (Prev Q) (Next Q), unicode (Prev Q) (Next Q) The OTF version of Minion Pro contains several Dingbats glyphs I would 416

like to access. Some of them are not unicode, so I can not just copy the specific unicode character I want to access into my text editor. In specific, I am looking for the bold looking Moon on page 3 of this document: http://www.adobe.com/type/browser/pdfs/1719.pdf After searching, I could not figure out how to include a specific character from a font to my document. I found out that I can use the command \symbol{glyph number}, but don’t see how I should obtain that number. Thus I ask my question more generally: how can I use a specific glyph from a font using LuaLaTeX? Tags: fontspec (Prev Q) (Next Q), xetex (Prev Q) (Next Q), unicode (Prev Q) (Next Q) User: ingo

Answer by ulrike-fischer In my version of Minion Pro I get the two moons with \documentclass{article} \usepackage{fontspec}% \setmainfont{Minion Pro} \begin{document} blub \symbol{57529} \symbol{57530} \end{document} I found the numbers this way: 1. I opened temp-minionpro-regular.lua (the path is mentioned in the logfile) 2. There I got to the part starting with unicodes={ (somewhere around line 590.000) and then skimmed the glyph names until I hit upon ["orn.001"]=57525, which sounded like the names for the ornaments.

Answer by charles-stewart 417

You can display the some of the glyphs in a font using Context document (assuming the font is called whatever.otf): \definefontsynonym[Dummy][file:whatever.otf][features=default] \starttext \showfont[Dummy] \stoptext This displays the offset numbers that you can use in Latex with \symbol, for the first 256 glyphs in the font. Postcript The following code iterates over all the characters in a given OTF file. For some reason unclear to me, this generally seems to include a lot of character entities not associated with glyphs. Skip code block %%Define font name and font path here \def\fontname{Jerusalem} \def\filename{/usr/X11/lib/X11/fonts/OTF/SyrCOMJerusalem.otf} \startluacode charset={} function fonttablechars (f) local cs, r = f.characters, {} for c in pairs(cs) do r[1+#r]=c end table.sort(r) return r end function setcharset () charset = fonttablechars(font.fonts[font.current()]) return charset 418

end function printcharset () local step=9 context "\\bTABLE[split=yes] " for i=1,#charset,step do context "\\bTR " for j=0,step-1 do local v, cstr = i+j, tostring(charset[i+j]) if not charset[v] then break end context ('\\bTD \\ppno{%s} \\eTD \\bTD \\glyph{%s} \\eTD ', cstr, cstr) end context "\\eTR " end context "\\eTABLE " end \stopluacode \definefontsynonym[\fontname][file:\filename][features=default] \def\glyph#1{\getglyph{\fontname}{#1}} \def\ppno#1{#1\relax} \starttext \section{Print font \fontname\ from \filename} \setupbodyfont [\fontname] \directlua0{setcharset()} \setupbodyfont [mainface] \directlua0{printcharset()} \stoptext

Answer by paul

419

Xetex Even though the question is about LuaLatex, here another XeTeX solution Based on this post: Generating a table of glyphs with XeTeX and some other research. It prints you all glyphs and you can access them with \XeTeXglyph Skip code block \documentclass[landscape]{article} \usepackage{geometry} \usepackage{xltxtra} \usepackage{fontspec} \usepackage{xunicode} \setmainfont{Minion Pro} \usepackage{multicol} \setlength{\columnseprule}{0.4pt} \usepackage{multido} \setlength{\parindent}{0pt} \begin{document} \XeTeXglyph508\XeTeXglyph1262 \begin{multicols}{10} \multido{\i=0+1}{\XeTeXcountglyphs\font}{ \makebox[3em][l]{\i}% \XeTeXglyph\i\endgraf } \end{multicols} \end{document}

Tags: fontspec (Prev Q) (Next Q), xetex (Prev Q) (Next Q), unicode (Prev Q) (Next Q)

420

Q: Lualatex (luaotfload) broke after upgrading to Mavericks Tags: fontspec (Prev Q) (Next Q), errors (Prev Q) (Next Q) Ever since I upgraded to OS X Mavericks—post hoc ergo propter hoc—I can no longer compile my dissertation using LuaLaTeX. When running lualatex I first got the following error: luaotfload | db: reload initiated; reason: “unresolved font name: ‘lucidacal Segmentation fault: 11 ’lucidacal’ presumably refers to the Lucida Grande font, which I had installed in ~/Library/texmf. I removed ~/Library/texmf and ~/Library/texlive and now I get the following error:

luaotfload | db : Font names database not found, generating new one. luaotfload | db : This can take several minutes; please be patient.Segmentation fa I can reproduce this error by running luaotfload-tool --update. At some point I also got the following error: luaotfload | db: Font names database not found, generating new one. Bus error: 10 I can’t reproduce this, however. I tried upgrading all packages using TeXLive but this didn’t help. I have no idea how to fix it and would be grateful for any clues! Tags: fontspec (Prev Q) (Next Q), errors (Prev Q) (Next Q) User: jdevuyst

Answer by egreg I tried the same and got Segmentation fault: 11 too. So I retried with luaotfload-tool -v -vvv -u that shows all processing and saw it stopped when trying to load Skia.ttf. So I edited 421

/usr/local/texlive/2013/texmf-dist/tex/luatex/luaotfload/luaotfload-blacklist.cnf (with sudo) and added Skia.ttf (the first two lines) Skip code block % Causes segmentation fault with Mavericks Skia.ttf % Takes ages to load LastResort.ttf % a MacOSX font, but also available for free from unicode.org % Segfaults under LuaTeX 0.76 lingoes.ttf % http://tug.org/pipermail/luatex/2013-May/004239.html Diablindall.ttf spltfgbd.ttf spltfgbi.ttf spltfgit.ttf spltfgrg.ttf Rerunning luaotfload -v -vvv -u was successful. Losing Skia is annoying, but not having a good font database is surely worse.

Note that also other fonts seem to be a cause for this. A user found that also Silom.ttf triggers a segmentation fault; running from the terminal luaotfload-tool -v -vvv -u will clearly show the culprit. The only known remedy is to add the offending font to the blacklist.

News (2014-01-01) The new version of luaotfload (2013/12/31, luaotfload v2.4) just uploaded for TeX Live, has Skia.ttf in the blacklist file. Skip code block % Takes ages to load 422

LastResort.ttf % a MacOSX font, but also available for free from unicode.org % Segfaults under LuaTeX 0.76 lingoes.ttf % http://tug.org/pipermail/luatex/2013-May/004239.html Diablindall.ttf spltfgbd.ttf spltfgbi.ttf spltfgit.ttf spltfgrg.ttf % Buggy Max OS font, see https://github.com/lualatex/luaotfload/issues/139 Skia.ttf

Tags: fontspec (Prev Q) (Next Q), errors (Prev Q) (Next Q)

Q: LuaLaTeX protrusion problem with Negative value Tags: fontspec (Prev Q) (Next Q), protrusion (Next Q) Please see the following screen shots.

423

As you can see there are two ”overfull” hbox there. However, LaTeX does not produced any overfull box warning at all. I tried to produce a minimal working example but without exactly the same layout, and fonts, and line breaks, it cannot be reproduced. So sorry that I cannot include a MWE in this question. (edit: please find an MWE further down). However I tried to diagnose the problem. Since LaTeX does not see these as overfull box, it could be protrusion problem I guess. I setup the Minion fonts with fontspec (LuaLaTeX) as following, Skip code block \setmainfont[ UprightFeatures = {RawFeature = {protrusion = BoldFeatures = {RawFeature = {protrusion = ItalicFeatures = {RawFeature = {protrusion = BoldItalicFeatures = {RawFeature = {protrusion = RawFeature = {expansion = default}, Ligatures = {Required, Common, Contextual, TeX}, Numbers = {OldStyle, Proportional}, SizeFeatures = { {Size = -8.41, OpticalSize = 8}, {Size = 8.41-13.01, OpticalSize = 11}, {Size = 13.01-19.91, OpticalSize = 19}, {Size = 19.91-, OpticalSize = 72}}, ]{Minion Pro}

mnr}}, mnr}}, mni}}, mni}},

Ignoring the other things (for example the SizeFeatures is used to work around the problem that fontspec/luaotfload cannot select the right optical sizes). The problems appeared to the line ItalicFeatures = {RawFeature = {protrusion = mmi}}, Where protrusion is turned on before the fonts setup by \pdfprotrudechars2 and mni is the protrusion setting for Minion Pro Italic. I translated the setting in MinionPro package to be used with LuaLaTeX (as the official release of microtype do not support LuaTeX with opentype fonts loaded by fontspec yet). A portion of the Lua file that setup the protrusion can be found below, Skip code block 424

fonts = fonts or { } fonts.protrusions = fonts.protrusions or { } fonts.protrusions.setups = fonts.protrusions.setups or { } --omitted codes-fonts.protrusions.setups["mni"] = { -- Minion Pro Italic factor = 1, left = 1, right = 1, -- omitted [0x0067] = [0x0069] = [0x006A] = [0x0070] = [0x0072] = -- omitted

code-{-0.070, -0.070}, -- g { 0.000, -0.110}, -- i {-0.090, -0.150}, -- j {-0.040, 0.000}, -- p { 0.000, 0.080}, -- r --

} I I change the protrusion factor of letter g and p, which are the breaking points in the picture above, then the problem solved. Can anyone explain the problem? Is there something wrong with my fonts setup (the use RawFeatures) or the protrusion setup file (the codes omitted in the above code snipes are just setting for other letters, which I assume should be independent from each other)? It seems that whenever a linebreak happens at a italic character and protrusion is activated for that character, then the problems always happen. This does not happen for roman fonts. Edits: Further experiments showing that assigning positive values instead of negative values to the protrusion factors does not cause any problem for the italic fonts. I guess the problem is not with Italic font, but with the negative value of protrusion factors. The reason no such problem for roman fonts is that there are no negative values assigned for any roman characters. But some italic characters has negative protrusion values so that they don’t reach out the boundary too much. Latest Edit: Here’s a minimal document that triggers the issue. 425

Skip code block \documentclass[a4paper]{article} \usepackage{microtype} \usepackage{amsthm} \newtheorem{proposition}{Proposition} \usepackage{lipsum} \begin{document} \begin{proposition} \lipsum \end{proposition} \end{document}

426

With lualatex (showcases the bug):

427

With pdflatex (perfectly fine):

428

Tags: fontspec (Prev Q) (Next Q), protrusion (Next Q) User: yan-zhou

Answer by robert This could be related to a bug with negative protrusion values that I reported a year ago and which is obviously still open. Which luatex version are you using?

Tags: fontspec (Prev Q) (Next Q), protrusion (Next Q)

Q: How do I change the font size in LuaLaTeX? Tags: fontspec (Prev Q) (Next Q) Skip code block \documentclass{minimal} \usepackage[paperheight = 140mm,% comprimento paperwidth = 200mm,% altura margin = 10mm % tamanho da margem ]{geometry} \usepackage[T1]{fontenc} \usepackage{fontspec} \usepackage{xcolor} \setmainfont[Color=brown]{Tangerine} \begin{document} Normal pleasure of your company is requested \end{document} I’m making a wedding invitation and I’m not sure how do it using LuaLaTeX.

429

I want to set, in \setmainfont, the default color and size but I don’t know how. I’m able to set the color, as in the example, but not the size at the same time. \setmainfont[SizeFeatures={Size=30}]{Tangerine} sets the size, but I don’t know how put it together. Is it possible? Furthermore, how do I change the font size in the middle of the document? I tried \Huge but got an error. Tags: fontspec (Prev Q) (Next Q) User: andré-andrade

Answer by andrey-vihrov \Huge did not work because you used the minimal document class, which does not provide any font size commands. Use the usual article instead. You shouldn’t also need to set font size with fontspec, too. Use any of these options: • To set a default font size document-wise, pass one of the options 10pt, 11pt or 12pt to the document class. • Use the usual font size commands (\small, \normalsize, \large, etc.). • If none of the above have the size you need, select it manually with \fontsize{}{}. A \selectfont command has to follow immediately after. The two latter options also can be used document-wise: just put them right after \begin{document} outside any groups. To sum up, an example document: Skip code block \documentclass[10pt]{article} \usepackage{fontspec} \usepackage{xcolor} \setmainfont[Color=brown]{Linux Libertine}

430

\begin{document} Lorem {\Huge ipsum} dolor {\fontsize{14pt}{16pt}\selectfont sit} amet. \end{document}

Answer by ulrike-fischer The option SizeFeatures is not meant to set a size. It should be used to set features which should be activated/used only for some font sizes: Skip code block \documentclass{article} \usepackage{fontspec} \usepackage{xcolor} \setmainfont[SizeFeatures={{Size=-11,Color=red}, {Size=11-30,Color=blue}, {Size=30-,Color=green}}]{Arial} \begin{document} normal red text \large larger blue text \fontsize{30pt}{30pt}\selectfont very large green Text \end{document}

Tags: fontspec (Prev Q) (Next Q)

431

Q: Towards a \ucshape and \textuc command for uppercase text (XeTeX, LuaTeX) Tags: fontspec (Prev Q) (Next Q), xetex (Prev Q) (Next Q), opentype (Prev Q) (Next Q) While we have \textit and \textsc, \itshape and \scshape etc., there’s no \textuc and \ucshape to typeset its argument in uppercase. There is \MakeUppercase, but -- as uppercase is not a font style -- it’s not a font selection command and cannot be used like one. That’s why it’s of no use in, e.g., formatting headings. There’s the seamus-egreg workaround, but that has its limitations, for example when exotic languages are used: \section{daß} produces »DAß« rather than »DASS«, etc. Traditionally, the only way towards a proper \textuc/\ucshape seemed to be via creating a virtual font in which all lowercase letters are replaced by uppercase ones. While I’ve seen a couple of people suggesting that approach, I don’t think anyone has ever done it, probably because it’s tedious and inflexible, as it’s always tied to one specific font. My question is if it might be a good idea to rethink that issue now that we have Xe and Lua, where we can use OpenType Fonts and, via fontspec, OpenType feature files. In those feature files, we can define substitution rules that can be switched on and off. In OpenType, an f_i ligature, for example, is produced via such a substitution rule, saying »whenever in the code you come across an f followed by an i, replace the two by the glyph f_i in the output«. To tentatively answer my own question: yes, it might be. Consider the following example. [edit: now including a comparison with the \MakeTextUppercase command from the textcase package barbara mentioned.] Skip code block \documentclass{scrartcl} \usepackage{fontspec,blindtext,microtype,filecontents,textcase} \begin{filecontents*}{universalcaps.fea} languagesystem DFLT dflt; languagesystem latn dflt;

432

feature caps { lookup ligatures { sub f_i by F I; sub f_l by F L; sub f_f_l by F F sub f_f_i by F F sub f_f by F F; sub f_j by F J; sub f_f_j by F F sub f_t by F T; sub f_f_t by F F } ligatures;

L; I;

J; T;

lookup eszett { sub germandbls by S S; } eszett; lookup single { sub [a-z] by [A-Z]; sub agrave by Agrave; sub aacute by Aacute; sub acircumflex by Acircumflex; sub atilde by Atilde; sub adieresis by Adieresis; sub aring by Aring; sub ccedilla by Ccedilla; sub egrave by Egrave; sub eacute by Eacute; sub ecircumflex by Ecircumflex; sub edieresis by Edieresis; sub igrave by Igrave; sub iacute by Iacute; sub icircumflex by Icircumflex; sub idieresis by Idieresis; sub eth by Eth; sub ntilde by Ntilde; sub ograve by Ograve; 433

sub oacute by Oacute; sub ocircumflex by Ocircumflex; sub otilde by Otilde; sub odieresis by Odieresis; sub ugrave by Ugrave; sub uacute by Uacute; sub ucircumflex by Ucircumflex; sub udieresis by Udieresis; sub yacute by Yacute; sub thorn by Thorn; sub ydieresis by Ydieresis; sub oe by OE; sub ae by AE; sub scaron by Scaron; sub zcaron by Zcaron; } single; } caps; \end{filecontents*} \setmainfont[FeatureFile=universalcaps.fea]{TeX Gyre Termes} \setsansfont[FeatureFile=universalcaps.fea]{TeX Gyre Heros} \newcommand*{\ucshape}{\addfontfeature{RawFeature=+caps}} \newcommand{\textuc}[1]{{\ucshape #1}} \setkomafont{section}{\ucshape} \begin{document} \section{Lorem Ipsum} \textuc{\blindtext àéîàáâãäåæ çèéêëìíîï ðñòóôõö ùúûüýþÿœš fi ff fl ffi ffl fj ffj} \MakeTextUppercase{daß} \textuc{daß}

434

\begin{titlepage} \ucshape \begin{center} John Doe\par {\huge Title} \end{center} \end{titlepage} \end{document} This will create a feature file, adding to whatever font is loaded a new feature called caps that can be turned on and off like any other. Note that this will work with TrueType fonts as well, {Georgia} etc; fontspec seems to transfer what’s in the .fea file to even non-OpenType fonts. • Are there any potential drawbacks that I may not have had in mind? I’m still thinking it seems too simple to be true. (While it may be simple, it may of course still be a lot of work to take are of all lowercase glyphs in advanced multi-language fonts). • Has anyone else ever done or seen something like that? I find it hard to believe I should be the first to come up with that idea... • If noone has done it so far, would it be a good idea to turn it into a little package? Tags: fontspec (Prev Q) (Next Q), xetex (Prev Q) (Next Q), opentype (Prev Q) (Next Q) User: nils-l

Answer by topskip A full implementation in LuaTeX: Skip code block \documentclass{article} \usepackage{fontspec} \usepackage{xcolor} \usepackage{luacode} 435

\usepackage{luatexbase} \usepackage{luatexbase-attr} \newluatexattribute\uppercaseattr

\begin{luacode*} local ucattr = luatexbase.attributes.uppercaseattr

local function makeuppercase(head) local orighead = head local string = unicode.utf8 while head do if head.id == 37 then local att = node.has_attribute(head,ucattr) if att then if head.char == 223 then -- ß -- insert two 'S' glyphs head.char = 83 orighead = node.insert_before(orighead,head,node.copy(head)) elseif head.char == 64258 then -- fl head.char = 70 -- F orighead = node.insert_before(orighead,head,node.copy(head)) head.char = 76 -- L elseif head.char == 64256 then -- ff head.char = 70 -- F orighead = node.insert_before(orighead,head,node.copy(head)) head.char = 70 -- F elseif head.char == 64257 then -- fi head.char = 70 -- F orighead = node.insert_before(orighead,head,node.copy(head)) head.char = 73 -- I elseif head.char == 64259 then -- ffi head.char = 70 -- F orighead = node.insert_before(orighead,head,node.copy(head)) head.char = 70 -- F orighead = node.insert_before(orighead,head,node.copy(head)) head.char = 73 -- I 436

elseif head.char == 64260 then -- ffl head.char = 70 -- F orighead = node.insert_before(orighead,head,node.copy(head)) head.char = 70 -- F orighead = node.insert_before(orighead,head,node.copy(head)) head.char = 76 -- L else head.char = string.byte(string.upper(string.char(head.char)) end end end head = head.next end return orighead end function makeuppercase_hbox(head,groupcode) local orighead = head if groupcode == "adjusted_hbox" or groupcode == "hbox" then makeuppercase(head) end return orighead end

luatexbase.add_to_callback("hpack_filter",makeuppercase_hbox,"makeuppercasehbox" luatexbase.add_to_callback("pre_linebreak_filter",makeuppercase,"makeuppercase") \end{luacode*} \newcommand*\ucshape{\uppercaseattr=1} \DeclareTextFontCommand{\textuc}{\ucshape}

\begin{document} \hsize 7.2cm \newcommand\sample{Draußen \i \ij\ ffl fluffiest fish \textit{König} \textcolor{bl

Lowercase {\ucshape \sample} Lowercase

437

Lowercase \textuc{\sample} Lowercase % textcolor doesn't work in LaTeX's \MakeUppercase % Lowercase \MakeUppercase{\sample} Lowercase

\end{document} which yields

The program above just manipulates the nodelist iff the given attribute is set (to any value). Attributes are grouped, just like any TeX assignment. It’s a bit more complicated than I thought because we need to treat \hbox{}es separately.

Tags: fontspec (Prev Q) (Next Q), xetex (Prev Q) (Next Q), opentype (Prev Q) (Next Q)

Q: Lualatex : € as a utf8 character is not recognized : why? Tags: fontspec (Prev Q) (Next Q) I need to include some tex files as parts of a more global project. Some of this global projects have to be compiled with pdflatex, some others with lualatex,

438

but the parts are the same. All this part files are written with a € as an utf8 character. I would like avoid to replace them by a \texteuro. Is there a way to make lualatex understand € as a \texteuro ? Skip code block \documentclass[french]{article} \RequirePackage{ifluatex} \ifluatex \RequirePackage{fontspec} \RequirePackage{luacode} \else \RequirePackage[utf8]{inputenc} \RequirePackage[T1]{fontenc} \fi \RequirePackage{fourier} \begin{document} 36\,\texteuro % works with both pdflatex lualatex 36\,€ % doesn't work with lualatex \end{document} Tags: fontspec (Prev Q) (Next Q) User: tarass

Answer by user11232 You can use newunicodechar package and define \newunicodechar{€}{\texteuro} Code: Skip code block \documentclass{article} \RequirePackage{ifluatex} \ifluatex 439

\RequirePackage{fontspec} \RequirePackage{luacode} \else \RequirePackage[utf8]{inputenc} \RequirePackage[T1]{fontenc} \fi \let\hbar\hhhbar %% without this I get a warning \RequirePackage{fourier} \usepackage{newunicodechar} \newunicodechar{€}{\texteuro} \begin{document} 36\,\texteuro % works with both pdflatex lualatex 36\,€ % doesn't work with lualatex \end{document} Then it should work in both pdflatex and lualatex.

Answer by egreg With \usepackage{fourier} you are simply ignoring fontspec and using a family of “classical” 256 character font. You can use classical fonts with LuaLaTeX, without loading fontspec, but luainputenc: Skip code block \documentclass{article} \usepackage{ifluatex} \usepackage[TS1,T1]{fontenc} % load TS1 so luainputenc will know \ifluatex \usepackage{luacode} \usepackage[utf8]{luainputenc} \else \usepackage[utf8]{inputenc} \fi 440

\usepackage{fourier} \begin{document} 36\,\texteuro % works with both pdflatex lualatex 36\,€ % doesn't work with lualatex \end{document} Of course this will not use the full strengths of LuaLaTeX as regards to fonts, but it’s impossible anyway if you want your document to be processable with LuaLaTeX and pdfLaTeX (and loading luacode doesn’t make much sense). A probably better solution is to use a text font replacement for Utopia, such as the very recent Erewhon font: Skip code block \documentclass{article} \usepackage{ifluatex} \ifluatex \usepackage{luacode} \usepackage{fourier} \usepackage{fontspec} \setmainfont{Erewhon} \else \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage{fourier} \fi

\begin{document} 36\,\texteuro % works with both pdflatex lualatex 36\,€ % doesn't work with lualatex Some math $a+\mathrm{a}=\int_{0}^{1} f(x)\,dx$ \end{document}

441

Tags: fontspec (Prev Q) (Next Q)

Q: Kerning and ligatures in TeX without TeX Tags: fontspec (Prev Q) (Next Q), ligatures (Prev Q) (Next Q) I am trying to get the same output as in this answer by topskip (an extended version with comments is presented in the TeX without TeX article). I am getting a paragraph consisting of 6 lines with hyphenation, but kerning and ligatures are lost (turned off?) as it can be seen around the character V in VLTAVA and in the letters ffi in office. I use WinXP + TeX Live 2014 and Lubuntu 13.10 + TeX Live 2013. I’ve got the same output, the font is LinLibertine_R.otf. First tip by topskip is to skip loading of the fontspec package which could handle things differently than the luaotfload package. Therefore, instead of libertine and luatextra (they both load the fontspec package), I tried to load luacode and luaotfload packages directly, no success, no errors and no warnings. Where the problem might be? We run lualatex testfonts.tex. Skip code block % lualatex testfonts.tex \documentclass[a4paper]{article} \pagestyle{empty} 442

%\usepackage{luatextra} %\usepackage{libertine} \usepackage{luaotfload} \usepackage{luacode} \begin{document} \font\main={file:LinLibertine_R.otf} \main \begin{luacode*} function count_lines (head) local linecount = 0 while head do if head.id == 0 then linecount = linecount + 1 end head = head.next end return linecount end function mknodes( text ) local current_font = font.current() local font_parameters = font.getfont(current_font).parameters local n, head, last -- we should insert the paragraph indentation at the beginning head = node.new("glue") head.spec = node.new("glue_spec") head.spec.width = 20 * 2^16 last = head for s in string.utfvalues( text ) do local char = unicode.utf8.char(s) if unicode.utf8.match(char,"%s") then -- its a space n = node.new("glue") n.spec = node.new("glue_spec") n.spec.width = font_parameters.space n.spec.shrink = font_parameters.space_shrink n.spec.stretch = font_parameters.space_stretch 443

else -- a glyph n = node.new("glyph") n.font = current_font n.subtype = 1 n.char = s n.lang = tex.language n.uchyph = 1 n.left = tex.lefthyphenmin n.right = tex.righthyphenmin end last.next = n last = n end -- now add the final parts: a penalty and the parfillskip glue local penalty = node.new("penalty") penalty.penalty = 10000 local parfillskip = node.new("glue") parfillskip.spec = node.new("glue_spec") parfillskip.spec.stretch = 2^16 parfillskip.spec.stretch_order = 2 last.next = penalty penalty.next = parfillskip -- just to create the prev pointers for tex.linebreak node.slide(head) return head end local txt = "VLTAVA office A wonderful serenity has taken possession of my entire tex.baselineskip = node.new("glue_spec") tex.baselineskip.width = 14 * 2^16 local head = mknodes(txt) 444

lang.hyphenate(head) head = node.kerning(head) head = node.ligaturing(head) local vbox local size = 90 lines = 0 lines_goal = 6

while lines < lines_goal do texio.write_nl(string.format("Formatting text to %d mm",size)) local copy_of_head = node.copy_list(head) vbox = tex.linebreak(copy_of_head,{ hsize = tex.sp(string.format("%dmm",size))}) size = size - 10 lines = count_lines(vbox) texio.write_nl(string.format("lines=%d",lines)) end node.write(vbox) \end{luacode*} VLTAVA office \end{document}

Tags: fontspec (Prev Q) (Next Q), ligatures (Prev Q) (Next Q)

445

User: malipivo

Answer by michal.h21 For opentype fonts, luaotfload provide function nodes.simple_font_handler which will take care of all font manipulations like ligaturing and kerning and all other features supported by luaotfload. This function isn’t advertised in the manual, I’ve found it in luaotfload source code. It is called as node callback on normal text, but as you create nodes directly from Lua, it doesn’t take effect on your text and you have to call it explicitly: local head = mknodes(txt) lang.hyphenate(head) head = nodes.simple_font_handler(head) you don’t have to call node.ligaturing and node.kerning any more, they were called from simple_font_handler already

Tags: fontspec (Prev Q) (Next Q), ligatures (Prev Q) (Next Q)

446

Q: Getting started with Greek and Hebrew in LuaLaTeX Tags: fontspec (Prev Q) (Next Q) I am typesetting a 17th century English theological document that uses a smattering of Greek and Hebrew. I am using LuaLaTeX with TeXShop on the Mac. Is LuaLaTeX up to the task? If so what are the basic steps needed to get accented Greek and pointed Hebrew? Is it possible to have English sentences interspersed with occasional Gk and Heb words, or can they (esp Heb) only be set in their own paragraphs? My plan was to use SBL Greek and Ezra SIL Hebrew fonts. Are these reasonable choices? Ideally I would like to be pointed to a tutorial that describes this stuff from the ground up (or rather, as suitable for someone with a Lamport understanding of LaTeX). But short of that I’m throwing myself on the mercy of knowledgable strangers! Tags: fontspec (Prev Q) (Next Q) User: paul-dulaney

Answer by clinteastwood LuaLaTeX is your choice! Greek is possible without any adjustments. Hebrew, as it is a language from right to left, needs adjustments. Of course, you need to use \usepackage{fontspec} in the preamble (as is usual when using LuaLatex). Greek You need a font that supports all the accents. If your mainfont for latin text does not support them, you need to implement a special greek font: \newfontfamily\greekfont[Script=Greek, Scale=MatchUppercase, Ligatures=TeX]{GREEK \newcommand{\textgreek}[1]{\bgroup\greekfont\emph{#1}\egroup} If your main font does support them you can just use: 447

\newcommand{\textgreek}[1]{\emph{#1}} I use a command like this for my greek passages, because so it stays possible to decide later whether the Greek words should be italicized or bold or whatever or not. This command sets Greek text in italics, because of the \emph{…} if you don’t want this, delete it.) Now you should be able to set Greek text inside Latin text by entering: \textgreek{�������}. Hebrew You need to set up a font and the settings for right-to-left-text: \newfontfamily\hebfont[Script=Hebrew, Scale=MatchUppercase, Ligatures=TeX]{HEBREW \newcommand{\textheb}[1]{\bgroup\luatextextdir TRT\hebfont #1\egroup} Now you should be able to set Hebrew text inside Latin text by entering: \textheb{�����}. Typographic Advice You should use a font that already contains Latin and Greek accented characters. If you’re lucky, you’ll find (a good) one that also contains Hebrew. Thereby you assure that the three languages have the same font style. It may not be a good idea to use three different fonts - except if they resemble each other in style. Have a look at the Brill Font. Palatino also has nice Greek. Or, if you want an expensive one, Adobe Garamond. I don’t know anything about Hebrew fonts. Entire Example Code of heb.tex Skip code block % !TEX TS-program = lualatexmk \documentclass[11pt, a4paper]{scrartcl} \usepackage{fontspec} 448

\setmainfont{Times New Roman} \newfontfamily\greekfont[Script=Greek, Scale=MatchUppercase, Ligatures=TeX]{Arial \newcommand{\textgreek}[1]{\bgroup\greekfont\emph{#1}\egroup} % Please note, that

\newfontfamily\hebfont[Script=Hebrew, Scale=MatchUppercase, Ligatures=TeX]{Ezra SI \newcommand{\textheb}[1]{\bgroup\luatextextdir TRT\hebfont #1\egroup} \begin{document} This is \textgreek{�������} Greek. And this is \textheb{�����} Hebrew. \end{document}

Tags: fontspec (Prev Q) (Next Q)

Q: fontspec: what does Renderer=Basic do? Tags: fontspec (Prev Q) (Next Q) I’m writing a document using LuaLaTeX on Windows, using Arial (please do not comment on that) as its main font with: \usepackage{fontspec} \defaultfontfeatures{Ligatures=TeX} \setmainfont[Renderer=Basic]{Arial} To keep the usual TeX substitutions I used Ligatures=TeX, but this does not work unless using Renderer=Basic additionally. Tags: fontspec (Prev Q) (Next Q) User: mkluwe

Answer by khaled-hosny

449

luaotfload (the package doing OpenType layout under the hood for LuaLaTeX) has two font processing modes; base mode which tries to made as much of OpenType lookups to traditional TeX ligaturing and kerning mechanisms (think of it like creating TFM files from OpenType fonts on the fly) and it is limited by what TeX can traditionally support, and node mode which tries to do faithful OpenType processing entirely in Lua. fontspec’s Renderer=Basic maps to the former, and Renderer=Full maps to the later. Why Renderer=Basic is needed for Ligatures=TeX to work with some fonts, is an artefact of how this feature is implemented in luaotfload, it is a bug actually, but the development of luaotfload is stalled…

Tags: fontspec (Prev Q) (Next Q)

Q: Is it possible now to use microtype with opentype fonts? Tags: fontspec (Prev Q) (Next Q), microtype (Prev Q) (Next Q) LuaTeX has limited support for microtypograhpy now, and it can be invoked if only type1 fonts are used. But is it possible for microtype to work with opentype fonts loaded with fontspec now? I have searched the Internet for this, but most of the relevant information is outdated. Tags: fontspec (Prev Q) (Next Q), microtype (Prev Q) (Next Q) User: siyuan-ren

Answer by mico You ask whether it [is] possible for microtype to work with OpenType fonts loaded with fontspec. The short answer is yes. A longer answer would add that microtype’s functionality under LuaLaTeX isn’t as complete as it is under pdfLaTeX. However, the limitations are not caused by the use of OpenType fonts. 450

The version of microtype that’s currently distributed with TeXLive 2012 and MikTeX 2.9 is still version 2.4. However, a late-beta edition of version 2.5 of the microtype package, dated 2012-05-23, may be downloaded from http: //tlcontrib.metatex.org/cgi-bin/package.cgi/action=view/id=608. This version, when run under LuaLaTeX, still isn’t as capable as when it’s run under pdfLaTeX, but it comes a lot closer than if you stick with version 2.4. You ask in a follow-up comment how version 2.5 of microtype might be installed manually under MikTeX. Do you have a ”local” directory set up among the directories that are searched by MikTeX? (Bring up the ”Settings” app of MikTeX to find out.) If not, do set up such a directory. Then, you could • make sure that this local directory is topmost in the search order (so that the version of microtype to be installed by you in the local directory are seen before the ”official” but now somewhat obsolete version that’s still distributed with MikTeX 2.9); • copy the files of microtype 2.5 beta to subdirectories of the local directory (such as ..\tex\latex\microtype and ..\doc\microtype); and • update MikTeX’s filename database; the particulars of this update process will depend on whether or not you installed MikTeX in ordinary mode or admin mode.

Update: Version 2.5a of the microtype package was released in May 2013.

Tags: fontspec (Prev Q) (Next Q), microtype (Prev Q) (Next Q)

Q: using Hoefler Text font under lualatex and MacOSX Tags: fontspec (Prev Q) (Next Q) I’m having unexpected problems getting the ”Hoefler Text” font to work when using LuaLaTeX (under MacTeX2012, all the latest updates installed) 451

on a Mac (MacOS X 10.7.4). The following MWE \documentclass{article} \usepackage{fontspec} \setmainfont{Hoefler Text} \begin{document} Hello World. \end{document} throws the following error message when run under LuaLaTeX: ! fontspec error: "font-not-found" ! ! The font "HoeflerText" cannot be found. Oddly, the very same MWE when run under XeLaTeX does not throw an error. The font is present on my Mac, under /Library/Fonts/, with a filename of Hoefler Text.ttc. For what it’s worth, this seems to one of very few fonts in this directory with this filename extension (which I believe Apple calls ”Truetype font collection”); almost all others have extensions such as .ttf and .otf. Is there something special about Hoefler Text on a Mac that requires a special font-loading sequence to work under LuaLaTeX? Addendum: Since first posting this question, I’ve learned from the comments and answer that this problem appears to affect all fonts stored in .ttc format on a Mac system, not just Hoefler Text. Tags: fontspec (Prev Q) (Next Q) User: mico

Answer by egreg For some reasons, the font loading mechanism of LuaLaTeX maintains a ”black list” for Mac OS X fonts, where all .ttc fonts are inserted; the file is /usr/local/texlive/2012/texmf-dist/tex/luatex/luaotfload/otfl-blacklist.cnf and its contents is Skip code block 452

% Tackes ages to load LastResort.ttf % a MacOSX font, but also available for free from unicode.org % Mac OS X TTC fonts, this list need to be filtered out /Library/Fonts/AmericanTypewriter.ttc /Library/Fonts/Baskerville.ttc /Library/Fonts/Chalkboard.ttc /Library/Fonts/Cochin.ttc /Library/Fonts/Copperplate.ttc /Library/Fonts/Didot.ttc /Library/Fonts/Futura.ttc /Library/Fonts/GillSans.ttc /Library/Fonts/Hoefler Text.ttc /Library/Fonts/MarkerFelt.ttc /Library/Fonts/Optima.ttc /Library/Fonts/Papyrus.ttc /Library/Fonts/STHeiti Medium.ttc /System/Library/Fonts/AquaKana.ttc /System/Library/Fonts/HelveticaNeue.ttc /System/Library/Fonts/LucidaGrande.ttc /System/Library/Fonts/Menlo.ttc /System/Library/Fonts/STHeiti Light.ttc You may modify the file, but there’s no guarantee that the font will work. I’ve found an old thread on the lualatex-dev list that deals with this problem. Added Thanks to Mico’s for experimenting the issue. The only font that seems to give problem is ”LastResort” that should be kept in the black list. Doing

sudo nano /usr/local/texlive/2012/texmf-dist/tex/luatex/luaotfload/otfl-blacklist. and putting a % in front of each line after % Mac OS X TTC fonts, this list need to be filtered out 453

followed by a call of mkluatexfontdb will make all .ttc fonts available for LuaLaTeX.

Tags: fontspec (Prev Q) (Next Q)

Q: fontspec throwing error with lualatex - broken? Tags: fontspec (Prev Q) (Next Q) I get an error when I try to include the fontspec package. Here is a minimum working example: \documentclass{article} \usepackage{fontspec} \begin{document} Hello \end{document} I’m trying to compile this using the following build command: lualatex --file-line-error-style "%f". Part of the output that I get is: Skip code block /usr/share/texlive/texmf-dist/tex/latex/base/fontenc.sty:100: Font \EU2/lmr/m/n/ 10=file:lmroman10-regular:script=latn;+trep;+tlig; at 10pt not loadable: metric data not found or bad.

relax l.100 \fontencoding\encodingdefault\selectfont ? /usr/share/texlive/texmf-dist/tex/latex/base/fontenc.sty:100: Emergency stop.

relax l.100 \fontencoding\encodingdefault\selectfont 269 words of node memory still in use: 454

2 hlist, 1 rule, 1 kern, 1 attribute, 41 glue_spec, 1 attribute_list, 2 if_st ack, 1 write, 1 dir nodes avail lists: 2:8,3:1,4:1,6:2,9:2 /usr/share/texlive/texmf-dist/tex/latex/base/fontenc.sty:100: ==> Fatal error o ccurred, no output PDF file produced! I would greatly appreciate any insight that you may have on this issue. I am using Linux Mint 16, with the standard texlive-luatex available in the repositories. Thank you. Edit: upon request from user phg, here is the output from luaotfload-tool --version luaotfload-tool version “2.3” database version “2.207” Lua interpreter: stock; version “Lua 5.2” and luaotfload-tool --diagnose=environment,permissions Skip code block luaotfload luaotfload luaotfload luaotfload luaotfload luaotfload luaotfload luaotfload luaotfload luaotfload luaotfload luaotfload luaotfload luaotfload luaotfload luaotfload luaotfload luaotfload luaotfload luaotfload

| | | | | | | | | | | | | | | | | | | |

diagnose diagnose diagnose diagnose diagnose diagnose diagnose diagnose diagnose diagnose diagnose diagnose diagnose diagnose diagnose diagnose diagnose diagnose diagnose diagnose

: : : : : : : : : : : : : : : : : : : :

Loading file hashes. =============== file permissions ============== Checking permissions of /home/alex/.texmf-var/luatex-cache Owner: 1000, group 1000, permissions rwxrwxr-x. Readable: ok. Writable: ok. Checking permissions of /home/alex/.texmf-var/luatex-cache Owner: 1000, group 1000, permissions rwxrwxr-x. Readable: ok. Writable: ok. Checking permissions of /home/alex/.texmf-var/luatex-cache Owner: 1000, group 1000, permissions rw-rw-rw-. Readable: ok. Writable: ok. Checking permissions of /home/alex/.texmf-var/luatex-cache Owner: 1000, group 1000, permissions rw-rw-rw-. Readable: ok. Writable: ok. Checking permissions of /home/alex/.texmf-var/luatex-cache Owner: 1000, group 1000, permissions rw-rw-rw-. 455

luaotfload luaotfload luaotfload luaotfload luaotfload luaotfload luaotfload

| | | | | | |

diagnose diagnose diagnose diagnose diagnose diagnose diagnose

: : : : : : :

Readable: ok. Writable: ok. Checking permissions of /home/alex/.texmf-var/luatex-cache Owner: 1000, group 1000, permissions rw-rw-rw-. Readable: ok. Writable: ok. Everything appears to be in order, you may sleep well

Thanks for the prompt feedback! Tags: fontspec (Prev Q) (Next Q) User: castle-bravo

Answer by kragol I have just faced the same problem and it turns out that the solution was to install the lmodern package. If I understand correctly this also installs the fonts-lmodern package which contains the missing font file lmroman10-regular that lualatex was complaining about. (lmodern seems to contain font files for pdfTeX) The conclusion is that this is perhaps not a TeX problem but rather a package dependency problem in the Linux Mint distribution (I am on Linux Mint Debian Edition). Still it seems a bit weird that lualatex requires a font that is not even used in the document.

Answer by mimoralea You might be missing a required package, try: sudo apt-get install texlive-luatex Then, try the update: luaotfload-tool --update

Tags: fontspec (Prev Q) (Next Q)

456

Q: tabular numbers in tables, proportional in text Tags: fontspec (Prev Q) (Next Q) I’m using LuaTeX with a font that has proportional, lining and tabular numbers available. Is it possible to set things up so tables automatically use tabular numbers but proportional numbers are used in the text? Tags: fontspec (Prev Q) (Next Q) User: davidc

Answer by uli There is a package called tabfigures which I have not tried yet.

Tags: fontspec (Prev Q) (Next Q)

Q: Replacing Unicode non-breakable spaces by normal spaces Tags: fontspec (Prev Q) (Next Q), xetex (Prev Q) (Next Q), unicode-math (Prev Q) (Next Q), unicode (Prev Q) (Next Q) I am using the Neo keyboard layout, which uses all kinds of modifier keys to input all kinds of characters (e.g. Greek letters and mathematical symbols). It also has shift+Mod3+space mapped to Unicode 0A, no-break space. From time to time it happens that I mistakenly press these buttons (while entering a space between other symbols with the same modifier keys). Unfortunately [Lua|Xe]TeX obeys these spaces as unbreakable spaces both in normal text and in mathmode (using fontspec and unicode-math). However my editor (vim) shows the symbol like a normal space, so it is impossible to see where I made a mistake.

457

Is there an easy way to tell [Lua|Xe]TeX to treat no-break spaces like normal spaces? Tags: fontspec (Prev Q) (Next Q), xetex (Prev Q) (Next Q), unicode-math (Prev Q) (Next Q), unicode (Prev Q) (Next Q) User: caramdir

Answer by egreg \usepackage{newunicodechar} \newunicodechar{ }{ } In the first argument you put a NO-BREAK SPACE (U+00A0), in the second a normal space. A better definition would be \newunicodechar{ }{~} (again the space is NO-BREAK SPACE), so this unbreakable space will stretch or shrink wit the other spaces in the line. Of course use the first one if you want a normal space, ça va sans dire. :)

Answer by aditya Another solution will be to change vim setup so that you can see the nonbreakable space. set listchars=nbsp:¬ set list You can set appropriate syntax highlighting for NonText to highlight the non-breakable space.

Tags: fontspec (Prev Q) (Next Q), xetex (Prev Q) (Next Q), unicode-math (Prev Q) (Next Q), unicode (Prev Q) (Next Q)

458

Q: Check for missing font characters in LuaLaTeX Tags: fontspec (Prev Q) (Next Q) I have a document: \documentclass{article} \usepackage{fontspec} \begin{document} Program the �C, please. \end{document} When I compile with xelatex or lualatex, there is a missing ”�” character in the output. This makes sense because the default font doesn’t contain that character, but I need to know when it happens. With xelatex, the log file contains a warning: Missing character: There is no � in font [lmroman10-regular]:mapping=tex-text! Cool. But with lualatex, the output is wrong and there’s not a single warning or error to be found. How can I detect missing characters in LuaLaTeX? It seems that ConTeXt can use \checkcharactersinfont or \enabletrackers[fonts.missing], while XeLaTeX controls it with \tracinglostchars=2. Tags: fontspec (Prev Q) (Next Q) User: jim-paris

Answer by philipp-gesang Here is an adaptation of the Context code for missing glyphs: https://gist. github.com/phi-gamma/5812290. As the character table shipped with luaotfload is currently experimental, it doesn’t contain the necessary metadata. Thus the code requires the full version of char-def.lua from a Context distribution (installing the Context packages from TL should suffice). Usage: \startreportmissingglyphs initializes the tracker. Its counterpart, \stopreportmissingglyphs, disables the glyph checker. Example:

459

\startreportmissingglyphs ... some text ... \stopreportmissingglyphs If invoked with the optional argument [once], \startreportmissingglyphs will report each missing character only once per font. Example output:

Note that due to the nature of the Luatex callbacks involved, the glyph checker works on a per-paragraph basis, and \stopreportmissingglyphs will force a paragraph end. For reference, I include the full example including the definitions of interface macros from the gist: Skip code block \documentclass{article} \usepackage{luacode,fontspec} %% 1) initialize the tracker code (could go to separate file) \makeatletter \directlua{dofile "track-missing-glyphs.lua"} %% 2) Environment start: the optional argument “once”, in square %% brackets, requests that the missing glyph message be printed %% only once per character and font. \def\startreportmissingglyphs{% \@ifnextchar[\[email protected]@indeed% {\[email protected]@indeed[]}% } \def\[email protected]@indeed[#1]{% \directlua{documentdata.missing_glyphs.enable"\luaescapestring{#1}"}% 460

} %% 3) Environment stop: we need to force a \par here to %% have the callback apply to the current paragraph. \def\stopreportmissingglyphs{% \endgraf %% paragraph-based callback! \directlua{documentdata.missing_glyphs.disable()}% } \makeatother %% Usage examples. \begin{document} %% Latin modern lacks glyphs for the Greek script so we use that for %% testing. \startreportmissingglyphs Program the �C, please. %% Works in math mode (different font model) as well. $f = ma$ \stopreportmissingglyphs lorem schmipsum \startreportmissingglyphs[once] %% With the “once” flag, no message is emitted for repetitions of %% missing chars. Θ������, �������. \stopreportmissingglyphs \end{document}

Tags: fontspec (Prev Q) (Next Q)

Q: Contextual Substitution with LuaLateX Tags: fontspec (Prev Q) (Next Q), xetex (Prev Q) (Next Q) Contextual substition doesn’t seem to work with LuaLateX, while it works fine with XeLateX. Am I doing something wrong or is this a bug? 461

\documentclass{article} \usepackage{fontspec} \setmainfont{Linux Libertine O} \begin{document} \textvbaraccent{i} fä f? \end{document} XeLaTeX

LuaLaTeX

(notice the spacing between the upper part of the ’f’ and the first dot of the ’ä’ and the space between the ’f’ and the ’?’) Tags: fontspec (Prev Q) (Next Q), xetex (Prev Q) (Next Q) User: wakimiko

462

Answer by egreg The problem seems to have been solved with the new release of TeX Live 2013 (presently in test version). Here’s the output obtained with Skip code block > lualatex --version This is LuaTeX, Version beta-0.76.0-2013052718 Execute

'luatex --credits'

(TeX Live 2013) (rev 4627)

for credits and version details.

There is NO warranty. Redistribution of this software is covered by the terms of the GNU General Public License, version 2 or (at your option) any later version. For more information about these matters, see the file named COPYING and the LuaTeX source. Copyright 2013 Taco Hoekwater, the LuaTeX Team.

And here’s the file list Skip code block *File List* article.cls size10.clo fontspec.sty expl3.sty

2007/10/19 2007/10/19 2013/05/20 2013/03/14

v1.4h v1.4h v2.3c v4469 463

Standard LaTeX document class Standard LaTeX file (size option) Font selection for XeLaTeX and LuaLaTeX L3 Experimental code bundle wrapper

l3names.sty 2012/12/07 v4346 L3 Namespace for primitives l3bootstrap.sty 2013/01/08 v4420 L3 Experimental bootstrap code luatex.sty 2010/03/09 v0.4 LuaTeX basic definition package (HO) infwarerr.sty 2010/04/08 v1.3 Providing info/warning/error messages (HO) ifluatex.sty 2010/03/01 v1.3 Provides the ifluatex switch (HO) etex.sty 1998/03/26 v2.0 eTeX basic definition package (PEB) luatex-loader.sty 2010/03/09 v0.4 Lua module loader (HO) pdftexcmds.sty 2011/11/29 v0.20 Utility functions of pdfTeX for LuaTeX (HO) ltxcmds.sty 2011/11/09 v1.22 LaTeX kernel commands for general use (HO) ifpdf.sty 2011/01/30 v2.3 Provides the ifpdf switch (HO) l3basics.sty 2013/01/10 v4428 L3 Basic definitions l3expan.sty 2013/02/03 v4458 L3 Argument expansion l3tl.sty 2013/01/08 v4415 L3 Token lists l3seq.sty 2013/01/12 v4434 L3 Sequences and stacks l3int.sty 2013/01/13 v4444 L3 Integers l3quark.sty 2012/11/04 v4268 L3 Quarks l3prg.sty 2013/02/13 v4459 L3 Control structures l3clist.sty 2013/01/08 v4414 L3 Comma separated lists l3token.sty 2013/01/10 v4428 L3 Experimental token manipulation l3prop.sty 2013/01/09 v4423 L3 Property lists l3msg.sty 2013/01/08 v4412 L3 Messages l3file.sty 2013/01/14 v4446 L3 File and I/O operations l3skip.sty 2013/01/13 v4444 L3 Dimensions and skips l3keys.sty 2013/02/24 v4461 L3 Experimental key-value interfaces l3fp.sty 2013/01/19 v4449 L3 Floating points l3box.sty 2013/01/08 v4411 L3 Experimental boxes l3coffins.sty 2012/09/09 v4212 L3 Coffin code layer l3color.sty 2012/08/29 v4156 L3 Experimental color support l3luatex.sty 2012/08/03 v4049 L3 Experimental LuaTeX-specific functions l3candidates.sty 2013/03/14 v4468 L3 Experimental additions to l3kernel xparse.sty 2013/03/12 v4467 L3 Experimental document command parser luaotfload.sty 2013/05/23 v2.2d OpenType layout system luatexbase.sty 2013/05/11 v0.6 Resource management for the LuaTeX macro progr ammer luatexbase-compat.sty 2011/05/24 v0.4 Compatibility tools for LuaTeX luatexbase-modutils.sty 2013/05/11 v0.6 Module utilities for LuaTeX luatexbase-loader.sty 2013/05/11 v0.6 Lua module loader for LuaTeX luatexbase-regs.sty 2011/05/24 v0.4 Registers allocation for LuaTeX 464

luatexbase-attr.sty luatexbase-cctb.sty luatexbase-mcb.sty fontspec-patches.sty

2013/05/11 v0.6 Attributes allocation for LuaTeX 2013/05/11 v0.6 Catcodetable allocation for LuaTeX 2013/05/11 v0.6 Callback management for LuaTeX 2013/05/20 v2.3c Font selection for XeLaTeX and LuaLaTeX

fixltx2e.sty 2006/09/13 v1.1m fixes to LaTeX fontspec-luatex.sty 2013/05/20 v2.3c Font selection for XeLaTeX and LuaLaTeX fontenc.sty eu2enc.def 2010/05/27 v0.1h Experimental Unicode font encodings eu2lmr.fd 2009/10/30 v1.6 Font defs for Latin Modern xunicode.sty 2011/09/09 v0.981 provides access to latin accents and many othe r characters in Unicode lower plane eu2lmss.fd 2009/10/30 v1.6 Font defs for Latin Modern graphicx.sty 1999/02/16 v1.0f Enhanced LaTeX Graphics (DPC,SPQR) keyval.sty 1999/03/16 v1.13 key=value parser (DPC) graphics.sty 2009/02/05 v1.0o Standard LaTeX Graphics (DPC,SPQR) trig.sty 1999/03/16 v1.09 sin cos tan (DPC) graphics.cfg 2010/04/23 v1.9 graphics configuration of TeX Live pdftex.def 2011/05/27 v0.06d Graphics/color for pdfTeX fontspec.cfg t3cmr.fd 2001/12/31 TIPA font definitions supp-pdf.mkii epstopdf-base.sty 2010/02/09 v2.5 Base part for package epstopdf grfext.sty 2010/08/19 v1.1 Manage graphics extensions (HO) kvdefinekeys.sty 2011/04/07 v1.3 Define keys (HO) kvoptions.sty 2011/06/30 v3.11 Key value format for package options (HO) kvsetkeys.sty 2012/04/25 v1.16 Key value parser (HO) etexcmds.sty 2011/02/16 v1.5 Avoid name clashes with e-TeX commands (HO) epstopdf-sys.cfg 2010/07/13 v1.3 Configuration of (r)epstopdf for TeX Live ***********

Tags: fontspec (Prev Q) (Next Q), xetex (Prev Q) (Next Q)

465

Q: Why does fontspec change the maths accents (and only with lualatex)? Tags: fontspec (Prev Q) (Next Q), math-mode (Prev Q) (Next Q) In the minimal example that follows luatex doesn’t place the accent correctly (it’s too far left): \documentclass{minimal} \usepackage{fontspec} \setromanfont{Linux Libertine O} \begin{document} \(\bar E\) \end{document} But if I compile it with xelatex, or with lualatex and \setromanfont{Linux Libertine O} commented out, everything works fine. I believed that fonspec was only for text, and not for math. So why this strange behaviour ? Tags: fontspec (Prev Q) (Next Q), math-mode (Prev Q) (Next Q) User: matsaya

Answer by egreg This is what I get when calling \showlists after the formula: LuaTeX Skip code block ### horizontal mode entered at line 6 \whatsit .\localinterlinepenalty=0 .\localbrokenpenalty=0 .\localleftbox=null .\localrightbox=null \hbox(0.0+0.0)x20.0, direction TLT 466

\mathon \vbox(8.20554+0.0)x7.95831, direction TLT .\hbox(5.67776+0.0)x0.0, direction TLT ..\OT1/cmr/m/n/10 ^^V .\kern-4.30554 .\hbox(6.83331+0.0)x7.95831, direction TLT ..\OML/cmm/m/it/10 E \mathoff XeTeX Skip code block ### horizontal mode entered at line 6 \hbox(0.0+0.0)x20.0 \mathon \vbox(8.20554+0.0)x7.95831 .\hbox(5.67776+0.0)x0.0, shifted 2.31252 ..\OT1/cmr/m/n/10 ^^V .\kern-4.30554 .\hbox(6.83331+0.0)x7.95831 ..\OML/cmm/m/it/10 E \mathoff There is clearly a problem with LuaTeX; it can be due to fontspec as, when not loading it or loading a different font than Linux Libertine O (I tested Old Standard and TeX Gyre Termes) I get the following: LuaTeX (without Linux Libertine O) Skip code block ### horizontal mode entered at line 6 \whatsit .\localinterlinepenalty=0 .\localbrokenpenalty=0 .\localleftbox=null .\localrightbox=null \hbox(0.0+0.0)x20.0, direction TLT 467

\mathon \vbox(8.20554+0.0)x7.95831, direction TLT .\hbox(5.67776+0.0)x0.0, shifted 2.31252, direction TLT ..\OT1/cmr/m/n/10 ^^V .\kern-4.30554 .\hbox(6.83331+0.0)x7.95831, direction TLT ..\OML/cmm/m/it/10 E \mathoff

Tags: fontspec (Prev Q) (Next Q), math-mode (Prev Q) (Next Q)

Q: fontspec option ”Renderer=Basic” - what does it mean? Tags: fontspec (Prev Q) (Next Q), microtype (Prev Q) (Next Q) Since a few days I’ve been using the fontspec option \setmainfont[Renderer=Basic] ... in order to use the microtype option tracking=true with LuaLaTeX. I have a simple question on this: why does using Renderer=Basic make computing my pdf sooooo much slower. It takes virtually hours now to complete on single run with lualatexmk -- and several (10+) minutes of high-fan-activity computing with the normal lualatex engine. So, again: what does Renderer=Basic mean? And what is the difference to the default? Tags: fontspec (Prev Q) (Next Q), microtype (Prev Q) (Next Q) User: clinteastwood

Answer by philipp-gesang Version 2.4 of Luaotfload (CTAN link) officially supports letterspacing similar to Xetex. You can enable it at font definition time (see the manual for details): \font \mainfont = "file:Iwona-Regular.otf:letterspace=15" at 42pt 468

where the value is a percentage of the requested font size, i.e. 6.3 pt in above example. (Alternatively, you can specify the value directly as a factor using the option kernfactor. In order to achieve the same effect as in the example you would add kernfactor=0.15. The kern factor, though equivalent to letterspace in functionality, makes more sense internally and is to a large extent consistent with the behavior of Context’s \setcharacterkerning family of macros that the letterspacing code is derived from.) This width is inserted as additional kern between glyphs, with special handling for already existing kerns, ligatures, and other denizens of TeX’s node list. In Fontspec terms, the feature should be directly accessible via the LetterSpace key of \fontspec, \set.*font etc. Beware, since this feature is quite new and only tested so much, there may still be some issues with it. Currently (January 2014) there are two bug reports on the tracker that have patches in version 2.4 but require further testing. Also, the output is not guaranteed to be identical with Xetex or the \letterspacefont primitive (or Pdftex, for that matter). For comparison, a short test file: Skip code block \def \testfont {Iwona-Regular.otf} %\def \testfont {lmroman10-regular.otf} %\def \testfont {MinionPro_Regular.otf} \def \testsize {20pt} \ifdefined \directlua \input luaotfload.sty \font \mainfont = "file:\testfont" at \testsize \font \mainfontlskern = "file:\testfont:letterspace=15" at \testsize \letterspacefont \mainfontlsfont = \mainfont 150 \else \font \mainfont = "[\testfont]" at \testsize \font \mainfontlskern = "[\testfont]:letterspace=15" at \testsize \def \mainfontlsfont {} \fi

469

\newdimen \scratchwd \newbox \scratchbox \def \test #1{% foo \begingroup #1% \setbox \scratchbox \hbox {bar baz}% \global \scratchwd = \wd \scratchbox% \box \scratchbox \endgroup\ bar (\the \scratchwd) \endgraf } \mainfont \test \mainfontlskern %% font kerning \test \mainfontlsfont %% increased sidebearings \bye The values for \letterspacefont and the letterspace option may differ in subtle ways. According to the Pdftex manual, This primitive creates an instance of \Something{font} with the widths of all glyphs increased by \Something{integer} thousandths of an em (as set in \Something{font}). The effect is letter spacing, but the glyphs are actually larger (sidebearings are increased), so a single glyph will take more space. Afaics the same holds for the Luatex implementation of \letterspacefont. Since the font size and the em (quad) dimension are identical for most fonts, the output should not differ by much. There is, however, another more visible difference: the \letterspacefont method also affects surrounding spaces whereas letterspace only works between glyphs. This behavior may change in future versions, or the microtype package may add support for adapting the spacing. 470

In summation, there are three approaches to letterspacing in modern TeX: • extending sidebearings of glyphs -- this is the strategy used in Pdftex as well as Luatex’s \letterspacefont. The value is specified in thousandths of an em. • adding spaces between glyphs -- according to the fontspec manual, this is the Xetex approach. The value is specified in hundredths (percent) of the font size. • inserting kerns between glyphs -- this is what Context and Luaotfload do. In Context and Luatofload with the kernfactor option, the value is a factor applied to the font size. Luaotfload’s letterspace option (which is again used by the fontspec package) emulates Xetex in that it interprets the value as hundredths (percent) of the font size.

Post scriptum regarding the original question: fontspec’s Renderer option, when used with Luaotfload, selects one of the two available processing modes. • base mode, which is the default in Context, should be “good enough” for most Latin-based scripts. Usually, though apparently not in OP’s case, it results in faster typesetting. The drawback is that base mode omits most Opentype features, so it is not an option for many scripts. The implementation is in font-otb.lua. • node mode, which is the default in Luaotfload, applies Opentype font features during typesetting, at the cost of a minor performance loss. The features ccmp, locl, rlig, liga, clig, kern, mark, and mkmk are active by default for the DFLT script (in Luaotfload, not Context). You can look up their definition in the Opentype spec. The implementation can be found in font-otn.lua.

Tags: fontspec (Prev Q) (Next Q), microtype (Prev Q) (Next Q)

471

Q: How to typeset a letter or grapheme specimen with alternates? Tags: fontspec (Prev Q) (Next Q), opentype (Prev Q) (Next Q), tikz-pgf (Next Q) I want to print a font specimen for certain letters, each of which should cover a complete A4 page. The Open Type font contains many letters with several glyphs, which are accessible as character variants (cc..), in stylistic sets (ss..), as contextual and positional alternates (calt; init, medi, fina), local or historic forms (locl; hist) or otherwise; some are available through different methods, of course. Some letters are also part of ligatures (liga, dlig, clig, hlig). Most of them can be seen with Access All Alternates (aalt) in GUIs. I’d like to typeset them all at the same font size, which would be considerably larger than \Huge, say 5 cm (140 pt or so). Preferably, they would be put on a background that showed light lines at baseline, x-height, cap-height or ascender-height and descender-height, all determined automatically if possible. The thing is, I have no idea if LuaTeX or Tikz/PGF or a combination thereof is the best tool for the job. The specimens might become part of a .tex document later on, but I could live with independent pages for now. So any pointers in the right direction are appreciated. • How do I draw and, most importantly, correctly position the horizontal lines – automatically? (Background colors to show the “bands” would be okay, too.) • Is there a better way to access glyphs (without Unicode position) by name than shown in the code below? Rough concept Using Linux Libertine as an example without employing OT features yet. Skip code block % !TEX TS-program = LuaLaTeX \documentclass{scrartcl}

472

\usepackage{fontspec,xcolor,libertine,graphicx} \setmainfont[Color=brown]{Linux Libertine O} % access glyph by name with LuaTeX \usepackage{luaotfload,luacode} \begin{luacode} documentdata = documentdata or { } local stringformat = string.format local texsprint = tex.sprint local slot_of_name = luaotfload.aux.slot_of_name documentdata.fontchar = function (chr) local chr = slot_of_name(font.current(), chr, false) if chr and type(chr) == "number" then texsprint (stringformat ([[\char"%X]], chr)) end end \end{luacode} \newcommand\linecolor{gray} \newcommand\lineheight{1mm} \newcommand\linelength{\textwidth}

% \horizontalline{}{}{}{} \newcommand\horizontalline[4]{\relax} % en dash U+002D U+002D U+002D U+2014 ; --- -> em dash U+0027 U+0027 U+0027 U+0022

>

U+2019 U+201D U+201D

; ' -> right single quote ; '' -> right double quote ; " -> right double quote

U+0060 U+0060 U+0060



U+2018 U+201C

; ` -> left single quote ; `` -> left double quote

U+0021 U+0060 U+003F U+0060



U+00A1 U+00BF

; !` -> inverted exclam ; ?` -> inverted question

; additions supported in T1 encoding U+002C U+002C U+201E ; ,, -> DOUBLE LOW-9 QUOTATION MARK U+003C U+003C U+00AB ; LEFT POINTING GUILLEMET 595

U+003E U+003E

U+0410 U+0411 U+0412 U+0413 U+0414 U+0415 U+0416 U+0417 U+0418 U+041A U+041B U+041C U+041D U+041E U+041F U+0420 U+0421 U+0422 U+0423 U+0424 U+0426 U+0427 U+0428 U+042D U+042E U+042F U+0401 U+0430 U+0431 U+0432 U+0433 U+0434 U+0435 U+0436 U+0437

























U+00BB

U+0041 ; A U+0042 ; B U+0056 ; V U+0047 ; G U+0044 ; D U+0045 ; E U+017D ; Ž U+005A ; Z U+004A ; J U+004B ; K U+004C ; L U+004D ; M U+004E ; N U+004F ; O U+0050 ; P U+0052 ; R U+0053 ; S U+0054 ; T U+0055 ; U U+0046 ; F U+0043 ; C U+010C ; Č U+0160 ; Š U+0116 ; Ė U+004A U+0075 U+004A U+0061 U+00CB ; Ë U+0061 ; a U+0062 ; b U+0076 ; v U+0067 ; g U+0064 ; d U+0065 ; e U+017E ; ž U+007A ; z

; >> -> RIGHT POINTING GUILLEMET

; Ju ; Ja

596

U+0438 U+0439 U+043A U+043B U+043C U+043D U+043E U+043F U+0440 U+0441 U+0442 U+0443 U+0444 U+0446 U+0447 U+0448 U+044D U+044E U+044F U+0451 U+0456 U+0406 U+0454 U+0468 U+0425 U+0445 U+0418 U+0429 U+042A U+042B U+042C U+0449 U+044A U+044B U+044C

























U+0069 U+006A U+006B U+006C U+006D U+006E U+006F U+0070 U+0072 U+0073 U+0074 U+0075 U+0066 U+0063 U+010D U+0161 U+0117 U+006A U+006A U+00EB U+0069 U+0049 U+006A U+004A U+0058 U+0078 U+0049 U+0160 U+0027 U+0059 U+2019 U+0161 U+2019 U+0079 U+2019

; i ; j ; k ; l ; m ; n ; o ; p ; r ; s ; t ; u ; f ; c ; č ; š ; ė U+0075 U+0061 ; ë ; i ; I U+0065 U+0065 ; X ; x ; I U+010C ; ' ; Y ; ' U+010D ; ' ; y ; '

; ju ; ja

; je ; Je

; ŠČ

; šč

and run it through teckit_compile to produce the file cyrillic-to-latin.tec file that should be put in a place where XeTeX can find it. Then a document 597

such as the following Skip code block \documentclass{article} \usepackage{fontspec} \setmainfont[Ligatures=TeX]{Linux Libertine O} \usepackage{polyglossia} \setmainlanguage{english} \setotherlanguage{russian} \newfontfamily{\transrussian}[Mapping=cyrillic-to-latin]{Linux Libertine O} \newenvironment{translitterated} {\transrussian\hyphenrules{nohyphenation}\ignorespaces} {\ignorespacesafterend} \begin{document} \begin{russian} ������ — ������� ���������� ���������, ����� ������������ ��������, ���������������� ����� ������������ ������������ ������ � ����� ���������� �������, � ������ ������� �� ������. ���������� �� ����������� ��������� ����� ������ � ������ (��������� �� 1 ������ 2012 ���� — 11 629 116 �������), �� ����� ���������� ������ � ������� ���������� ������� ����. ����� ���������� ��������� �����������. \end{russian} \begin{translitterated} ������ — ������� ���������� ���������, ����� ������������ ��������, ���������������� ����� ������������ ������������ ������ � ����� ���������� �������, � ������ ������� �� ������. ���������� �� ����������� ��������� ����� ������ � ������ (��������� �� 1 ������ 2012 ���� — 11 629 116 �������), �� ����� ���������� ������ � ������� ���������� ������� ����. ����� ���������� ��������� �����������. \end{translitterated} \end{document} 598

will give a result similar to the following

599

600

The nohyphenation in the translitterated environment definition is necessary as XeTeX doesn’t know how to hyphenate translitterated Russian.

Tags: xetex (Prev Q) (Next Q)

Q: Accessing side-bearings in LuaTeX Tags: xetex (Prev Q) (Next Q) This question has been solved, in XeTeX, by this code: \def\kright#1{\leavevmode #1\kern-\XeTeXglyphbounds3 \the\XeTeXcharglyph`#1 } \def\kleft#1{\leavevmode \kern-\XeTeXglyphbounds1 \the\XeTeXcharglyph`#1 #1} which allows me to align text more precisely to the ink by accessing the side-bearing measurements (\XeTeXglyphbounds1 and 3). This XeTeX dependency is currently the only thing stopping me from moving to LuaTeX (mainly for microtype). Is an equivalent function available in LuaTeX, or planned?

After reading a bit more on microtype, could the equivalent effect be achieved by an appropriately-tailored set of character protrusions? That way, my move to LuaTeX might be a lot simpler. Tags: xetex (Prev Q) (Next Q) User: brent.longborough

Answer by philipp-gesang While preparing a font for Luatex, the fontloader also sets up some extra tables inside the font structure that contain the unprocessed data as returned by fontloader.open(). Among these is the glyph data: For every glyph in 601

the font there is some additional information that is not contained in the characters array since it is unnecessary for Luatex to render a font. For instance, this is a dump of the information about the glyph a: Skip code block table={ ["boundingbox"]={ 45, -10, 432, 460 }, ["depth"]=10, ["height"]=460, ["index"]=9, ["name"]="a", ["slookups"]={ ["as_l_1_s"]={ 63209, 63329 }, ["ss_cyrl_l_18_s"]=63209, ["ss_cyrl_l_44_s"]=63329, ["ss_grek_l_17_s"]=63209, ["ss_grek_l_43_s"]=63329, ["ss_l_16_s"]=63209, ["ss_l_37_s"]=63209, ["ss_l_42_s"]=63329, }, ["width"]=512, } There we find everything we need to calculate the sidebearings in the boundingbox array: The first value is the left sidebearing. The third value is the bbox width. (Dimensions are in hundredths of a TeX point.) Skip code block packagedata packagedata.sidebearings local sidebearings

= packagedata or { } = { } = packagedata.sidebearings

local utfbyte local texsprint

= utf.byte = tex.sprint

local get_sidebearings = function (id, char) local tfmdata = font.getfont (id) 602

if not (tfmdata and tfmdata.shared) then return 0, 0 end local descriptions = tfmdata.shared.rawdata.descriptions local glyphdata = descriptions [char] if not glyphdata then --- font lacks the glyph return 0, 0 end local local local local

boundingbox lside wd rside

= = = =

glyphdata.boundingbox boundingbox [1] or 0 boundingbox [3] or glyphdata.width glyphdata.width - wd

inspect (glyphdata) return lside / 100, rside /100 end local sidebearings = function (id, char, left) char = utfbyte (char) local lside, rside = get_sidebearings (id, char) if left then texsprint (tostring (lside), "pt") else texsprint (tostring (rside), "pt") end end packagedata.sidebearings.left = function (char) return sidebearings (font.current (), char, true) end packagedata.sidebearings.right = function (char) return sidebearings (font.current (), char, false) 603

end Now we can wrap those functions on the TeX end like so: \def \lsidebearing #1{% \directlua {packagedata.sidebearings.left [[#1]]}% } \def \rsidebearing #1{% \directlua {packagedata.sidebearings.right [[#1]]}% } These can be used just like \XeTeXglyphbounds with the argument 1 and 3 respectively. For comparison, here is a test file that runs with both Xetex and Luatex: Skip code block \ifdefined \directlua \input luaotfload.sty \directlua {require "sidebearings"} \def \lsidebearing #1{% \directlua {packagedata.sidebearings.left [[#1]]}% } \def \rsidebearing #1{% \directlua {packagedata.sidebearings.right [[#1]]}% } \font \mainfont = "file:Iwona-Regular.otf" \else \def \lsidebearing #1{\the \XeTeXglyphbounds1 \the \XeTeXcharglyph`#1} \def \rsidebearing #1{\the \XeTeXglyphbounds3 \the \XeTeXcharglyph`#1} \font \mainfont = "[Iwona-Regular.otf]" \fi \mainfont

604

\def \test #1{[#1] left: \lsidebearing {#1}, right: \rsidebearing {#1}\par} \test \test \test \test \test \test \test \test

a b y z � � � �

\bye

Convenience gist of the files.

Answer by topskip Yes and no. When you load the font via the built-in fontloader library (which 605

is very low level), you can access all the information of the font file. This includes the bounding box, as far as I can see (look at the section 4.4.5.1.2 ”Glyph items” in the LuaTeX reference manual). But normally you load the fonts via the fontspec / luaotfload packages, which discard that information and only keep what is needed for TeX. I doubt that inclusion of that information is planned in the luaotfload package, which is based on ConTeXt’s font loader.

Tags: xetex (Prev Q) (Next Q)

Q: Access specific characters in LuaTeX Tags: xetex (Prev Q) (Next Q), symbols (Prev Q) (Next Q) Recently, I switched from XeTeX to LuaTex for a document of mine. However, there is a feature which I do not immediately see how to convert: Accessing specific characters. In particular, I need the upright double quote. In the font I use, however, the standard \dq command produces upper 99 quotes. In XeTeX, I therefore redefined the command: \renewcommand\dq{\XeTeXglyph\XeTeXglyphindex"quotedbl"} 1. How can I do that in general, ie. how can I access all the glyphs in the font, whereever they might be placed (even without a codepoint, perhaps)? 2. Is there another way to access the upright double quote? Tags: xetex (Prev Q) (Next Q), symbols (Prev Q) (Next Q) User: mpi

Answer by alan-munn You should be able to enter any characters from your font directly into your source, just like in XeTeX. With respect to the double upright quote, you need 606

to load the font without the [Ligatures=TeX] option (or if you want the most of the TeX replacements, but not the " replacement, you can specifically turn off the TeX quote replacement feature:) Skip code block \documentclass{article} \usepackage{fontspec} \setmainfont[Ligatures=TeX,RawFeature=-trep]{Linux Libertine O} \begin{document} "This is in upright quotes but will preserve e.g. --- replacement" \addfontfeature{RawFeature=+trep} "This has replaced quotes" \addfontfeature{RawFeature=-trep;-tlig} "This is in upright quotes and doesn't preserve e.g. --- replacement" \end{document} The raw features are described in the luaotfload manual; the rest is plain fontspec. The default behaviour (if you don’t load a font explicitly) is to turn on both features so as to mimic standard TeX behaviour.

Answer by khaled-hosny Assuming you are using luaotfload (which is true if you are using fontspec as well), you can use the lua function fonts.otf.char() which takes either glyph name or glyph index, e.g.: Skip code block \documentclass{article} \usepackage{fontspec} \setmainfont{TeX Gyre Pagella} \def\fontchar#1{\directlua{fonts.otf.char("#1")}} \def\dq{\fontchar{quotedbl}} \begin{document} \dq 607

\end{document}

Tags: xetex (Prev Q) (Next Q), symbols (Prev Q) (Next Q)

Q: Do XeTeX and LuaTeX always use Unicode? Tags: xetex (Prev Q) (Next Q), pdftex (Prev Q) (Next Q), unicode (Prev Q) (Next Q), tex-core (Prev Q) (Next Q) I am writing some functions to manipulate strings. A typical way to produce a character with a given character code is the \lowercase primitive. The following code produces a character with code 234, and displays it to the terminal. \lccode`*=234 \lowercase{\message{*}} If I replace 234 by 345 above, then pdfTeX raises an error: Invalid code (345), should be in the range 0..255. On the other hand, LuaTeX and XeTeX are happy up to 1114111, as expected from a Unicode-compliant engine. Now, I want my macros to be as robust as possible. Is it always true that the maximum lccode is 255 in pdfTeX and 1114111 in LuaTeX and XeTeX? Or can a user prevent in any way the engine from using the full range, hence confusing my macros? Tags: xetex (Prev Q) (Next Q), pdftex (Prev Q) (Next Q), unicode (Prev Q) (Next Q), tex-core (Prev Q) (Next Q) User: bruno-le-floch

Answer by ulrike-fischer The LuaTeX manual says quite clearly that \char now accepts values between 0 and 1114111 and extends this statement to the other similar com-

608

mands like \lccode. As far as I know this is true in XeTeX too. And IMHO a command line to change this seems rather senseless. But the eTeX extension can be disabled in both engines. Or more precisely: XeTeX has a command line option to enable the eTeX extension (which is used by default by all TeX Systems) and LuaTeX has a similar feature. So it is possible to build a format manually which doesn’t use them. But this affects only the eTeX relevant commands.

Tags: xetex (Prev Q) (Next Q), pdftex (Prev Q) (Next Q), unicode (Prev Q) (Next Q), tex-core (Prev Q) (Next Q)

Q: PDF/X-1a on TeX Live 2014 for publishing with POD lightining source Tags: xetex (Prev Q) (Next Q) I am trying to get a PDF/X-1a compliant PDF for sending the pdf to Lightning Source for publishing books. I searched and found the following post and tested it PDF/A with hyperref on TeX Live 2013 And ran the following code in TexStudio Skip code block % =============================== % Filename: test.tex \documentclass{article} % % % %

=============================== Embedding the color profile. Requires eciRGB_v2.icc in the working directory http://www.eci.org/_media/downloads/icc_profiles_from_eci/ecirgbv20.zip

609

\pdfminorversion 4 \immediate\pdfobj stream attr{/N 3} file{eciRGB_v2.icc} \pdfcatalog{% /OutputIntents [ > ] } \usepackage{xcolor} \usepackage{hyperxmp} \usepackage[pdftex, pdfa, linktoc=none]{hyperref} % ---------------------------------------------% Add metadata \hypersetup{% pdftitle={Title}, pdfauthor={Author}, pdfauthortitle={Title of the Author}, pdfcopyright={Copyright (C) 20xx, Copyrightholder}, pdfsubject={Something}, pdfkeywords={Keyword1, Keyword2}, pdflicenseurl={http://creativecommons.org/licenses/by-nc-nd/3.0/}, pdfcaptionwriter={Scott Pakin}, pdfcontactaddress={Street}, pdfcontactcity={City}, pdfcontactpostcode={101}, pdfcontactcountry={Country}, pdfcontactemail={[email protected]}, pdfcontacturl={http://www.institute.edu}, pdflang={en}, bookmarksopen=true, bookmarksopenlevel=3, 610

hypertexnames=false, linktocpage=true, plainpages=false, breaklinks } \begin{document} What cat says? \label{meow} See question on page \pageref{meow}. \end{document} Then ran the Preflight in Adobe Acrobat Pro XI, for PDF/A-1b varification, it came out with no problems. how changes do we have to make it to work with PDF/X-1a and PDF/X-3? Is there a way to get PDF/X-1a fully compliant pdf with PDFLaTex or XeLateX or LuaLaTeX? Tags: xetex (Prev Q) (Next Q) User: ibn-saeed

Answer by dg’ Update: Since the original answer, the PDF api in luatex changed. In order to use this code you have to load luatex85 This should do the trick for PDF/X-1a (you need ISOcoated_v2_300_eci.icc in the current directory): Skip code block % =============================== % Filename: test.tex \documentclass{article} % =============================== % Embedding the color profile. % Requires ISOcoated_v2_300_eci.icc in the working directory 611

% http://www.eci.org/_media/downloads/icc_profiles_from_eci/eci_offset_2009.zip \usepackage{luatex85} \pdfminorversion=3 \pdfpageattr{/MediaBox[0 0 595 793] /BleedBox[0 0 595 793] /TrimBox[25 20 570 773]} \immediate\pdfobj stream attr{/N 4} file{ISOcoated_v2_300_eci.icc} \pdfcatalog{% /OutputIntents [ > ] } \pdfinfo{% /Title(Title)% /GTS_PDFXVersion (PDF/X-1:2001)% /GTS_PDFXConformance (PDF/X-1a:2001)% } \usepackage[cmyk]{xcolor} \usepackage{hyperxmp} \usepackage[pdftex, draft]{hyperref} \begin{document} What cat says? \label{meow} See question on page \pageref{meow}. \end{document} Works with pdflatex and lualatex but not xelatex.

Tags: xetex (Prev Q) (Next Q)

612

Q: Fix message about outdated xelatex Tags: xetex (Prev Q) (Next Q), polyglossia (Next Q) I’m a new to (La)Tex. The problem I’m having it that every output document (pdf) starts with Your xelatex format appears to be outdated!Please update your system and recreate it with fmtutil. I’m using LuaTeX (I need unicode) and TeXlipse on Arch Linux. Here is the output from the command: http://pastie.org/5351646 (out of the Eclipse console) and here is the output from lualatex small2e: http: //pastie.org/5351655 Here is the preamble: Skip code block \documentclass{article} \usepackage[Ligatures=TeX]{fontspec} \setmainfont[Ligatures=TeX]{DejaVu Serif} \setsansfont[Ligatures=TeX]{DejaVu Sans} \setmonofont[Ligatures=TeX]{DejaVu Sans Mono} \usepackage{polyglossia} \setmainlanguage{bulgarian} \usepackage{minted}

\begin{document} % ... rest of document with Cyrillic in it

I will update the question with more details as soon as I know what they should be Tags: xetex (Prev Q) (Next Q), polyglossia (Next Q)

613

User: emil-ivanov

Answer by egreg The error message you get is ! Undefined control sequence. \[email protected] {Your xelatex format appears to be outdated! so it’s only by chance that you see the ”outdated” message. The error is that \[email protected] is not defined and it’s due to the fact that you can’t use Polyglossia with LuaLaTeX, but only with XeLaTeX. You have two possibilities: 1. Compile with LuaLaTeX but load babel \documentclass{article} \usepackage{fontspec} \setmainfont[Ligatures=TeX]{DejaVu Serif} \setsansfont[Ligatures=TeX]{DejaVu Sans} \setmonofont[Ligatures=TeX]{DejaVu Sans Mono} \usepackage[bulgarian]{babel} \usepackage{minted}

\begin{document} �� � ������� ���������������, ������������, �����������, �������� � �������������� ������ �� ��������, ���� � ��� � ������������� 1/6 �� ������������ ������������ �� ��������. \end{document} 2. Compile with XeLaTeX \documentclass{article} \usepackage{fontspec} 614

\setmainfont[Ligatures=TeX]{DejaVu Serif} \setsansfont[Ligatures=TeX]{DejaVu Sans} \setmonofont[Ligatures=TeX]{DejaVu Sans Mono} \usepackage{polyglossia} \setmainlanguage{bulgarian} \usepackage{minted}

\begin{document} �� � ������� ���������������, ������������, �����������, �������� � �������������� ������ �� ��������, ���� � ��� � ������������� 1/6 �� ������������ ������������ �� ��������. \end{document} In both cases the paragraph is typeset as in the following image.

Tags: xetex (Prev Q) (Next Q), polyglossia (Next Q)

Q: British hyphenation with either xelatex or lualatex Tags: xetex (Prev Q) (Next Q), hyphenation (Prev Q) (Next Q), babel (Prev Q) (Next Q), polyglossia (Prev Q) (Next Q) For several reasons, I am working on a source file that should be compilable by either xelatex or lualatex. I would like British hyphenation for the text and am using csquotes and biblatex with british options. On the XeTeX mailing list two things were mentioned: (a) Use polyglossia, not babel with xelatex; 615

(b) polyglossia is incompatible with lualatex at present; use babel instead. I show below a sample file with my question and my present setup. Skip code block

\documentclass[12pt,a4paper]{memoir} % \usepackage{fontspec} \setmainfont{Minion Pro} \setsansfont{Myriad Pro} % % We want to compile with either xelatex or lualatex % The former requires polyglossia for british hyphenation % The latter requires bable for british hyphenation % % Ideally something like (unsure if this is correct) % % \ifxetex % \usepackage{polyglossia} % \setmainlanguage[variant=british]{english} % % \ifluatex % usepackage[british]{babel} % % should work but I do not know the correct syntax for it. % % My workaround is: % \makeatletter \language=\[email protected] \makeatother % % which works but is inelegant in a *LaTeX source file. % \usepackage[backend=biber,babel=none,date=iso8601,urldate=iso8601,language=british \usepackage[english=british]{csquotes} \begin{document} 616

Try some hyphenation, some \enquote{quotations}, and some references to see if e \end{document} Any suggestions to make hyphenation and other language features like date work consistently across both xelatex and lualatex is most welcome. Tags: xetex (Prev Q) (Next Q), hyphenation (Prev Q) (Next Q), babel (Prev Q) (Next Q), polyglossia (Prev Q) (Next Q) User: chandra

Answer by egreg While polyglossia is widely recommended for XeLaTeX usage, babel can still be used for languages that need only the Latin alphabet.

Answer by igor-kotelnikov \usepackage{ifluatex,ifxetex} \ifxetex \usepackage{polyglossia} \setmainlanguage[variant=british]{english} \else\ifluatex \usepackage[british]{babel} \fi\fi This loads polyglossia for xetex and babel for luatex.

Tags: xetex (Prev Q) (Next Q), hyphenation (Prev Q) (Next Q), babel (Prev Q) (Next Q), polyglossia (Prev Q) (Next Q)

Q: XeLaTex and TexMaker ”cannot-use-pdftex” Tags: xetex (Prev Q) (Next Q) I would like to use the CV template provided by this link. 617

In the .tex file the author recommends to compile with XeLaTeX. In TeXmaker 4.0, I’ve used the right option to compile but the following error showed up: ! Fatal fontspec error: ”cannot-use-pdftex” Should I try to compile using the LuaLaTeX support? EDIT The texlive-xetex package was not installed on the system sudo apt-get install texlive-xetex -> Now I can compile. Another error came out: File ‘layaureo.sty’ not found EDIT 2 I installed texlive-lang-italian package sudo apt-get install texlive-lang-italian Now the error is: ! Font \[email protected]=pzdr at 0.00002pt not loadable: Metric (TFM) file or ins Solved using sudo apt-get install texlive-fonts-recommended from my old question Tags: xetex (Prev Q) (Next Q) User: userk

Answer by userk The package required to compile using XeLaTeX was not installed on my linux ditribution. Solved with: sudo apt-get install texlive-xetex

Tags: xetex (Prev Q) (Next Q)

618

Q: Is there a LuaTeX analogue to XeTeXinterchartoks? Tags: xetex (Prev Q) (Next Q) Just as the title of the questions says, is there an LuaTeX analogue to XeTeXinterchartoks? Tags: xetex (Prev Q) (Next Q) User: pmav99

Answer by leo-liu I hope so, but the answer is no. We use \XeTeXinterchartoks mechanism heavily to implement zhspacing and xeCJK packages to support auto font switching and other features or CJK. But we cannot transplant them to LuaTeX. Now the same feature in LuaTeX (zhfonts module of ConTeXt) uses a totally different mechanism to implement: \definefontfallback and pre_linebreak_filter etc. If you want to do similar things in Greek, I hope it would help.

Tags: xetex (Prev Q) (Next Q)

Q: Can XeLaTeX | LuaTeX import movies? Tags: xetex (Prev Q) (Next Q), beamer (Prev Q) (Next Q) It seems that XeLaTeX cannot handle movies. I imported movies into PDF produced with pdflatex compiler using the multimedia package that comes with beamer. My search over various boards revealed that currently there is no package that could import movies under XeLaTeX. Is that correct? And what about LuaLaTeX?

619

UPDATE: This question became obsolete with the advent of media9 package. Tags: xetex (Prev Q) (Next Q), beamer (Prev Q) (Next Q) User: igor-kotelnikov

Answer by cefstat There is a version of movie15.sty called movie15_dvipdfmx.sty, see http: //www.ctan.org/tex-archive/graphics/asymptote/patches/, that allows the inclusion of movies with xelatex with \includemovie. Since it may not be clear, as there is no documentation, the package movie15_dvipdfmx.sty should be passed the option dvipdfmx for use with xelatex, that is, \usepackage[dvipdfmx]{movie15_dvipdfmx}.

Tags: xetex (Prev Q) (Next Q), beamer (Prev Q) (Next Q)

Q: Expex glosses get broken when unicode-math is loaded in XeLaTeX and LuaLaTeX Tags: xetex (Prev Q) (Next Q), unicode-math (Prev Q) (Next Q) I’m trying to typeset multiline numbered examples with John Frampton’s expex package (version 4.1). Since I’m using XeLaTeX (TeXLive 2012), I’ve picked unicode-math to typeset maths. The following MWE illustrates the problem, which is that the first and second lines of the multiline example are no longer separated properly: Skip code block \documentclass{article} \usepackage{fontspec} \usepackage{unicode-math} \usepackage{expex} 620

\setmathfont{Latin Modern Math} \begin{document} \ex \begingl \gla See on lühike tekst {eesti keeles}.// \glb This is short text {in Estonian}// \glft `This is a short text in Estonian.'// \endgl \xe \end{document} The only warning I get is the innocuous xparse/redefine-command warning, and once I remove unicode-math, the output looks as desired. What’s going on here and is there a solution? I should probably add that the same behaviour is observed when I compile with LuaLaTeX. Tags: xetex (Prev Q) (Next Q), unicode-math (Prev Q) (Next Q) User: pavel-rudnev

Answer by egreg The unicode-math package defines a \gla command for a (quite rare) character. You can do it with the following trick: Skip code block \documentclass{article} \usepackage{fontspec} \usepackage{unicode-math} \setmathfont{Latin Modern Math} \usepackage{expex} 621

\let\expexgla\gla \AtBeginDocument{\let\gla\expexgla} \begin{document} \ex \begingl \gla See on lühike tekst {eesti keeles}.// \glb This is short text {in Estonian}// \glft `This is a short text in Estonian.'// \endgl \xe \end{document} The definitions of unicode-math happen at begin document, so you need to redefine \gla to the saved version after that.

Tags: xetex (Prev Q) (Next Q), unicode-math (Prev Q) (Next Q)

Q: Place TikZ picture over top of text Tags: xetex (Prev Q) (Next Q), tikz-pgf (Prev Q) (Next Q) I’m designing some letterhead using LuaLaTeX (interchangeable with XeLaTeX at this point) where I want my signature and name to be drawn like this:

The signature is a TikZ drawing, the text is normal type raised by negative \vspace{}. However, if you look closely, the text is (naturally) on top of the signature, and I would like to reverse that. 622

I understand why it is on top, but not what I can do to reverse it because the text is positioned relative to the sizing of the signature. Because the above MWE example is 3,878 lines, I made a smaller MWE: Skip code block \documentclass{article} \usepackage{tikz} \begin{document} \begin{minipage}{2in} \resizebox{2in}{!}{ \begin{tikzpicture} \draw[color=blue](0,0) circle (2); \end{tikzpicture}}\par \vspace*{-.15in} \resizebox{2in}{!}{Minimum Working Example} \end{minipage} \end{document}

623

The structure is the same, just a simpler drawing and text. Is there any way to force the blue TikZ drawing to display on top of the text below it? Tags: xetex (Prev Q) (Next Q), tikz-pgf (Prev Q) (Next Q) User: ryan

Answer by steven-b.-segletes \documentclass{article} \usepackage{tikz,stackengine} \begin{document} \stackon[-5pt]{\resizebox{2in}{!}{Minimum Working Example}} {\begin{tikzpicture}\draw[color=cyan](0,0) circle (2);\end{tikzpicture}} \end{document} 624

Tags: xetex (Prev Q) (Next Q), tikz-pgf (Prev Q) (Next Q)

Q: How are non-unicode glyphs referenced in LuaTeX .dvi files? Tags: xetex (Prev Q) (Next Q), unicode-math (Prev Q) (Next Q), unicode (Prev Q) (Next Q) Dvi files reference glyphs by their unicode number. However, a document often contain some unencoded glyphs, such as large math symbols. By inspecting dvi files containing such glyphs, I conclude that these glyphs are referenced by some non-unicode (Private Use Area) character codes. How can I know which character code LuaTeX will choose for a certain glyph, say, the display version of the integral sign? The same question goes for XeTeX, in case they are different. 625

Example: \documentclass{standalone} \usepackage{fontspec} \usepackage{unicode-math} \setmainfont{XITS} \setmathfont{XITS Math} \begin{document} $\int\displaystyle\int$ \end{document} When compiled with LuaLaTeX, using the --output-format=dvi option, the small integral is encoded as 0x222B (as expected) and the big integral is encoded as 0x0F001C (somewhat mystifying). Update: Some experimentation confirms that the encoding of the integral sign differs between fonts. The display version of the integral is 0x0F05C2 in Cambria Math, 0x10FF99 in Asana Math and 0x0F0314 in STIX Math, for instance. Tags: xetex (Prev Q) (Next Q), unicode-math (Prev Q) (Next Q), unicode (Prev Q) (Next Q) User: akvilas

Answer by martin LuaTeX uses a pretty simple algorithm to choose the DVI character codes: While reading the OTF file, it checks whether a character has a Unicode point assigned or not. If there’s an entry in the Unicode mapping table, LuaTeX uses the Unicode point. Otherwise, it populates the Unicode range starting at 0xF0000. The first unmapped character is assigned to 0xF0000, the second one to 0xF0001 etc. Thus, you can only predict the DVI character codes if you evaluate the Unicode table of the OTF fonts yourself. Especially, there’s no relation between the code and the semantics of an unmapped character, i.e. the big integral sign can get different DVI codes depending on the mapping tables and the characters present in the various font files. XeTeX, on the other hand, simply uses the glyph indexes of the characters in an OTF file if the characters are set with XDV command XGlyphArray 626

or XGlyphString. Each glyph in a font has a unique internal value with no relation to any encoding. The encoding itself is realized by the already mentioned encoding tables that, for example, map from Unicode or ISO-88591 to glyph indexes. So, XeTeX ignores the encodings present in the font file and uses the glyph indexes directly -- more precisely, those provided by the FreeType library (which may rearrange the values).

Tags: xetex (Prev Q) (Next Q), unicode-math (Prev Q) (Next Q), unicode (Prev Q) (Next Q)

Q: How to write a LaTeX command that could discriminate if it’s being called with pdfLaTeX in order to use PSTricks? Tags: xetex (Prev Q) (Next Q), pdftex (Prev Q) (Next Q), tikz-pgf (Prev Q) (Next Q) I’m writing a class for LaTeX, and I need to make it general. I want to include a simple image, a logo, within the class, which would be inserted into the document as a simple command \insertCompanyLogo. To avoid extra files, I added the PostScript definition of the logo in the .sty file. % Include PSTricks package \usepackage{pstricks} % Create new command to insert logo \newcommand{\insertCompanyLogo}{ \psset{xunit=.5pt,yunit=.5pt,runit=.5pt} \begin{pspicture}(180,180) \psline(0,0)(180,180) %The actual image is far more complex \end{pspicture} } This works good when I compile the document with latex . However, it fails when I try to use pdflatex. In order to use PSTricks with pdflatex, some modifications are required. For example, I can add in the .sty file \usepackage[pdf]{pstricks}. 627

Then compile the document using pdflatex -shell-escape . But this won’t be general, and it won’t work using the regular latex command. My question is: Is there any way to define a command that understand if the document is being compiled with pdflatex or latex? That way I can add a couple of \ifthenelse{}{}{} to the include line of PSTricks. Thus, the document that uses this .sty class and calls the \insertCompanyLogo could be compiled with both commands without any modification. I hope I was clear enough. And any solution, tip, recommendation or workaround, as always, is more than welcome. EDIT: Forgot to mention, I think that packages like xelatex and asymptote that could make this easier. But I would like this to work with a standard TexLive or MiKTeX installation, which is probably what 95% of the users of this class will have installed EDIT 2: This question was marked as duplicate. The other questions address the engine issue (pdflatex vs. latex). Helpful information. But they leave out the PSTricks part, and how to make its use flexible and multi-engine, and that was the reason of my question. EDIT 3: At the end, I opted for a completely different solution. What I wanted was to put a logo with a macro that works with both engines, latex and pdflatex. I used TiKz Skip code block \documentclass{article} % Include package TiKz \includepackage{tikz} % Create new command to insert logo \newcommand{\insertCompanyLogo}{ \begin{tikzpicture} \draw[thick,rounded corners=8pt] (0,0) -- (0,2) -- (1,3.25) -- (2,2) -- (2,0) -- (0,2) -- (2,2) -- (0,0) -- (2,0); \end{tikzpicture} } \begin{document} \insertCompanyLogo 628

\end{document} The actual logo, and the contents of the tikzpicture environment, I got them from Inkscape, with an extension to export to TiKz format. Tags: xetex (Prev Q) (Next Q), pdftex (Prev Q) (Next Q), tikz-pgf (Prev Q) (Next Q) User: phollox

Answer by herbert That is a bit tricky because \ifpdf cannot be used with xelatex which allows PSTricks code. The following example works with latex, pdflatex, xelatex, and lualatex: Skip code block \documentclass{article} \usepackage{ifpdf} \providecommand\insertCompanyLogo{} \newif\ifPSTricks \PSTrickstrue \usepackage{ifxetex} \ifpdf \PSTricksfalse \ifxetex\PSTrickstrue\fi \fi \ifPSTricks % Include PSTricks package \usepackage{pstricks} % Create new command to insert logo \renewcommand\insertCompanyLogo{% \psset{xunit=.5pt,yunit=.5pt,runit=.5pt} \begin{pspicture}(180,180) \psline(0,0)(180,180) %The actual image is far more complex \end{pspicture}} \fi \begin{document} 629

PSTricks code is \ifPSTricks\else not \fi possible: \insertCompanyLogo \end{document}

Tags: xetex (Prev Q) (Next Q), pdftex (Prev Q) (Next Q), tikz-pgf (Prev Q) (Next Q)

Q: How does XeLaTeX and LuaLaTeX extend the dvi format? Tags: xetex (Prev Q) (Next Q) The structure of the DVI file format is documented by Donald Knuth in TEX: the Program, Addison-Wesley, 1986. Although PDF is the primary output format, LuaTeX can also output DVI files. Are these DVI files different from what is found in the original specification? XeTeX can output XDV files, which are an extension of the DVI format. Is the XDV format documented anywhere? Tags: xetex (Prev Q) (Next Q) User: akvilas

Answer by david-carlisle I think luatex generated dvi is standard. For xdv, xetex.web defines the extended format, the relevant parts being Skip code block \yskip\noindent Commands 250--255 are undefined in normal \.{DVI} files, but the following commands are used in \.{XDV} files. \yskip\hang\vbox{\halign{#&#\hfil\cr 630

|define_native_font| 252 & |k[4]| |s[4]| |flags[2]| |l[1]| |n[l]| |i[4]|\cr & |if (flags and COLORED) then| |rgba[4]|\cr & |if (flags and EXTEND) then| |extend[4]|\cr & |if (flags and SLANT) then| |slant[4]|\cr & |if (flags and EMBOLDEN) then| |embolden[4]|\cr }} \yskip\hang|set_glyphs| 253 |w[4]| |k[2]| |xy[8k]| |g[2k]|. \yskip\noindent Commands 250 and 255 are undefined in normal \.{XDV} files. @ @d set_char_0=0 {typeset character 0 and move right} @d set1=128 {typeset a character and move right} @d set_rule=132 {typeset a rule and move right} @d put_rule=137 {typeset a rule} @d nop=138 {no operation} @d bop=139 {beginning of page} @d eop=140 {ending of page} @d push=141 {save the current positions} @d pop=142 {restore previous positions} @d right1=143 {move right} @d w0=147 {move right by |w|} @d w1=148 {move right and set |w|} @d x0=152 {move right by |x|} @d x1=153 {move right and set |x|} @d down1=157 {move down} @d y0=161 {move down by |y|} @d y1=162 {move down and set |y|} @d z0=166 {move down by |z|} @d z1=167 {move down and set |z|} @d fnt_num_0=171 {set current font to 0} @d fnt1=235 {set current font} @d xxx1=239 {extension to \.{DVI} primitives} @d xxx4=242 {potentially long extension to \.{DVI} primitives} @d fnt_def1=243 {define the meaning of a font number} @d pre=247 {preamble} @d post=248 {postamble beginning} @d post_post=249 {postamble ending} 631

@d define_native_font=252 {define native font} @d set_glyphs=253 {sequence of glyphs with individual x-y coordinates}

Tags: xetex (Prev Q) (Next Q)

Q: STIX 2.0 font declaration Tags: xetex (Prev Q) (Next Q), unicode-math (Prev Q) (Next Q) Today the STIX v2.0 was released. What is the proper font declaration to make use of various optical sizes etc with unicode-math? Tags: xetex (Prev Q) (Next Q), unicode-math (Prev Q) (Next Q) User: sapere-aude

Answer by khaled-hosny You don’t need to do any thing to get the optical sizes included in the math font. They are associated with the ssty feature which unicode-math will enable it for script and scriptscript font sizes.

Tags: xetex (Prev Q) (Next Q), unicode-math (Prev Q) (Next Q)

Q: Defining ‘commands’ or ‘macros’ with unicode names Tags: xetex (Prev Q) (Next Q), macros (Prev Q) (Next Q), tex-core (Prev Q) (Next Q) How can I implement the rough equivalent of \def\macro{expansion} so that the macro name can contain spaces and other unicode characters? I’d like to be able to do the following, for example: 632

\defineinsert{qty: �2 activity}{\SI{1.85}{\mega\becquerel}} [...] The measured activity was \insert{qty: �2 activity}. $R_\beta = \insert{qty: �2 activity}$ producing The measured activity was \SI{1.85}{\mega\becquerel}. $R_\beta = \SI{1.85}{\mega\becquerel}$ The motivation is to be able to pre-define many orderly ‘macros’ in to be used throughout a document, without the restriction that characters must only be [a-zA-Z], as imposed by using \def to define actual commands.

I have no idea how to implement this, since I don’t know how one would create key-value mappings with TeX… or if that would be the right approach. Perhaps there is another way of filling this need? Should I start using LuaTeX to accomplish this? (I am presently using XeLaTeX.) Perhaps there exists a package for this? Thanks! Tags: xetex (Prev Q) (Next Q), macros (Prev Q) (Next Q), tex-core (Prev Q) (Next Q) User: jollywatt

Answer by ulrike-fischer You can use \csname ...\endcsname for this. \@namedef:

E.g with the help of

Skip code block \documentclass{article} \begin{document} \makeatletter \@namedef{\detokenize{qty: �2 activity}}{bllb} The beta activity \@nameuse{\detokenize{qty: �2 activity}} 633

The beta activity \@nameuse{\detokenize{qty: �2

activity}}

\end{document}

For brevity, you may define something like \makeatletter \newcommand\newshortcut[2]{\@namedef{\detokenize{#1}}{#2}} \newcommand\shortcut[1]{\@nameuse{\detokenize{#1}}} \makeatother which may be used like so: \newshortcut{qty: �}{lola} [...] Hello \shortcut{qty: �}.

Tags: xetex (Prev Q) (Next Q), macros (Prev Q) (Next Q), tex-core (Prev Q) (Next Q)

Q: List of all post original TeX control commands Tags: xetex (Prev Q) (Next Q), pdftex (Prev Q) (Next Q), e-tex (Next Q) Is there a well documented list of all control commands added by all post Knuth’s Tex like PdfTeX, e-TeX, XeTex, LuaTeX? Tags: xetex (Prev Q) (Next Q), pdftex (Prev Q) (Next Q), e-tex (Next Q) User: codefx

Answer by charles-stewart

634

You can get the lists programmatically, using LuaTeX, provided you are interested in the new primitives provided by one of the dialects of TeX supported by that engine. By changing the values of the dialect variable in Skip code block

proc = tex.initialize () dialect = "etex" -- The dialect identifiers accepted are: tex (i.e., original Knuth, without Plain -core (core Luatex, that is, which at present is just "directlua", -not in the luatex dialect), -- and the extension dialects: -etex, pdftex, omega, aleph, luatex, umath -- so the primitives introduced by Luatex are the ones in core, luatex, and umath. -- These dialect identifiers are case sensitive: "etex" is accepted by -- tex.extraprimitives, "eTeX" is not. ps = tex.extraprimitives (dialect) for _, v in ipairs(ps) do print (v) end (which you should run using texlua listprims.lua if you have saved the program with that filename), this code will output the list of primitives for the given possible values. The Unix column utility makes the output nicer to read. The LuaTeX manual lists this output in its tex.extraprimitives section, giving a non-programmatic route to this information if for some reason you prefer that. Not all dialects of TeX are included in LuaTeX; most importantly, XeTeX is not. I think both NTS and ExTeX introduced new primitives -- for these other systems, look up their documentation; XeTeX’s list of primitives is in the XeTeX reference guide. Also note that the dialects change as the software develops. For instance, XeTeX gained primitives for compatibility with pdfTeX, I think relatively recently. As for a single guide providing well-documented lists for all the dialects -- well, since it’s a moving target, I doubt there is enough motivation to produce and 635

maintain such a thing.

Tags: xetex (Prev Q) (Next Q), pdftex (Prev Q) (Next Q), e-tex (Next Q)

Q: LuaLaTeX + libertine... the issue of math font Tags: xetex (Prev Q) (Next Q) Would it be possible to use Libertine otf font (using LuaLaTeX and, for example, package libertine for automatic settings) for everything but in math mode where I’d like to use newtxmath and its libertine option (which produces acceptable output with pdfLaTeX)? Neither : \usepackage[libertine]{newtxmath} \usepackage[no-math]{fontspec} \usepackage{libertine} nor \usepackage[libertine]{newtxmath} \usepackage[no-math]{fontspec} \setmainfont[Ligatures={TeX}]{Linux Libertine O} are successful. I get CM font for maths using the following: Skip code block %!TEX program = lualatex \documentclass[]{scrbook} \usepackage{amsmath} \usepackage{amssymb} \usepackage{mathtools} \usepackage[libertine]{newtxmath} 636

\usepackage[no-math]{fontspec} \usepackage{libertine} \begin{document}

\begin{equation} \mathit{TRUC} = \frac{1}{10} \times \sum _{d=0.2}^{12.8} \frac{\pi \times d \t \end{equation} \end{document} Tags: xetex (Prev Q) (Next Q) User: user2165907

Answer by egreg Since you give the no-math option, you have to help fontspec: Skip code block \documentclass[]{scrbook} \usepackage{amsmath} \usepackage{amssymb} \usepackage{mathtools} \usepackage[libertine]{newtxmath} \usepackage[no-math]{fontspec} \usepackage{libertine} \DeclareSymbolFont{operators}{\encodingdefault}{\familydefault}{\mddefault}{n} \DeclareMathAlphabet{\mathit}{\encodingdefault}{\familydefault}{\mddefault}{it} \DeclareMathAlphabet{\mathbf}{\encodingdefault}{\familydefault}{\bfdefault}{n} \begin{document}

\begin{equation} \mathit{TRUC} = \frac{1}{10} \times \sum _{d=0.2}^{12.8} \frac{\pi \times d \t 637

\end{equation} $\mathbf{ABC}$ \end{document} Otherwise you need to restore the standard math codes for the digits. Skip code block \documentclass[]{scrbook} \usepackage{amsmath} \usepackage{amssymb} \usepackage{mathtools} \usepackage[libertine]{newtxmath} \usepackage{fontspec} \usepackage{libertine} \AtBeginDocument{% \DeclareMathSymbol{0}{\mathalpha}{operators}{`0}% \DeclareMathSymbol{1}{\mathalpha}{operators}{`1}% \DeclareMathSymbol{2}{\mathalpha}{operators}{`2}% \DeclareMathSymbol{3}{\mathalpha}{operators}{`3}% \DeclareMathSymbol{4}{\mathalpha}{operators}{`4}% \DeclareMathSymbol{5}{\mathalpha}{operators}{`5}% \DeclareMathSymbol{6}{\mathalpha}{operators}{`6}% \DeclareMathSymbol{7}{\mathalpha}{operators}{`7}% \DeclareMathSymbol{8}{\mathalpha}{operators}{`8}% \DeclareMathSymbol{9}{\mathalpha}{operators}{`9}% } \begin{document} \showthe\mathcode`1

\begin{equation} \mathit{TRUC} = \frac{1}{10} \times \sum _{d=0.2}^{12.8} \frac{\pi \times d \t 638

\end{equation} $\mathbf{ABC}$ \end{document}

Tags: xetex (Prev Q) (Next Q)

Q: Define MakeUppercase list with XeLaTeX/LuaLaTeX Tags: xetex (Prev Q) (Next Q), babel (Prev Q) (Next Q) I do custom list for to make uppercase/lowercase for 8-bit TeX for Georgian and it works fine, but how to define it for XeLaTeX/LuaLaTeX? here is a similar question Applying MakeUppercase to non-English characters in math mode this is example. it works for Russian and English Skip code block

\documentclass{article} \usepackage{fontspec} \usepackage[russian,georgian]{babel} \makeatletter \def\[email protected]@[email protected]{% \expandafter\def\expandafter\@uclclist\expandafter {\@uclclist \�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\� \let\[email protected]@[email protected]\relax % } 639

\makeatother \setmainfont{Dejavu Serif} \begin{document} \MakeUppercase{abc ��� ���} \end{document} Tags: xetex (Prev Q) (Next Q), babel (Prev Q) (Next Q) User: levan-shoshiashvili

Answer by joseph-wright You need to tell TeX to map the characters themselves to each other: there are no control sequences involved here. (This is different in 8-bit engines where the code points you want are not single bytes.) You also need to make sure this code gets activated when Georgian is selected. For example Skip code block

\documentclass{article} \usepackage{fontspec} \usepackage[russian,georgian]{babel} \makeatletter \[email protected]@macro\extrasgeorgian{% \def\[email protected]@georgian#1#2{% \ifx\relax#2\relax \else \uccode`#1=`#2 % \expandafter\[email protected]@georgian \fi }% \[email protected]@georgian \�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\�\� \relax\relax } \makeatother \setmainfont{Dejavu Serif} 640

\begin{document} \MakeUppercase{abc ��� ���} \end{document} will work. (I’ve kept your list of escaped characters simply to avoid having to edit it all!)

Not directly relevant, but at least worth noting from the point of view of the question ’Why is no case changing happening as standard?’ is the nature of the input you have. For example, � is code point U+10D0, listed as 10D0;GEORGIAN LETTER AN;Lo;0;L;;;;;N;GEORGIAN SMALL LETTER AN;;;; Notice that this is a caseless letter with no upper/lower mapping. On the other hand, � (U+10A0) is a cased letter 10A0;GEORGIAN CAPITAL LETTER AN;Lu;0;L;;;;;N;;;;2D00; but maps to U+2D00. If we look there we find 2D00;GEORGIAN SMALL LETTER AN;Ll;0;L;;;;;N;;;10A0;;10A0 which does mean there is an upper/lower case pair. However, U+2D00 seems to have a different appearance to U+10D0! (I’m not saying Unicode is ’right’ here, just that the data in Unicode TeX engines for case changing is as-standard that taken from the Unicode Consortium, so we can see why there is an issue.)

Tags: xetex (Prev Q) (Next Q), babel (Prev Q) (Next Q)

Q: Latex command for unfilled \bigstar Tags: xetex (Prev Q), unicode-math (Prev Q) (Next Q), symbols (Prev Q) (Next Q) 641

\bigstar produces a black star. What is the LaTeX command for white or unfilled \bigstar? The unicode-math package has a command \bigwhitestar, but I am not able to use it in the usual way. When I compile with \usepackage{unicode-math}, I get the following error: ! Package unicode-math Error: Cannot be run with pdfLaTex! (unicode-math) Use XeLaTeX or LuaLaTex instead. PS: I need the big white star symbol to reference a point in a Matlab generated figure. I cannot compile with xetex or xelatex because they do not use the conference style file properly, i.e. the output looks quite different from that of latex. Tags: xetex (Prev Q), unicode-math (Prev Q) (Next Q), symbols (Prev Q) (Next Q) User: prometheus

Answer by steven-b.-segletes If your require some tuning of the star border, this solution is an alternative. The downside is that it loads a lot of packages; however, none of those packages overwrite the existing fonts, in the way that MnSymbol does. In this case \openbigstar takes an optional argument specifying the relative size of the inner white star relative to the outer black star, thus defining a border thickness in the process. And using scalerel package’s features, it automatically works across different math styles. Skip code block \documentclass{article} \usepackage{amssymb} \usepackage{stackengine} \usepackage{scalerel} \usepackage{xcolor} \usepackage{graphicx} \newcommand\openbigstar[1][0.7]{% \scalerel*{% 642

\stackinset{c}{-.125pt}{c}{}{\scalebox{#1}{\color{white}{$\bigstar$}}}{% $\bigstar$}% }{\bigstar} } \begin{document} $\bigstar\openbigstar\openbigstar[.4]\openbigstar[.9]$ $\scriptstyle\bigstar\openbigstar\openbigstar[.4]\openbigstar[.9]$ $\scriptscriptstyle\bigstar\openbigstar\openbigstar[.4]\openbigstar[.9]$ \end{document}

Tags: xetex (Prev Q), unicode-math (Prev Q) (Next Q), symbols (Prev Q) (Next Q)

PdfTeX Skip to questions, Wiki by user stefan-kottwitz pdfTeX is an extension of TeX which is capable of directly generating PDF output. Use this tag if your question is about pdf(La)TeX specific problems, i.e. if the subject has something to do with pdfTeX but not with standard (La)TeX which produces DVI output. For standard LaTeX choose an appropriate specific Tag. Since the majority of questions on this site deal with LaTeX, there’s no need for a LaTeX tag. However, if your question is really about LaTeX in general, you may choose the latex-project tag. The other most common TeX/LaTeX engines are xelatex and lualatex. 643

Questions Q: Frequently loaded packages: Differences between pdfLaTeX and LuaLaTeX Tags: pdftex (Prev Q) (Next Q), packages (Prev Q) (Next Q) I’m in the process of switching my LaTeX document from pdflatex to lualatex. Similar to Frequently loaded packages: Differences between pdfLaTeX and XeLaTeX I would like to know, what are typical packages loaded with LuaLaTeX and which typical pdfLaTeX packages should be removed or replaced? The following are the main difference I found so far: • Don’t use inputenc, but instead save your plain files in utf-8 and add the following as the first line: % !Mode:: "TeX:UTF-8". • Don’t use font-packages but instead load fontspec with \setmainfont{FONT_NAME}, \setsansfont{FONT_NAME}, \setmonofont{FONT_NAME}. • In order to make microtype work with fontspec, use the beta version of microtype (At least with TeX Live 2011). See more details. • hyperref should be loaded with the option unicode. What other packages do you use? What about babel and textcomp? And are there some ”killer-packages” that are only working with lualatex besides fontspec? Tags: pdftex (Prev Q) (Next Q), packages (Prev Q) (Next Q) User: apepper

Answer by �aphink Besides supporting a Lua interpreter, LuaTeX brings to pdfTeX quite the same changes as XeLaTeX (native Unicode support, support for system fonts).

644

For this reason, the question you linked to applies to LuaTeX as well, modulo the answers to this question about migrating from XeTeX to LuaTeX, which shows that apart from microtype support and font names, LuaTeX- and XeTeX-specific codes are mostly compatible. babel works fine with LuaTeX as far as I can tell. At least with frenchb, I haven’t had any issues. Besides fontspec (which also works with XeTeX), there’s more and more packages that use Lua to provide features. As an example, I have recently released the impnattypo package which has some LuaTeX specific features (thanks to Patrick), and I have more coming (such as the unreleased overcolored package).

Answer by martin-schröder Most usage questions for LuaLaTeX are answered in lualatex-doc.pdf.

Answer by matth Similar to the MWE in the linked XeLaTeX question, here is a MWE for LuaLaTeX. It uses the ifluatex package to allow switching between pdfLaTeX and LuaLaTeX (remember to delete all .aux files). I used the fonts from the Microsoft ClearType fonts, because they look good on screen and printed. Skip code block % !TEX program = LuaLaTeX \documentclass[ a4paper, ngerman, final ]{scrbook} \usepackage{amsmath} \usepackage{ifluatex} \ifluatex % Lua(La)TeX 645

\usepackage[ngerman]{babel} %\usepackage{polyglossia} %\setmainlanguage[spelling=new,babelshorthands=true]{german} \usepackage{fontspec} \defaultfontfeatures{Ligatures=TeX} \usepackage[]{unicode-math} \unimathsetup{math-style=TeX} \setmainfont[Ligatures=TeX]{Constantia} \setsansfont{Calibri} \setmonofont{Consolas} \setmathrm{Cambria Math} \setmathfont{Cambria Math} \else %default: pdf(La)TeX \usepackage[ngerman]{babel} \usepackage{lmodern} % load vector font \usepackage[T1]{fontenc} % font encoding \usepackage[utf8]{inputenc} % input encoding \fi \usepackage[babel=true]{microtype}

%% ================== \begin{document} \chapter{Goldener Schnitt} Beim Goldenen Schnitt (lateinisch: sectio aurea) oder auch bei der Goldenen Teilun --- seltener beim Göttlichen Schnitt oder bei der Göttlichen Teilung (lateinisch: entsteht ein bestimmtes Verhältnis zwischen zwei Zahlen oder zwei Größen. Dieses Verhältnis ist die Goldene Zahl $\Phi$ (Phi) (oder das Goldene Verhältnis o \begin{equation} \Phi=\frac{1 + \sqrt{5}}{2} \approx 1{,}618 \end{equation} Zum Beispiel stehen zwei Teile einer Strecke im Verhältnis $\Phi$, wenn sich der größere zum kleineren Teil verhält wie die ganze Strecke zum größere \begin{equation} \frac{a}{b} = \frac{a+b}{a} \end{equation} 646

Streckenverhältnisse wie beim Goldenen Schnitt werden seit der griechischen Antike Sie werden als ideale Proportionen in Kunst und Architektur angewendet, kommen aber auch in der Natur vor. Das Goldene Verhältnis ist häufig bei der Bildkomposition in der Malerei zu finden \begin{table}[!htb] \begin{tabular}{@{}l*{10}{p{7mm}@{}}} Some T1 characters: & \# & \$ & \% & Ă & Ň & § & @ & Æ & ß & £ \\[1.5m Some non-T1 characters: & ‡ & ÿ & ‰ & … & ¶ & ½ & ĩ & µ & | | & | | \\ \end{tabular} \end{table} Es zeichnet sich durch eine Reihe besonderer mathematischer Eigenschaften aus. Umgangssprachlich wird Goldener Schnitt auch für die Goldene Zahl beziehungsweise \end{document}

Tags: pdftex (Prev Q) (Next Q), packages (Prev Q) (Next Q)

Q: Abandon LaTeX2e for LaTeX3 or LuaTeX Tags: pdftex (Prev Q) (Next Q), latex3 (Prev Q) (Next Q) I think my question is: Should I abandon pdflatex, possibly for xetex or context, and a TeX/LaTeX based macro writing approach, possibly for a LuaTeX or LaTeX3 based approach? Possibly relevant to the answer is that I am an academic who exclusively uses the English language and a lot of math. I have been using TeX on and off for a number of years. I am happy using TeX to create all my documents (papers, presentations, letters, etc.), new macros and even simple packages (although the whole literate programming and documentation thing is beyond me). My macros tend to use both TeX and LaTeX macros. I used to create DVI files by compiling with latex but now I use pdflatex to create pdf files. The change from EPS to PDF figures and the loss of pstricks took some time for me to get used to, but I am now happy with the change. Recently, I gave up BibTeX for Biber and BibLaTeX and am very happy. I am willing to put in the time to learn LuaTeX/LaTeX3/ConTeX if there are advantages. 647

Tags: pdftex (Prev Q) (Next Q), latex3 (Prev Q) (Next Q) User: strongbad

Answer by loop-space I’m going to expand on my comment and turn it into an answer. I take issue with the word abandon in your question. Using xelatex and latex3 does not mean that you have to abandon pdflatex and latex2e. It is entirely possible to use them alongside each other. The differences at the document level are such that it is relatively straightforward to remember ”This is a pdflatex document” and ”This is a xelatex document”. I do my lectures with xelatex because I want to be able to use unicode-math. I tend to write my articles with pdflatex - see below - though for the fun of it I tried an article with xelatex and using unicode symbols and really quite liked the readability of the source code. So when there’s functionality that I would like to make use of, then I’m happy to use xelatex or lualatex or latex3. If I don’t need them, then at the moment I’ll probably not use them so that I keep my options open. As I see more ”here’s what you can do” on this site, then I find myself more and more using them to make use of what I learn here. Some is a bit silly (such as my use of unicode-math) but others are more serious. The one thing that I really don’t take any notice of is the compatibility with journals or the arxiv. This is for two reasons: 1. If a journal actually accepts my article then (within reason) I’m happy to modify it to suit their bizarre style requirements (and before you ask, all journals have bizarre requirements). 2. Before a journal accepts my article then I’ll not know what bizarre requirements I’m going to have to meet so I’d rather make my life easier here and now than try to guess what I might have to do when it is accepted. The point of that second one is that I spend a lot of time writing an article. I’m often doing the maths as I actually write it because it is often only when I see it written down that I see whether or not my argument worked - when it’s in my head then I gloss over all the technicalities. So it’s not ”prove result 648

then write article” it is ”prove result while writing article”. This means that the writing stage is longer and more involved than if I worked the other way and so it is all the more important that the writing be easy and not get in the way. So being able to make use of great tools and stuff is more important than not annoying some future copy-editor. So if you see an example of something on this site and you think ”That would be just perfect for what I’m trying to do”, don’t let the fact that it uses xelatex or lualatex or latex3 put you off. Just think of it as another LaTeX package that you use for some of your documents, but not all of them. It’s no big deal.

Answer by seamus If you want to publish in academic journals, you need to be sensitive to what new TeX related goodies their setup can handle. For instance, I’ve had to regress from BibLaTeX to BibTeX because a journal couldn’t handle it. Likewise, I’d expect that LuaTeX or ConTeXt might not fit well into the workflow of a journal. I’m sure there are people here who know more about this sort of thing, and it probably depends on your field. (There are journals in my area that accept submissions in Word only! Sigh) There’s also the worry that collaborators will have older TeX distributions, and so you may encounter friction when trying to work with others. My university’s computers seem to still have an old distribution which doesn’t include many packages I would otherwise use. (This doesn’t affect me since I use my laptop, but when I’m working with others, I need to go down to their level). In short, feel free to move towards the new stuff for your own documents, but be aware that journals and collaborators might be less keen on staying cutting edge.

I think it is perhaps worth making a comment or two in response to the discussion in comments on this and Yiannis’ answers. There are good reasons for journals and big university-wide computing set ups to avoid the cutting edge technologies that we are fond of on this site. As Barbara Beeton mentioned, stability is key. LaTeX2e is stable. The bugs have been ironed out, 649

and packages like fixltx2e fix a few remaining oddities. Moving to a system involving components under active development (e.g. LuaTeX, BibLaTeX…) would mean frequent breakages and things like that; things that publishers can’t afford to deal with.

Answer by yiannis-lazarides Although these issues were discussed earlier here are some pointers, from someone that has been using TeX/LaTeX since the middle 80s. 1. The knowledge you build with TeX/LaTeX and friends is additive. What you have used as plain TeX commands, your \defs and similar can be used today with all of the above variants. Similarly for all the LaTeX commands and yes your pstricks knowledge can still be used with pdfLaTeX. 2. The new variants such as XeLaTeX offer advantages in some areas especially font management. If you are using special fonts and UTF8 typing it will pay you to migrate. In many cases it is as simple as adding a few lines on top of your normal LaTeX/pdfLaTeX file. 3. LuaLaTeX is not as yet production stable and personally cannot see any reason to use it on a daily basis unless you need fancy calculations, iteration and other complicated macros. 4. LaTeX3. Portions of it are stable and can be used to-day in peaceful coexistence with LaTeX2e commands. You cannot as of to-day say I will only use LaTeX3 as it is still incomplete (it has no kernel as yet that compares to LaTeX2e or offer any of the standard classes in the new syntax). 5. ConTeXt is a great system but for whatever reason is not as popular as the other variants. Personally I don’t use it as I still get lots of installation problems on Window machines. My general advice (especially for maths) is to stay with pdfLaTeX or XeLaTeX and you good for the next 10 years (I cannot see amsmath migrating to LaTeX3 any time soon). It is harmless though to keep your ears on the ground and try some of the new things. For example xparse from the LaTeX3 suite has a lot to offer as well as all the sequence macros, as they can save you a lot of programming time. I personally use pdfLaTeX for my daily engineering documents and for its 650

intellectual stimulation since the late Martin Gardner’s column in Scientific America stopped being published!

Tags: pdftex (Prev Q) (Next Q), latex3 (Prev Q) (Next Q)

Q: Highlight every occurrence of a list of words? Tags: pdftex (Prev Q) (Next Q) In order to revise a draft, and identify related sections, I would like to identify similar words (by color of text, highlight, underline, or otherwise) according to topic. For example, I would like all uses of the terms ”foo” or ”bar” highlighted red and all uses of ”biz” and ”baz” highlighted green. There might be four or five groups of words or word roots that I want to specify. This is only for revision, so it can be rather crude. For example, replace this:

with this:

(In the example, it is hard to see the green text; perhaps bold+color or underline would be more useful) Update A related question provides an answer using XeLaTex. My document does not compile with XeLaTex, I would prefer a solution compatible

651

with pdflatex if available (since that is what I use), though my document also compiles with luatex. Other related questions: • Macro: Replace all occurrences of a word (answer is not generic - requires seven lines per string to be replaced) • automatically apply special formatting to selected words in text (only provides xelatex solution) • Automatically highlight words from a predefined list (uses chickenize, replaces string but does not add color) Tags: pdftex (Prev Q) (Next Q) User: david-lebauer

Answer by manuel Here’s another with l3regex. Skip code block \documentclass{scrartcl} \usepackage{xcolor,xparse,l3regex} \ExplSyntaxOn \NewDocumentCommand \texthighlight { +m } { \david_texthighlight:n { #1 } } \cs_new_protected:Npn \david_texthighlight:n #1 { \group_begin: \tl_set:Nn \l_tmpa_tl { #1 } \seq_map_inline:Nn \g_david_highlight_colors_seq { \clist_map_inline:cn { g_david_highlight_##1_clist } { \regex_replace_all:nnN { (\W)####1(\W) } { \1\c{textcolor}\cB\{##1\cE\}\cB\{####1\cE\}\2 } \l_tmpa_tl } } \tl_use:N \l_tmpa_tl \group_end: 652

} \seq_new:N \g_david_highlight_colors_seq \NewDocumentCommand \addhighlighting { O{red} m } { \seq_if_in:NnF \g_david_highlight_colors_seq { #1 } { \seq_gput_right:Nn \g_david_highlight_colors_seq { #1 } } \clist_if_exist:cF { g_david_highlight_#1_clist } { \clist_new:c { g_david_highlight_#1_clist } } \clist_gput_right:cn { g_david_highlight_#1_clist } { #2 } } \ExplSyntaxOff \addhighlighting{amet,Mauris,ut,et,leo} \addhighlighting[blue]{Phasellus,vestibulum} \begin{document} \texthighlight{Lorem ipsum dolor foo sit amet, bar consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna. Donec vehicula augue eu neque. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Mauris ut leo. Cras viverra metus rhoncus sem. Nulla et lectus foo vestibulum urna fringilla ultrices. Phasellus eu tellus sit amet tortor gravida placerat. Integer sapien est, iaculis in, pretium quis, viverra ac, nunc. Praesent eget sem vel leo ultrices bibendum. Aenean faucibus. Morbi dolor nulla, malesuada eu, pulvinar at, mollis ac, nulla. Curabitur auctor semper nulla. Donec varius orci eget risus. Duis nibh mi, congue eu, accumsan eleifend, bar sagittis quis, diam. Duis eget orci sit amet orci dignissim rutrum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, foo vulputate a, magna. Donec vehicula augue eu neque. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Mauris ut leo. Cras viverra metus rhoncus sem. Nulla et lectus vestibulum urna fringilla ultrices. 653

Phasellus eu tellus sit amet tortor gravida placerat. Integer sapien est, iaculis in, pretium quis, viverra ac, bar nunc. Praesent eget sem vel leo ultrices bibendum. Aenean faucibus. Morbi dolor nulla, malesuada eu, pulvinar at, mollis ac, nulla. Curabitur auctor semper nulla. Donec varius orci eget risus. Duis nibh mi, congue eu, accumsan eleifend, sagittis quis, diam. Duis eget orci sit amet orci dignissim rutrum.} \end{document}

Answer by aditya ConTeXt provides a proof of concept module for such translations: mtranslate. You could use it to translate text, but the translation takes place before macro expansion. So, the method will fail if the translation string is part of a macro name. The translation can be enabled and disabled using \enableinputtranstion and \disableinputtranslation. Here is an example, which a little wrapper 654

macro for ease of input. Skip code block \usemodule[translate] \define\defineautocoloring {\dodoubleargument\dodefineautocoloring} \def\dodefineautocoloring[#1][#2]% {\def\dododefineautocoloring##1% {\translateinput[##1][{\color[#1]{##1}}]}% \processcommalist[#2]\dododefineautocoloring} \defineautocoloring[red][foo, bar] \defineautocoloring[blue][color] \setuppapersize[A5] \starttext \enableinputtranslation This is a foo example of coloring random bar text. What is foobar? The translation is done before macro expansion, so weird stuff can happen: \type{foobar} \disableinputtranslation This is a foo example of coloring random bar text. What is foobar? The translation is done before macro expansion, so weird stuff can happen: \type{foobar} \stoptext which gives

655

Answer by steven-b.-segletes Strongly based on my answer at How to insert a symbol to the beginning of a line for which a word appears?. However, I had to extend the logic to handle multiple color assignments. Syntax is multiple invocations of \WordsToNote{space separated list}{color} and then \NoteWords{multiple paragraph input} Macros in the input are limited to style (e.g., \textit) and size (e.g., \small) changes. Otherwise, only plain text is accepted. As detailed in the referenced answer, I adapt my titlecaps package, which normally capitalizes the first letter of each word in its argument, with a userspecified list of exceptions. Here, instead of capitalizing the words, I leave them intact. However, I trap the user-specified word exceptions and use them to set a different color. In this extension of that method, I had to revise two titlecaps macros: \titlecap and \[email protected] The method cannot handle word subsets, but it can ignore punctuation. EDITED to fix bug when flagged word appears with punctuation, and issue with first word of paragraphs. Skip code block \documentclass{article} 656

\usepackage{titlecaps} \makeatletter \renewcommand\titlecap[2][P]{% \[email protected]% \if T\converttilde\def~{ }\fi% \[email protected]% \[email protected]{#2}% \[email protected]{#1}% \if P#1% \[email protected]% \[email protected]{#2}% \[email protected]\[email protected]{\argi}% \else% \fi% \setcounter{[email protected]}{0}% \[email protected]% \def\@thestring{}% \[email protected]{#2}% \if P#1\[email protected]\argi{\[email protected]}\fi% \whiledo{\value{[email protected]} < \narg}{% \addtocounter{[email protected]}{1}% \if F\csname [email protected]\roman{[email protected]}\endcsname% \[email protected]{\csname arg\roman{[email protected]}\endcsname}% \expandafter\[email protected]\csname% arg\roman{[email protected]}\endcsname{\@thestring}% \else \[email protected]{\csname arg\roman{[email protected]}\endcsname}% \expandafter\[email protected]\csname% arg\roman{[email protected]}\endcsname{\color{% \csname color\romannumeral\value{[email protected]}\endcsname}% \@thestring\color{black}{}}% \fi% }% \def\@thestring{}% \setcounter{[email protected]}{0}% \whiledo{\value{[email protected]} < \narg}{% \addtocounter{[email protected]}{1}% \ifthenelse{\value{[email protected]} = 1}% 657

{}{\[email protected]}% \[email protected]\@thestring{\@thestring% \csname arg\roman{[email protected]}\endcsname}% }% \let~\SaveHardspace% \@thestring% \[email protected]% \[email protected]}

% SEARCH TERTIUS CONVERTED ARGUMENT FOR LOWERCASE WORDS, SET FLAG % FOR EACH WORD (T = FOUND IN LIST, F= NOT FOUND IN LIST) \renewcommand\[email protected][1]{% \[email protected]% \setcounter{[email protected]}{0}% \whiledo{\value{[email protected]} < \narg}{% \addtocounter{[email protected]}{1}% \[email protected]\[email protected]{% \csname arg\romannumeral\value{[email protected]}\endcsname}% \def\[email protected]{F}% \setcounter{[email protected]}{0}% \expandafter\def\csname% [email protected]\romannumeral\value{[email protected]}\endcsname{F}% \whiledo{\value{[email protected]} < \value{[email protected]}}{% \addtocounter{[email protected]}{1}% \[email protected]\[email protected]{% \csname lcword\romannumeral\value{[email protected]}\endcsname}% %% THE FOLLOWING THREE LINES ARE FROM DAVID CARLISLE \[email protected]\tmp{\noexpand\scantokens{\def\noexpand\tmp% {\noexpand\ifthenelse{\noexpand\equal{\[email protected]}{\[email protected]}}}}}% \tmp\ifhmode\unskip\fi\tmp %% {\expandafter\def\csname% [email protected]\romannumeral\value{[email protected]}\endcsname{T}% \expandafter\[email protected]\csname color\romannumeral\value{[email protected]}\endc \csname CoLoR\csname lcword\romannumeral\value{[email protected]}\endcsname\endc \setcounter{[email protected]}{\value{[email protected]}}% }% {}% 658

}% }% \if P#1\def\[email protected]{F}\fi% \[email protected]% } \makeatother \usepackage{xcolor} \newcommand\WordsToNote[2]{\Addlcwords{#1}\edef\assignedcolor{#2}% \assigncolor#1 \relax\relax} \def\assigncolor#1 #2\relax{% \expandafter\edef\csname CoLoR#1\endcsname{\assignedcolor}% \ifx\relax#2\else\assigncolor#2\relax\fi% } \newcommand\NoteWords[1]{\NoteWordsHelp#1\par\relax} \long\def\NoteWordsHelp#1\par#2\relax{% \titlecap[p]{#1}% \ifx\relax#2\else\par\NoteWordsHelp#2\relax\fi% } \begin{document} \WordsToNote{foo bar at}{red} \WordsToNote{Nulla dolor nulla}{cyan} \WordsToNote{amet est et}{orange} \WordsToNote{Lorem Ut ut felis}{green} \NoteWords{ \textbf{Lorem ipsum dolor foo sit amet, bar consectetuer adipiscing elit}. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna. Donec vehicula augue eu neque. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Mauris ut leo. Cras viverra metus rhoncus sem. \textit{Nulla et lectus foo} vestibulum urna fringilla ultrices. Phasellus eu tellus sit amet tortor gravida placerat. Integer sapien est, iaculis in, pretium quis, viverra ac, nunc. Praesent eget sem vel leo ultrices bibendum. \scshape Aenean faucibus. Morbi dolor nulla, malesuada eu, pulvinar at, mollis ac, nulla. Curabitur auctor semper nulla. Donec varius orci eget risus. \upshape Duis nibh mi, congue eu, accumsan eleifend, bar sagittis quis, diam. Duis eget orci sit amet orci dignissim rutrum. 659

\textsf{Lorem ipsum dolor sit amet}, consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis. Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, foo vulputate a, magna. Donec vehicula augue eu neque. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Mauris ut leo. Cras viverra metus rhoncus sem. Nulla et lectus vestibulum urna fringilla ultrices. Phasellus eu tellus sit amet tortor gravida placerat. Integer sapien est, iaculis in, pretium quis, viverra ac, bar nunc. Praesent eget sem vel leo ultrices bibendum. Aenean faucibus. Morbi dolor nulla, malesuada eu, pulvinar at, mollis ac, nulla. Curabitur auctor semper nulla. Donec varius orci eget risus. Duis nibh mi, congue eu, accumsan eleifend, sagittis quis, diam. \Large Duis eget orci sit amet orci dignissim rutrum.\normalsize } \end{document}

660

Tags: pdftex (Prev Q) (Next Q)

Q: pgfplot: plotting a large dataset Tags: pdftex (Prev Q) (Next Q), tikz-pgf (Prev Q) (Next Q), pgfplots (Prev Q) (Next Q) I try to plot a dataset which is large using pgfplots. Since I’m aware of problems with large files, I used the external mode. I additionally increased main_memory from 3000000 to 6000000. It crashes nevertheless, saying that pdflatex exceeded main memory. But if I look at the memory consumption 661

of my system during compilation, I can’t see any increase in memory usage. I couldn’t find any explanation what main_memory takes, is it byte or Kbyte? If I increase it at a larger value, fmtutil-sys --all will fail and pdflatex won’t work anymore. Can I get around this somehow? Skip code block \documentclass{article} \usepackage{pgfplots} \usepackage{pgfplotstable} \usepgfplotslibrary{external} \tikzexternalize \begin{document} \begin{tikzpicture} \begin{axis} \addplot table[x expr=\coordindex, y index=0] {largefile}; \end{axis} \end{tikzpicture} \end{document} I also tried to compile with lualatex (just replaced pdflatex with lualatex) but this also seems to call pdflatex? At least I got this error message (same for lualatex and pdflatex): ! Package tikz Error: Sorry, the system call 'pdflatex -halt-on-error -interact ion=batchmode -jobname "report-figure0" "\def\tikzexternalrealjob{report}\input {report}"' did NOT result in a usable output file 'report-figure0' (expected on e of .pdf:.jpg:.jpeg:.png:). Please verify that you have enabled system calls. For pdflatex, this is 'pdflatex -shell-escape'. Sometimes it is also named 'wri te 18' or something like that. Or maybe the command simply failed? Error messag es can be found in 'report-figure0.log'. If you continue now, I'll try to types et the picture. Excerpt from report-figure0.log: ! TeX capacity exceeded, sorry [main memory size=6000000]. 662

\[email protected] ...toka \the \[email protected]@tokb \the... l.13 ... expr=\coordindex, y index=0] {largefile}; ^^M largefile is 5.7 Mb is size and has 593932 datapoints. I barely dare to say that I also have a file of 163 Mb in size with 18928305 datapoints. I thought this is no problem because gnuplot can handle those files fast without problems. head of largefile: Skip code block 9409252 17298051 21351017 24466010 26952485 29389696 31442872 33345635 35029538 36710432 Please find the dataset here. I’m using texlive2012: $ pdflatex This is pdfTeX, Version 3.1415926-2.4-1.40.13 (TeX Live 2012) restricted \write18 enabled $ lualatex This is LuaTeX, Version beta-0.70.2-2012052410 (TeX Live 2012) restricted \write18 enabled. Tags: pdftex (Prev Q) (Next Q), tikz-pgf (Prev Q) (Next Q), pgfplots (Prev Q) (Next Q) User: oliver

663

Answer by herbert you can use this simple sed one liner to reduce the data, eg for every 200th value sed -n '1~200p' < large.data > large200.data then it can easily be plotted. An alternative for the first 200 and then every 1000th: sed '1,200!d' < large.data > large1000.data sed -n '201~1000p' < large.data >> large1000.data

Tags: pdftex (Prev Q) (Next Q), tikz-pgf (Prev Q) (Next Q), pgfplots (Prev Q) (Next Q)

Q: Compile all tex files within a folder at once Tags: pdftex (Prev Q) (Next Q), compiling (Next Q) Is there a way to compile all tex files within a specific folder, from LINUX terminal, at once? I would like to do this using pdflatex or lualatex in a way to create a pdf file for each distinc original tex file. This question is not about creating individual tex files to form a single pdf file using \input or \include, at all. Tags: pdftex (Prev Q) (Next Q), compiling (Next Q) User: fcpenha

Answer by david-carlisle You could use a loop in the shell eg cd myfolder; for i in *.tex; do pdflatex $i;done 664

Answer by andrew-swann By default latexmk compiles all tex files in the current directory, including doing the necessary calls to biber, bibtex, etc. To run pdflatex on the files use latexmk -pdf or for lualatex latexmk -lualatex You can set default behaviour via a configuration file.

Answer by cmhughes I imagine there are quite a few ways to do this- David Carlisle mentioned one in his comment, here’s another: find -name "*.tex"|while read file; do pdflatex "$file";done

Tags: pdftex (Prev Q) (Next Q), compiling (Next Q)

Q: How to get accented unicode characters that can be copypasted? Tags: pdftex (Prev Q) (Next Q), unicode (Prev Q) (Next Q) The aim is to generate the .pdf with accented characters (the .tex file has mixed macro and unicode input), in a way that the .pdf text can be copypasted. An example: Skip code block

665

\documentclass{article} \usepackage[utf8x]{inputenc} \usepackage[T1]{fontenc} \usepackage{tgpagella} \begin{document} Unicode input: ā ī ū ṃ ṅ ñ Macro input: \=a \={\i} \=u \d{m} \.n \~n \end{document} Compiling with pdflatex, the above will visually produce the desired characters, but when you select and copy-paste them from the .pdf, you get Unicode input: a ̄ u m n ñ ̄ı ̄ . ̇ Macro input: a ̄ u m n ñ Edit: Ulrike’s answer explains what pdflatex is doing here. Tags: pdftex (Prev Q) (Next Q), unicode (Prev Q) (Next Q) User: nyiti

Answer by ulrike-fischer pdflatex doesn’t use ”unicode compounds”. You are using T1-encoding and for the accented chars not available in this encoding pdflatex use various methods to build them. E.g the dot below the m is actually a small tabular with the m in the first row and a dot in the second: \DeclareTextCommand{\d}{T1}[1] {\[email protected] \[email protected]{\relax#1\crcr\hidewidth\[email protected]@ft{-1ex}.\hidewidth}\egroup} In theory you can get correct glyphs with pdflatex (if your font contains them). In practice it would mean a lot work. Better use xelatex or lualatex. 666

Answer by nyiti This is the path to victory: 1. Install TeX Live 2010 which has a luatex and fontspec version that work together. Follow the instructions on tug.org. 2. On Linux, don’t forget to update the $PATH! If you already have TeX Live installed with your package manager, give the new path priority over the old one. For example, at the end of ~/.bashrc, put PATH=/usr/local/texlive/2010/bin/i386-linux:$PATH; export PATH 3. Log out and back in (or just open a new terminal) so that your $PATH updates. Save this test to test.tex somewhere, and compile with lualatex --interaction=nonstopmode test.tex Skip code block \documentclass{article} \usepackage{fontspec} \setmainfont[Ligatures=TeX]{TeX Gyre Pagella} \begin{document} Unicode input: ā ī ū ṃ ṅ ñ Macro input: \=a \={\i} \=u \d{m} \.n \~n \end{document} Open the resulting test.pdf, and when you copy-paste from it, you get Unicode input: ā ī ū ṃ ṅ ñ Macro input: ā ī ū ṃ ṅ ñ Nice!

667

Answer by martin-schröder Try adding \usepackage{cmap}. Or switch to xelatex/lualatex.

Tags: pdftex (Prev Q) (Next Q), unicode (Prev Q) (Next Q)

Q: \ifpdf returns true when using LuaLaTeX Tags: pdftex (Prev Q) (Next Q), conditionals (Prev Q) (Next Q) The ifpdf package is supposed to detect if pdfTeX is running: This package looks for pdfTeX in pdf mode and implements and sets the switch \ifpdf. (from the ifpdf documentation) However, when I compile the following MWE with LuaLaTeX, my document reads This is pdfTeX. Skip code block \documentclass{article} \usepackage{ifpdf} \begin{document} \ifpdf This is pdfTeX. \else This is not pdfTeX. \fi \end{document} Is this expected and intended behavior? How do I set up a conditional that only detects pdfTeX? (The MWE works as expected for XeTeX.)

668

Tags: pdftex (Prev Q) (Next Q), conditionals (Prev Q) (Next Q) User: doncherry

Answer by heiko-oberdiek LuaTeX comes from pdfTeX, it also knows the same modes for PDF and DVI and provides nearly all PDF features of pdfTeX. It knows even \pdftexversion and \pdftexrevision. Thus \ifpdf has the same semantics here. The test \ifpdf is not for testing for an engine. Even if \ifpdf is false, then you can have pdfTeX, but pdfTeX in DVI mode. Usually TeX Live and MiKTeX are also using pdfTeX for the command latex, but generating DVI with pdfTeX in DVI mode. If you want to know, if pdfTeX and not LuaTeX is running, then you can exclude luatex by \ifluatex of package ifluatex and then testing for \pdftexversion, for example: Skip code block \usepackage{ifluatex} \usepackage{ifpdf} \ifluatex \typeout{This is LuaTeX}% \else \begingroup\expandafter\expandafter\expandafter\endgroup \expandafter\ifx\csname pdftexversion\endcsname\relax \typeout{This is neither LuaTeX nor pdfTeX}% \else \typeout{This is pdfTeX in \ifpdf PDF \else DVI \fi mode}% \fi \fi Testing for package driver options and … Some TeX engines and modes can be detected at TeX macro level and the packages (or its configuration files) are automatically loading the right

669

drivers, e.g.: • pdfTeX and LuaTeX in PDF mode • XeTeX DVI drivers are different. The DVI driver program is running after the TeX run, thus there is no way of knowing the future. The default is often dvips. Therefore in many cases you won’t need complicate switch structures to differentiate between the different TeX compilers, just loading the package is enough: \usepackage{color} \usepackage{graphicx} \usepackage{hyperref} In case of package fontspec you need to test for the Unicode aware TeX compilers, for example: Skip code block \usepackage{ifluatex} \usepackage{ifxetex} \ifluatex \usepackage{fontspec} % other LuaTeX setup \else \ifxetex \usepackage{fontspec} % other XeTeX setup \else \usepackage[T1]{fontenc} \usepackage{textcomp} \usepackage{lmodern} % other font setup \fi \fi

Answer by herbert use the package ifluatex instead with \ifluatex ... \else ... \fi 670

Tags: pdftex (Prev Q) (Next Q), conditionals (Prev Q) (Next Q)

Q: hyperref: Wrong DVI mode driver option ‘dvips’,(hyperref) because pdfTeX or LuaTeX is running in PDF mode. \ProcessKeyvalOptions{Hyp} Tags: pdftex (Prev Q) (Next Q), hyperref (Next Q) hyperref: Wrong DVI mode driver option `dvips',(hyperref) because pdfTeX or LuaTeX is running in PDF mode. \ProcessKeyvalOptions{Hyp} How can i fix this error? I m trying to compile a template of MMA journal. It is under this link MMA Template Tags: pdftex (Prev Q) (Next Q), hyperref (Next Q) User: andii

Answer by heiko-oberdiek Class mma.cls is intended to be used with latex+dvips and contains several driver option settings: \usepackage[dvips,a4paper,colorlinks,breaklinks,unicode]{hyperref}%backref, \usepackage[dvips]{color} If you want to use pdflatex, then remove options dvips.

Tags: pdftex (Prev Q) (Next Q), hyperref (Next Q)

671

Q: What possibilities are there of using OpenType fonts and margin kerning? Tags: pdftex (Prev Q) (Next Q), protrusion (Prev Q) (Next Q) I really like the protrusion and margin kerning features of pdfTeX and LuaTeX. I also like to use other fonts than those available for TeX. What choices do I have when I want to use both? Also, what problems with typography should I expect? Tags: pdftex (Prev Q) (Next Q), protrusion (Prev Q) (Next Q) User: roman-plášil

Answer by khaled-hosny This is for lualatex: Skip code block \documentclass{article} \usepackage{fontspec} \setmainfont[RawFeature={protrusion=default}]{TeX Gyre Pagella} \pdfprotrudechars2 % 1 if you don't want to change line breaking \begin{document} \input{knuth} \end{document}

Tags: pdftex (Prev Q) (Next Q), protrusion (Prev Q) (Next Q)

Q: Selectively disable dash ligatures in LuaLaTeX Tags: pdftex (Prev Q) (Next Q), ligatures (Prev Q) (Next Q) 672

With pdfLaTeX, I can print two hyphens using -{}-. This does not seem to work in LuaLaTeX. Indeed, the following snippet \documentclass{minimal} \begin{document} en dash -- two dashes -{}\end{document} prints en dash — two dashes -when compiled with pdflatex, but en dash — two dashes — when compiled with lualatex. How do I print -- in LuaLaTeX without disabling ligatures completely? Tags: pdftex (Prev Q) (Next Q), ligatures (Prev Q) (Next Q) User: clément

Answer by egreg I suppose you don’t want to introduce break points at the double hyphen. Here’s a way. Skip code block \documentclass{article} %\usepackage{fontspec} % works also with fontspec \newcommand{\texthyphen}{} % ensure \texthyphen is not defined \protected\def\texthyphen{\mbox{-}} \begin{document} en dash -- two dashes \texthyphen\texthyphen \textit{en dash -- two dashes \texthyphen\texthyphen} 673

\textbf{en dash -- two dashes \texthyphen\texthyphen} \strut \vrule-\vrule\ \textit{\vrule-\vrule} \textbf{\vrule-\vrule} \end{document} The \protected is just to avoid the command being expanded when in moving arguments, but it’s not really necessary. I add a graphic analysis of the hyphen’s placement with respect to its bounding box.

Answer by mico Indeed, the method of breaking up ligatures by inserting an empty TeX group, {}, does not work in LuaTeX and LuaLaTeX. To prevent the creation of an en-dash, then, you could insert a ”zero-width kern”, i.e., -\kern0ptor an explicit ”italic correction”, i.e., -\/With either method, LuaTeX will not insert a line break between the two dashes. If you have many instances of such double-dashes, you may want to create a dedicated macro called, say, \dbldash, to streamline your typesetting: 674

\newcommand{\dbldash}{-\kern0pt-} Here’s an illustration of the result of using \dbldash:

\documentclass{article} \usepackage{fontspec} \setmainfont[Ligatures=TeX]{Latin Modern Roman} \newcommand\dbldash{-\kern0pt-\ } \begin{document} dash - endash -- double-dash \dbldash \end{document} Aside: At least if the Computer Modern (and Latin Modern) font family is in use, employing either the -\kern0pt- or the -\/- method while in italics mode will result in slightly more whitespace being inserted between the two dashes; this amount is the same irrespective of which of the two methods is in use. The cause of this increased space between the dashes would appear to be the fact that the ”side-bearing” (the glyph-associated white-space) in front of (but not the one behind) the dash-character is slightly more generous in the italic font shape than they are in the upright font shape. Addendum: @egreg’s parallel answer shows explicitly that there’s a nonzero side-bearing in front of but not behind the dash character when it occurs in italic mode, at least for the Computer Modern font family. In contrast, there’s a somewhat smaller non-zero side-bearing after, but not before, the dash character in the plain-upright and bold-upright font shapes. These differences in side-bearings cause the differences in whitespace between the plain-upright and italic font shapes.

Tags: pdftex (Prev Q) (Next Q), ligatures (Prev Q) (Next Q)

Q: Problems with mixing Icelandic and German with LuaLaTex Tags: pdftex (Prev Q) (Next Q), babel (Prev Q) (Next Q) 675

So what I am trying to do is to use the letter-classic class with LuaLaTeX (This is LuaTeX, Version beta-0.80.0 (MiKTeX 2.9) (rev 5238) (format=lualatex 2015.11.10) 25 NOV 2015 09:30) as included in MikTeX. It bombs in icelandic.ldf with errors like these: Skip code block ! String contains an invalid utf-8 sequence. l.144 \DeclareTextCommand{\ooob}{T1}{\sob { ó}{.85}{0}{.04}{0}} A funny symbol that I can't read has just been (re)read. Just continue, I'll change it to 0xFFFD. ! String contains an invalid utf-8 sequence. l.145 \DeclareTextCommand{\OOob}{T1}{\sob { Ó}{.7}{0}{0}{0}} A funny symbol that I can't read has just been (re)read. Just continue, I'll change it to 0xFFFD. ! String contains an invalid utf-8 sequence. l.148 \DeclareTextCommand{\eeob}{T1}{\sob { é}{1}{0}{.04}{0}} A funny symbol that I can't read has just been (re)read. Just continue, I'll change it to 0xFFFD. ! String contains an invalid utf-8 sequence. l.149 \DeclareTextCommand{\EEob}{T1}{\sob { É}{1}{0}{.04}{0}} A funny symbol that I can't read has just been (re)read. Just continue, I'll change it to 0xFFFD. ! String contains an invalid utf-8 sequence. l.152 \[email protected]{icelandic}{" ó}{\ooob} A funny symbol that I can't read has just been (re)read. Just continue, I'll change it to 0xFFFD.

676

! String contains an invalid utf-8 sequence. [email protected]@\string "@\string � \ooob @ l.153 \[email protected] {icelandic}{"Ó}{\OOob} A funny symbol that I can't read has just been (re)read. Just continue, I'll change it to 0xFFFD. My minimal working example is this one: Skip code block

\documentclass[english,12pt,a4paper]{letter-classic} \usepackage[T1]{fontenc} \usepackage[icelandic,german,english]{babel} \selectlanguage{english} \newcommand{\ISL}[1]{\foreignlanguage{icelandic}{#1}} \newcommand{\DEU}[1]{\foreignlanguage{german}{#1}} %%\usepackage[utf8]{inputenc} % needed with pdfLaTeX, but not with LuaLaTeX (see c \begin{document} \begin{letter}{Troll family\\\ISL{Elliðaárdalur}\\\ISL{999 Reykjavík}\\ICELAND} \fromname{\DEU{Mäxchen Mustermann}} \fromstreet{\DEU{Musterstraße 123}} \fromtown{12345 Musterstadt} \fromphone{+49 123 4567890} \fromtownshort{Musterstadt} \fromsignature{\DEU{Mäxchen}} \subject{\ISL{Jólasveinar}} \opening{Folks,}

do you know the current address of the \ISL{Jólasveinar} and/or their parents \ISL \closing{\ISL{Með kveðju,}} \end{letter} \end{document} 677

The actual document worked without problems until a few months ago, using pdfLaTeX (and still does, see below).

How it looks

.

Can anyone explain to me how to mix Icelandic and German using LuaLaTeX with the letter-classic class?

I looked into the KOMA letter class already, but I prefer a slightly more modern/custom look for the letter head, such that at this moment I really want to avoid that one. Tags: pdftex (Prev Q) (Next Q), babel (Prev Q) (Next Q) User: 0xc0000022l

Answer by egreg The problem is not in mixing Icelandic and German. A smaller example shows the issue in all document classes.

678

\documentclass{article} \usepackage[icelandic]{babel} \begin{document} Test \end{document} Running this through LuaLaTeX produces the same error you see (and similar ones later on): ! String contains an invalid utf-8 sequence. l.144 \DeclareTextCommand{\ooob}{T1}{\sob { ?}{.85}{0}{.04}{0}} ? Unfortunately, the file icelandic.ldf loaded by babel hardcodes four Latin1 characters to be used for shorthands in "Ó "ó "É "é and, when LuaTeX is reading the file, it chokes on that invalid input. XeTeX is more forgiving in this respect and doesn’t choke. As it stands, babel-icelandic is not compatible with LuaLaTeX and there’s no workaround, as far as I can see, except writing a modified icelandic.ldf file. Lines 142 to 157 should be Skip code block 142 143 144 145 146 147 148 149 150

\DeclareTextCommand{\oob}{T1}{\sob {o}{.85}{0}{.04}{0}} \DeclareTextCommand{\Oob}{T1}{\sob {O}{.7}{0}{0}{0}} \DeclareTextCommand{\ooob}{T1}{\sob {^^f3}{.85}{0}{.04}{0}} \DeclareTextCommand{\OOob}{T1}{\sob {^^d3}{.7}{0}{0}{0}} \DeclareTextCommand{\eob}{T1}{\sob {e}{1}{0}{.04}{0}} \DeclareTextCommand{\Eob}{T1}{\sob {E}{1}{0}{.04}{0}} \DeclareTextCommand{\eeob}{T1}{\sob {^^e9}{1}{0}{.04}{0}} \DeclareTextCommand{\EEob}{T1}{\sob {^^c9}{1}{0}{.04}{0}} \[email protected]{icelandic}{"o}{\oob} 679

151 152 153 154 155 156 157

\[email protected]{icelandic}{"O}{\Oob} \[email protected]{icelandic}{"^^f3}{\ooob} \[email protected]{icelandic}{"^^d3}{\OOob} \[email protected]{icelandic}{"e}{\eob} \[email protected]{icelandic}{"E}{\Eob} \[email protected]{icelandic}{"^^e9}{\eeob} \[email protected]{icelandic}{"^^c9}{\EEob}

Changes are in the lines where ^^ appears; I added the line numbers for convenience. A bug report should be filed to the maintainer of babel.

Answer by ulrike-fischer As a work-around you could switch locally to ansinew reading with luainputenc: (edited a bit to reset the catcodes afterwards and also removed the write call back so that the toc now contains again real utf8). Skip code block \documentclass{article} \usepackage{fontspec} \usepackage{luatexbase} %not needed now, but probably in the future. \PushCatcodeTableNumStack \usepackage[ansinew]{luainputenc} \usepackage[icelandic]{babel} \PopCatcodeTableNumStack

\directlua{luatexbase.remove_from_callback('process_input_buffer', 'luainputenc.fa luatexbase.remove_from_callback('process_output_buffer','luainputenc.fa luainputenc.state = stopped} \begin{document} \tableofcontents \section{öäüß} äöüß € ólasveinar Grýla Leppalúði \end{document} 680

But it is quite possible that some other things in icelandic.ldf are not suitable to luatex and then you will have to adapt more.

Answer by andrew-swann Why not use polyglossia? I don’t have letter-classic, but here is similar version in letter:

Skip code block 681

\documentclass{letter} \usepackage[T1]{fontenc} \usepackage{polyglossia} \setdefaultlanguage{english} \setotherlanguages{icelandic,german} \newcommand{\ISL}[1]{\texticelandic{#1}} \newcommand{\DEU}[1]{\textgerman{#1}} \begin{document} \begin{letter}{Troll family\\\ISL{Elliðaárdalur}\\\ISL{999 Reykjavík}\\ICELAND} \name{\DEU{Mäxchen Mustermann}} \address{\DEU{Musterstraße 123}\\ 12345 Musterstadt} \telephone{+49 123 4567890} \signature{\DEU{Mäxchen}} \opening{Folks,} \begin{center} \ISL{Jólasveinar} \end{center}

Do you know the current address of the \ISL{Jólasveinar} and/or their parents \ISL \closing{\ISL{Með kveðju,}} \end{letter} \end{document}

Tags: pdftex (Prev Q) (Next Q), babel (Prev Q) (Next Q)

682

Q: Using \input|texlua... to emulate \directlua in pdfTeX Tags: pdftex (Prev Q) (Next Q), shell-escape (Next Q) When --shell-escape is enabled, pdfTeX allows to run external programs and input the result expandably with \input|"...". Together with the Lua interpreter texlua, this could be used to provide a dumbed down version of \directlua. However, texlua expects a file name as its argument. In my setup (Ubuntu 10.04, with up-to-date TeXLive 2012 install), one can run pdftex --shell-escape on

\everyeof{\noexpand} \message{\input|"echo print\string\(3.4+5.7\string\) > tmp.lua ; texlua tmp.lua" a \bye to get \message{9.1}. Note that the \everyeof{\noexpand} is in part for convenience, it would be possible to make the construction work (not entirely robustly) without this non-expandable step. This approach is not portable because it relies on echo, which probably doesn’t exist in Windows environments. One way around this would be to have a simple Lua script taking the code print\string\(3.4+5.7\string\) as its argument (see a recent question on texlua arguments), then somehow performing it. Is this possible? Otherwise, we need an os-dependent approach. A second problem is that special characters such as parentheses need escaping. Which ones? In particular, I’m worried about quotes ", which are used to enclose the argument of \input|. Given a list of which escapings to perform, I have some code up my sleeve to do that expandably (see the l3kernel-extras package on the LaTeX3 svn repository). Basically, my question boils down to: ”How can I invoke texlua from pdfTeX with arbitrary Lua code as portably as possible?” Tags: pdftex (Prev Q) (Next Q), shell-escape (Next Q) User: bruno-le-floch

Answer by joseph-wright 683

The echo built-in is available on both Unix and Windows, and so provided platform detection is available then the problem is in principal one of deciding which characters to escape. For LaTeX, platform detection can be done using the ifplatform package, which provides the \ifwindows switch. The first character to worry about is the ’chain process’ one. On Windows, this is &, whereas on Unix ; is correct. That be handles with something like \RequirePackage{ifplatform} \edef\luachainprocess{\ifwindows\string&\else;\fi } There is then the question of special characters in the echo part. For Windows, the required substitutions are • • • • •

> < | & ^

replaced replaced replaced replaced replaced

by by by by by

^> ^< ^| ^& ^^

with everything else left alone by echo. On Unix, the appropriate list seems to be • • • • • • • •

> < ( ) & | ` \

replaced replaced replaced replaced replaced replaced replaced replaced

by by by by by by by by

\> \< \( \) \& \| \` \\

(Note: that is with the bash shell, but others may vary.) As Windows allows for example ^( for (, it would probably be easiest to use a common set of characters for replacement with only the escape character itself varying. (The same is true for Unix with for example \^.) One thing that is not clear at all is if there is any way to deal with " in either case, as the pipe syntax for \input does not provide an escape for this, so it seems to be misunderstood whatever you do. This is particularly frustrating for the Unix case as generating effectively 684

echo "" would avoid needing to escape anything other than " inside the code.

Answer by bruno-le-floch I found out about the loadstring function in Lua, which converts a string to Lua code. To avoid any escaping issue for the TeX → Lua conversion, the TeX code converts the argument of \texlua to a space-separated list of character codes, which is then given as extra arguments to texlua. The Lua code decodes this using to str.char. The remaining weak link is that \input|..., just like any other \input or \scantokens, inserts an end-of-file marker, which may not appear in the argument of any command. We need to get rid of it, and one way is to add some material just before, and just after, the end of the file, here \romannumeral\numexpr0\noexpand and \relax (the \noexpand is key). Unfortunately, the code \romannumeral\numexpr0\noexpand is not inserted if there is a Lua error; in this case, the end-of-file marker is not removed, and all hell breaks loose. Skip code block \begingroup \catcode `@ = 11 % % Get \[email protected] = primitive \input \expandafter\ifx\csname @@input\endcsname\relax \global\let\[email protected]\input \else \global\let\[email protected]\@@input \fi % % Write very simple Lua file. \newwrite \[email protected] \xdef \[email protected] {\jobname.texlua} \immediate \openout \[email protected] \[email protected] \relax \immediate \write \[email protected] {% 685

assert(loadstring(string.char(unpack(arg))))()% \detokenize{print("\\romannumeral\\numexpr0\\noexpand")}% } \immediate \closeout \[email protected] % % Detokenize the argument and convert spaces to category other. \gdef\[email protected]#1% {% \expandafter\[email protected]@i \detokenize{#1}\\ \\\[email protected]@ii/ \relax } \lccode `* = 32 \lowercase{\gdef\[email protected]@i#1 #2\\#3 {#3\[email protected]@i#1*#2\\{#3} }} \gdef\[email protected]@ii/#1#2\\#3\relax{#2} % % Convert each character to its character code, space-separated. % This is not "f-expandable", it is "restricted expandable" in % expl3 terms. \gdef\[email protected]#1% {\expandafter\[email protected]@i\romannumeral-`q\[email protected]{#1}\relax} \gdef\[email protected]@i#1% {% \ifx #1\relax \else \number `#1 \space \expandafter\[email protected]@i \fi } % % Calling `\input|`. \gdef\texlua#1% {% \[email protected]|"texlua \[email protected] \space \[email protected]{#1}"% \relax } \endgroup \message{a\texlua{io.write(3+4)}b} 686

Answer by aditya In filter module in ConTeXt provides the necessary boilerplate to run the content of an environment or macro through an external command (full disclosure, I am the author of the module). It does not use \input| to read the output, rather assumes that the external program will write the file to an external file and then the user can specify how to read the file (the default is \ReadFile, which is similar to \input). The example below illustrates how to process using texlua. Skip code block % engine=pdftex \usemodule[filter] \defineexternalfilter [luatex] [filtercommand={texlua \externalfilterinputfile > \externalfilteroutputfile}] \starttext \inlineluatex{print((3+5)*3)} \startluatex local t = {1,2,3} print("Number of entries " .. #t) \stopluatex \stoptext Note: The \inlineluatex macro is not expandable.

Tags: pdftex (Prev Q) (Next Q), shell-escape (Next Q)

687

Q: Hyphenation does not work with acro and luatex, but with pdftex Tags: pdftex (Prev Q) (Next Q), hyphenation (Prev Q) (Next Q) I’m using luatex 0.70.1 together with acro 1.2 and I have the following MWE. Skip code block \documentclass{minimal} \usepackage[ngerman]{babel} \usepackage{acro} \DeclareAcronym{DNA}{ short=DNA, long=Desoxyribonukleinsäure }

\begin{document} Das ist ein sehr langer Satz und er wird an seinem Ende leider nicht richtig umgeb

Das ist ein sehr langer Satz und er wird an seinem Ende leider nicht richtig umgeb \end{document} Document looks normal with pdftex (both lines wrapped after dash), but when using luatex the 2nd line continues into the margin. I would have posted images, but due to the fact that this is my first post the systems doesn’t allow it. Tags: pdftex (Prev Q) (Next Q), hyphenation (Prev Q) (Next Q) User: quincy

Answer by egreg This has to do with the different hyphenation algorithm used by LuaTeX. I don’t really know the details, but here’s what’s shown when I put DNA-Sequenzierung and \acs{DNA}-Sequenzierung in a box and make LuaTeX show it.

688

\sbox0{DNA-Sequenzierung} Skip code block \hbox(6.8872+1.94397)x88.4784, direction TLT .\T1/cmr/m/n/10 D .\T1/cmr/m/n/10 N .\T1/cmr/m/n/10 A .\T1/cmr/m/n/10 .\discretionary .\T1/cmr/m/n/10 S .\T1/cmr/m/n/10 e .\T1/cmr/m/n/10 q .\T1/cmr/m/n/10 u .\T1/cmr/m/n/10 e .\T1/cmr/m/n/10 n .\T1/cmr/m/n/10 z .\T1/cmr/m/n/10 i .\T1/cmr/m/n/10 e .\T1/cmr/m/n/10 r .\T1/cmr/m/n/10 u .\T1/cmr/m/n/10 n .\T1/cmr/m/n/10 g \sbox0{\acs{DNA}-Sequenzierung} Skip code block \hbox(6.8872+1.94397)x88.4784, direction TLT .\hbox(6.8872+0.0)x22.63336, direction TLT ..\hbox(6.8872+0.0)x22.63336, direction TLT ..\hbox(6.8872+0.0)x0.0, glue set - 22.63336fil, direction TLT ...\glue 0.0 plus 1.0fil minus 1.0fil ...\T1/cmr/m/n/10 D ...\T1/cmr/m/n/10 N ...\T1/cmr/m/n/10 A .\T1/cmr/m/n/10 .\T1/cmr/m/n/10 S .\T1/cmr/m/n/10 e 689

.\T1/cmr/m/n/10 .\T1/cmr/m/n/10 .\T1/cmr/m/n/10 .\T1/cmr/m/n/10 .\T1/cmr/m/n/10 .\T1/cmr/m/n/10 .\T1/cmr/m/n/10 .\T1/cmr/m/n/10 .\T1/cmr/m/n/10 .\T1/cmr/m/n/10 .\T1/cmr/m/n/10

q u e n z i e r u n g

In the first case LuaTeX puts a \discretionary item after the hyphen, while it doesn’t in the second case, probably because it thinks that the hyphen is at the start of a word (it comes after a box which is not part of the word). This does not happen with pdfLaTeX, because the \discretionary item is inserted at a later stage. It’s probably better, in any case, using the babel shortcuts: Das ist ein sehr langer Satz und er wird an seinem Ende leider nicht richtig umgebrochen: DNA"=Sequenzierung Das ist ein sehr langer Satz und er wird an seinem Ende leider nicht richtig umgebrochen: \acs{DNA}"=Sequenzierung which gives

Tags: pdftex (Prev Q) (Next Q), hyphenation (Prev Q) (Next Q)

690

Q: Does the lualatex shell enable behavior differ from pdflatex on purpose? Tags: pdftex (Prev Q) (Next Q), shell-escape (Prev Q) (Next Q) I am trying to use TikzEdt, an editor for TikZ graphics. For some tasks TikZ needs to call other commands so I tried to enable this by the parameter --shell-escape passed to lualatex (on Windows, MiKTeX 2.9). Strangely this fails to enable the feature. After some fiddling around it turns out that it even fails with this MWE: \documentclass{standalone} \begin{document} \write18{echo SHELL ENABLED} \end{document} TikzEdt appends the switch and calls lualatex test.tex --shell-escape which does not seem to work. The same command with pdflatex works nicely. It turns out that other than in pdflatex the order of arguments seem to play a role in lualatex, lualatex --shell-escape test.tex runs nicely. Unfortunately TikzEdt only allows to append switches not insert switches. Is this a bug in lualatex or is TikzEdt using a wrong assumption? Tags: pdftex (Prev Q) (Next Q), shell-escape (Prev Q) (Next Q) User: alexander

Answer by egreg Let’s try a simple document test.tex; the package pdftexcmds is loaded in order to have \[email protected] available with all engines. Skip code block \documentclass{article} \usepackage{pdftexcmds} \makeatletter \[email protected]=\[email protected] \showthe\[email protected]

691

\makeatother \begin{document} Ciao \end{document} Here’s what happens with • • • • • •

pdflatex test pdflatex test --shell-escape lualatex test lualatex test --shell-escape xelatex test xelatex test --shell-escape

The execution stops because of \showthe, showing > 2. l.5 \showthe\[email protected] in all six invocations (TeX Live 2012 on Mac OS X, but I don’t think it’s different with other platforms). If we put --shell-escape at its proper place, the execution of any of • pdflatex --shell-escape test • lualatex --shell-escape test • xelatex --shell-escape test stops showing > 1. l.5 \showthe\[email protected] This means that the setting of --shell-escape can be done only in ”infix notation” and that the option has no effect if postfixed. As kindly as usual, Paulo Cereda confirms that, on MiKTeX, options can be specified after the file name for pdftex and xetex, but not for luatex. As the most common syntax format on other systems is with ”infix” options, my opinion is that TikZEdt is wrong in its assumptions.

692

Answer by herbert the syntax of luatex (lualatex) is Usage: luatex --lua=FILE [OPTION]... [TEXNAME[.tex]] [COMMANDS] or: luatex --lua=FILE [OPTION]... \FIRST-LINE or: luatex --lua=FILE [OPTION]... &FMT ARGS --shell-escape is an option the reason why it must be before the TEXNAME[.tex]

Tags: pdftex (Prev Q) (Next Q), shell-escape (Prev Q) (Next Q)

Q: How to increase bufsize for lualatex or pdflatex? Tags: pdftex (Prev Q) (Next Q) I work with large TikZ graphics for which the default bufsize of lualatex/pdflatex is too small: Unable to read an entire line---bufsize=200000. Please increase buf_size in texmf.cnf. Is there a quick way to increase the buffer size for either lualatex or pdflatex without editing texmf.cnf? If there is no quick solution, could someone please describe the obscure configuration mechanism of LaTeX that needs to be executed to process changes made to texmf.cf? Also, where is texmf.cnf in a standard installation of a Ubuntu texlive package? What happens to my changes to texmf.cf when I update the texlive package? Tags: pdftex (Prev Q) (Next Q) User: bernhard-anderson

693

Answer by martin-schröder To find the texmf.cnf of your installation, use kpsewhich: kpsewhich texmf.cnf In a normal installation of texlive this will point you to a file that will probably tell you not to edit any other texmf.cnf. You could try to increase the buf_size for one run by setting it on the cmdline: buf_size=100000 pdflatex foo.tex This may work, but you may also have to change texmf.cnf and recreate the formats. See also Memory settings with MacTeX - Which texmf.cnf to modify

Tags: pdftex (Prev Q) (Next Q)

Q: char to integer cast in latex Tags: pdftex (Prev Q) (Next Q) I am wondering what an integer in LaTeX is. I take this from pdfTeX release notes (2005-08-01) • \pdfelapsedtime is a read-only integer that (initially) returns the amount of time passed since the start of this run. This amount is given in ‘scaled seconds’: the value 65536 counts as one second. If more time has passed than 32767 seconds, (2^31)-1 will be returned. • \pdfresettimer updates the internal timer, such that subsequent calls to \pdfelapsedtime will restart from 0. so I guess the return value from \pdfelapsedtime is an integer. I have to use \the\pdfelapsedtime to cast it to string value (please correct my words to

694

the LaTeX conventions, I hope everybody knows what I mean). To further elucidate my problem, please look at the following MWE: \documentclass{minimal} \newcount\benchmarkcount \begin{document} \pdfelapsedtime \benchmarkcount \end{document} The first error is ! You can't use '\pdfelapsedtime' in vertical mode. while the second one gives ! Missing number, treated as zero. So an integer is not the same as a counter either. Is there anything -- let me call it \foo -- that casts a string to become an integer, e.g. \foo\the\pdfelapsedtime. Or, that would solve my problem as well, is there an analog to \directlua{tex.print(...)} that gives an integer back? background: I am working on the answer to this question and try to make the lualatex \pdfelapsedtime macro as identical to the pdflatex one as possible. Tags: pdftex (Prev Q) (Next Q) User: andy

Answer by joseph-wright The difference here is that \pdfelapsedtime is read only integer, while \benchmarkcount is a read-write register. In both cases, the contents are ’internal integers’, and therefore you need \the or \number to insert the values into the input stream. However, TeX will allow you to assign to \benchmarkcount \benchmarkcount so when you use it as you have done, TeX goes looking for a number and fails to find one. On the other hand, you cannot assign \pdfelapsedtime. 695

That means that you simply can’t use it as you have, and so TeX complains. Thus while the difference can be explained, the only way you can get the same error is to create a new \pdfelapsedtime which is a TeX count. The problem there is that the value is dynamic, and so the usual copy-and-rename approaches will fail.

Tags: pdftex (Prev Q) (Next Q)

Q: warning (pdf backend): pop empty color page stack 0 Tags: pdftex (Prev Q), tcolorbox (Next Q), color (Next Q) I’ve been receiving this warning and for the past several hours (erh, something like 12 hours now). I’ve been trying to narrow down what’s been causing it, but to no avail. I managed to cut down the project to ~1000 lines of code and still produce the warning, but I’ve tried cutting out tens of different things from that ~1000 lines, and so far, whatever I try to cut beyond that makes the warning go away, making it incredibly difficult to debug. There’s also of course no line the warning points to and no visual indication in the document that something is wrong to point me in the right direction. Here is a link to the actual project that produces the warning. So far I’ve managed to deduce that \includeonly{basics,apd} reproduces the error, but if you remove either basics or apd here, the warning goes away. Furthermore, while I haven’t tested ever two-chapter combination, it is the only two-chapter combination I have found that will reproduce the warning (and no chapter by itself will reproduce it). I am also able to remove ~half the lines from either of these files to still retain the warning, but, besides the actual amount of code I’m removing, I don’t see any pattern in the code that does and does not reproduce the warning. I’ve also been able to remove the title page, table of contents, references, and index, and still retain the warning. I apologize for not being able to give any sort of MWE, but I really wasn’t able to get it down much more than \includeonly{basics,apd} even after 696

hours and hours of experimenting. Hopefully at least someone has an idea as to what this error even means so that I have a better chance of debugging it? (FWIW, the pdf backend I’ve been using is LuaLaTeX, though I’ve confirmed that pdfLaTeX produces the warning just the same (from the TeX Live 2016 distro). Perhaps it’s also worth noting that Texmaker (my current IDE) does not report this warning and I have to go into the log file to find it.) Tags: pdftex (Prev Q), tcolorbox (Next Q), color (Next Q) User: jonathan-gleason

Answer by david-carlisle Well what it means is that’s you’ve corrupted the colour stack. Unlike font changes colour is not an intrinsic attribute of a tex box, so colour changes are managed by nodes marking the change of state whatsit, Originally it was very hard to maintain colour correctly over page breaks, as the macro package needed to normalise colour in the page headings and could not reset the current colour for the text at the start of a page as the page breaking routine can not easily insert a special there. dvips introduced the notion of a colour stack where the driver maintains a stack of colours that are handled correctly at a page break, and the macro layer just needs to push and pop colours on to this stack rather than trying to set the ”correct” colour at points over which it has little control. pdftex (and luatex) extend this model further and have specific push/pop commands more or less: \pdfcolorstack push {red} ... \pdfcolorstack pop so you get the error if you have a \colorstack pop without a matching push, or in latex macro wrappers, if you have a \[email protected] without a \[email protected]

697

I guess this fixes it, modify \tcbtitle after loading tcolorbox in your structure file:

\usepackage{tcolorbox} % Required for creating the theorem, definition, exercise a \makeatletter \renewcommand\tcbtitle{\ifx\tcbtitletext\@empty\else% {\leavevmode\color{[email protected]}\[email protected] \[email protected]\[email protected]@title \tcbtitletext\[email protected]@title}\fi} \makeatother or perhaps better \makeatletter \renewcommand\tcbtitle{\ifx\tcbtitletext\@empty\else% {\[email protected]\[email protected]\[email protected]@title \leavevmode\color{[email protected]}\tcbtitletext\[email protected]@title}\fi} \makeatother so you delay the color until after \[email protected]@title

Answer by heiko-oberdiek The warning ”pop empty color stack” is usually caused by color stack commands out of order. A typical scenario is the use of low level box set command \setbox instead of LaTeX box set macros (\sbox, environment lrbox, ...). When LaTeX sets a color, then the color reset command is issued after the current group. Therefore LaTeX box macros add a group layer around the contents of the box. Without this additional group, the color reset (pop operation of the color stack) leaks out of the box and is executed at the wrong time: \documentclass{article} \usepackage{color} \begin{document} \setbox0=\hbox{\color{red}Red} \null \end{document}

698

At the begin of the box the color red is put on the stack. Then the box is closed and the pop operation leaks out of the box and is executed at the time of the box definition, before the box is used. Push and pop are out of order (in the example the box is not used, only the pop special). Solution: A group keeps the pop special inside: \setbox0{\begingroup\color{red}Red\endgroup} because it is inserted after \endgroup before the box closes. LaTeX’s \sbox does this automatically: \sbox0{\color{red}Red}

Tags: pdftex (Prev Q), tcolorbox (Next Q), color (Next Q)

Unicode Math Questions Q: What is the right way to input prime with Unicode-math (LuaTeX backend) Tags: unicode-math (Prev Q) (Next Q) I opened an issue about this in Unicode-math’s github repository. However, I am not so sure it is actually a bug, or I just did something wrong. Here is a minimal example, Skip code block \documentclass{article} \usepackage{unicode-math} \setmathfont[version=Asana]

{Asana Math} 699

\setmathfont[version=Cambria] {Cambria Math} \setmathfont[version=LatinModern]{Latin Modern Math} \setmathfont[version=Minion] {Minion Math} \setmathfont[version=XITS] {XITS Math} \def\testprime{f'x'f''''x''''\quad f\prime x\prime f\qprime x\qprime} \setlength{\parindent}{0pt} \begin{document} \fontsize{36}{36}\selectfont Asana \mathversion{Asana} Cambria \mathversion{Cambria} LatinModern \mathversion{LatinModern} Minion \mathversion{Minion} XITS \mathversion{XITS} \end{document}

700

\[ \[ \[ \[ \[

\testprime \testprime \testprime \testprime \testprime

\] \] \] \] \]

It seems that the ASCII input was transformed into supscripts while \prime etc are not. 701

With Asana Math the ASCII version looks fine while the \prime version looks horrible. It looks like in Asana Math primes are designed as normal glyph, they need to be raised to supscripts to works well. With Latin Modern Math, it looks horrible for both case. I think it is a font problem for LM case. For other three fonts, the \prime looks good while using ASCII input they looks terrible. In these fonts, the primes seems to be designed as a supscripts glyph, and raising them even more does not looks good. Is there anyway to modify the behavior of the ASCII input? In addition, with Latin Modern Math, neither '''' or \qprime works, they all produce nothing. I thought '''' was supposed to use negative kern to fake the \qprime when it is not available. Update: Thanks for both @KhaledHosny and @LeoLiu’s answers. Now it seems to be more complicated. Using the old TeX way to typeset primes get the position right when both prime and subscripts are presented. However, to conform the Unicode standard, I think the fonts should design the primes as superscript glyphs, which means they will look really bad when raised in superscript position. Right now my temporary solution is to use \prime etc. and add a negative kern between primes and subscripts. Update Thanks for @LeoLiu’s answer, which worked fine for me before. Here is just an update for newer versions of unicode-math. The main change is that the prefix of unicode-math’s internal macros is now __um instead of um. Skip code block \ExplSyntaxOn \group_begin: \char_set_catcode_active:N \char_set_catcode_active:N \char_set_catcode_active:n \char_set_catcode_active:n \char_set_catcode_active:n \char_set_catcode_active:n \char_set_catcode_active:n \char_set_catcode_active:n \char_set_catcode_active:n

\' \` {"2032} {"2033} {"2034} {"2057} {"2035} {"2036} {"2037} 702

\cs_gset:Nn \__um_define_prime_chars: { \cs_set_eq:NN ' \__um_scan_prime: \cs_set_eq:NN ^^^^2032 \__um_scan_prime: \cs_set_eq:NN ^^^^2033 \__um_scan_dprime: \cs_set_eq:NN ^^^^2034 \__um_scan_trprime: \cs_set_eq:NN ^^^^2057 \__um_scan_qprime: \cs_set_eq:NN ` \__um_scan_backprime: \cs_set_eq:NN ^^^^2035 \__um_scan_backprime: \cs_set_eq:NN ^^^^2036 \__um_scan_backdprime: \cs_set_eq:NN ^^^^2037 \__um_scan_backtrprime: } \group_end: \ExplSyntaxOff Also it seems that newer versions of CambriaMath and latest unicode-math together no longer need this fix. Though it is still needed for MinionMath. Tags: unicode-math (Prev Q) (Next Q) User: yan-zhou

Answer by khaled-hosny You can either use f' or f^\prime, which is the proper way for inputting prime even if not using unicode-math. The fact that some fonts give superscripted prime with \prime is not something you should rely on. See Why isn’t \prime automatically set to be a superscript? for the reason why old TeX fonts have such a big prime glyph (In OpenType math the issue is dealt with a bit differently, but some fonts still following the old practices).

Tags: unicode-math (Prev Q) (Next Q)

703

Q: LuaTeX: Wrong/missing italic correction in TeXLive 2015 vs 2014 Tags: unicode-math (Prev Q) (Next Q), math-mode (Prev Q) (Next Q) Italic correction for OTF math fonts seems to be broken in LuaTeX in TL15. MWE: \documentclass{article} \usepackage{unicode-math} \setmathfont{Latin Modern Math} \begin{document} \begin{equation} V^* \quad T^6 \quad T) \quad VT \end{equation} \end{document} Compiling with TL14 gives

and TL15:

There is no problem for upright letters (\mathup{T}). Using the .otf font from 2014 with TL15 produced the same result as with the 2015 font. I can remember having similar problems with TL11/12. So the question is: what caused this change and how can I fix it? Tags: unicode-math (Prev Q) (Next Q), math-mode (Prev Q) (Next Q) User: ismo-toijala 704

Answer by egreg The problem has a long history. It was brought up in 2011, as far as I know, with a message to the TeX Live mailing list; the thread went on also in the LuaTeX list. The problem is that LuaTeX doesn’t add the italic correction in math mode after characters having category code 11. Indeed, in TeX Live 2011, the output from your code would be the same as you get now. See How can I enable italic correction for LuaTeX? for finding a workaround that applies also to the present version of LuaLaTeX: Skip code block \documentclass{article} \usepackage{unicode-math} \setmathfont{Latin Modern Math} %\setmathfont{TeX Gyre Termes Math} \everymath\expandafter{\the\everymath\luatexcatcodetable\CatcodeTableLaTeX} \everydisplay\expandafter{\the\everydisplay\luatexcatcodetable\CatcodeTableLaTeX} \begin{document} \begin{equation} V^* \quad T^6 \quad T) \quad VT \end{equation} \end{document}

The problem was circumvented by changing the default category codes for math letters to 12. However, as suggested by Ulrike Fischer, the new release 705

of LaTeX (2015/01/01) has changed back the category codes to 11 for every character that qualifies as a letter and so the problem has reappeared. Quoting Joseph Wright in chat That’s a bit of a problem: we are for a start looking at fixing \CatcodeTableLaTeX so it has the right catcodes so the workaround is not guaranteed to be valid in the future (but I hope some better remedy will be found in the meantime).

Tags: unicode-math (Prev Q) (Next Q), math-mode (Prev Q) (Next Q)

Q: clash between mathtools and unicode-math Tags: unicode-math (Prev Q) (Next Q) Lately I started looking into LuaTeX and I must say I’m growing fond of it with every feature I discover. So I decided to transfer my pdfTeX preamble to LuaTex checking which packages still work and which ones need to be replaced. I use the mathtools package with pdfTeX for its centercolon and \smashoperator features. Unfortunately it seems to clash with the unicode-math package under LuaTeX. It boils down to: \documentclass{minimal} \usepackage{mathtools} \usepackage{unicode-math} \setmathfont{Latin Modern Math} \mathtoolsset{centercolon} \begin{document} \[:=\coloneq\coloneqq\eqcolon\eqqcolon:=\] \end{document} results in ! Invalid math code. 706

\let l.5 \mathtoolsset{centercolon} with LuaTex beta-0.70.1 under MiKTeX 2.9. It seems that unicode-math is aware of the mathtools package as it warns in the log file that some commands were redefined.

EDIT: As mentioned above as I’m not working on a true document just doing preamble conversion work. Thus the random choice of Latin Modern Math was a poor one as pointed out by egreg. The partial answer is that the new OpenMath OpenType Fonts make the centercolon feature of the mathtools package obsolete. I wasn’t aware of that. Of the handfull available OpenMath compliant fonts Neo Euler seems to be the only one where := is not symmetric. I can’t check Minion Math yet. Taking egregs answer into account and avoiding coloneq while trying to use mathtools to adjust Neo Euler’s := gives however the same error as above: Skip code block \documentclass{minimal} \usepackage{mathtools} \usepackage{unicode-math} \setmathfont[version=Asana]{Asana-Math.otf}% Asana Math \setmathfont[version=Cambria]{Cambria Math} \setmathfont[version=LatinModern]{Latin Modern Math} %\setmathfont[version=Minion]{Minion Math} \setmathfont[version=XITS]{xits-math.otf}% XITS Math \setmathfont[version=NeoEuler]{Neo Euler} \begin{document} \mathversion{Asana} Asana \(:=:=\) \mathversion{Cambria} Cambria \(:=:=\) \mathversion{LatinModern} LatinModern \(:=:=\) \mathversion{XITS} XITS \(:=:=\) \mathtoolsset{centercolon} \mathversion{NeoEuler} Neo Euler \(:=:=\) \end{document} Tags: unicode-math (Prev Q) (Next Q) 707

User: uli

Answer by egreg The main problem is that the \coloneq character is missing in Latin Modern Math: Missing Missing Missing Missing

character: character: character: character:

There There There There

is is is is

no no no no

� � � �

(U+2254) (U+2254) (U+2255) (U+2255)

in in in in

font font font font

name:LatinModernMath:mode=base;s name:LatinModernMath:mode=base;s name:LatinModernMath:mode=base;s name:LatinModernMath:mode=base;s

The fact that the messages are repeated is due to unicode-math redefining \coloneqq to \coloneq and \eqqcolon to \eqcolon. However, there should be no need to do anything special, since the math mode colon in Latin Modern Math and most other math OpenType fonts is symmetrical with respect to the equals sign, so := works as you wish. If you really want to use the control sequences, then \AtBeginDocument{% \renewcommand{\coloneq}{:=}% \renewcommand{\eqcolon}{=:}% } is what you need. For the NeoEuler font, where the colon is not symmetric with respect to =, you can emulate the behavior of mathtools by writing this code in the preamble: \newcommand{\centercolon}{\mathcode`:="8000 } \begingroup\catcode`\~=\active \lccode`~=`: \lowercase{\endgroup\def~}{\mathrel{\mathop\normalcolonchar}} \AtBeginDocument{ \edef\normalcolonchar{\Umathcharnum\the\Umathcodenum`: } \edef\normalcolon{\Umathcodenum`:=\the\Umathcodenum`: } } Then the declaration \centercolon will center the colon with respect to the math axis, from that point on; the declaration \normalcolon is the opposite 708

(so \centercolon is similar to \mathtoolsset{centercolon}).

Tags: unicode-math (Prev Q) (Next Q)

Q: Is direct utf8 input of combining diacritics in math mode possible with lualatex? Tags: unicode-math (Prev Q) (Next Q), unicode (Prev Q) (Next Q), mathmode (Prev Q) (Next Q) I am trying to typeset a document with combining diacritics directly input in it. I use LuaLaTex. Here is a minimal example illustrating the original issue: \documentclass{minimal} \usepackage{unicode-math} \setmathfont{XITS Math} \begin{document} $v�$ \end{document} The above vector arrow (U+20D7) is completely lost in the output. In text mode it would be shown, but in math mode it was discarded from the horizontal list alltogether. Then I tried the following: Skip code block \documentclass{minimal} \usepackage{unicode-math} \setmathfont{XITS Math} { 709

\catcode`\_=11\relax \catcode`\:=11\relax \gdef\SetMathCode#1#2{\um_set_mathcode:nnn{#1}{#2}\um_symfont_tl} } \SetMathCode{"20D7}\mathaccent \begin{document} $v�$ \end{document} This code essentially uses \Umathcode, indirectly through a macro in the unicode-math package. The reason is, that I found I had to change the math family of the arrow to the XITS font. The mapping of the diacritics (and possibly some of the other characters) are not set up automatically for math mode. Now the arrow is typeset adjacently to the right of the accented v. I want it to be typeset as accent, above the v. The \vec macro and \Umathaccent work, but I want to make the formulas plain-text readable if possible. (I use the Emacs quail system for input.) Could you please advice? My LuaTeX version is beta-0.70.2, TeX Live 2012, LaTeX2e XITS font is version 1.105. Thanks in advance Note: Obviously the problem arises when accenting the special script-like letters. In the end, the issue seems to be with the handling of the special topaccent glyph metric. It is supposed to be done as described in the ”Math accent handling” section of the luatex manual, but in reality is done only for the \Umathaccent command, and I think forgotten for combining characters. The text version of the font uses some other mechanism with horizontal offsets (called ”bearings”?), and goes around this limitation. I will investigate this a bit further. If it is a core issue, I should file this with the LuaTeX guys. Consider the question closed. It became too specific anyway.

710

Tags: unicode-math (Prev Q) (Next Q), unicode (Prev Q) (Next Q), mathmode (Prev Q) (Next Q) User: simeonz

Answer by von I got it working with a lua script. Your minimal example becomes: \documentclass{minimal} \usepackage{unicode-math} \setmathfont{XITS Math} \AtBeginDocument{\directlua{require("combining_preprocessor.lua")}} \newcommand{\�}[1]{\ensuremath{\vec{#1}}} \begin{document} $v�$ \end{document} The idea is that it’s difficult to make LaTeX handle a command or macro that comes after its argument, which is how Unicode combining characters work, so we use would like a preprocessor to move the accent so it comes before its argument. That is, map v� to \�{v} in a script, and then define whatever action you want \� to have. (That’s a backslash followed by a combining arrow, which should be printed above the backslash.) My lua script does most (all?) of the combining characters, so you just need to define what they should do in the .tex file. Many accents on the same character is possible. Example: Skip code block \documentclass{minimal} \usepackage{unicode-math} \setmathfont{XITS Math} \AtBeginDocument{\directlua{require("combining_preprocessor.lua")}} \newcommand{\̂}[1]{\ensuremath{\hat{#1}}} \newcommand{\�}[1]{\ensuremath{\vec{#1}}} 711

\newcommand{\̱}[1]{\ensuremath{\underline{#1}}} \newcommand{\́}[1]{\ensuremath{\acute{#1}}} \usepackage{stackrel} \newcommand{\�}[1]{\ensuremath{\stackrel[\approx]{}{#1}}} \begin{document} Hello $�̂$ is hat on $�$, more on $�̂�$ (stress test) $�̂ x̂$ Many combining accents on $x�̱̂́�$ is cool. \end{document} (My browser doesn’t do the many combining characters justice here, but it looks nice in the PDF file.) Not sure if this is the ideal way of doing things, but for what it’s worth, here is combining_preprocessor.lua: Skip code block function minornil(a, b) if a == nil and b == nil then return nil elseif a == nil then return b elseif b == nil then return a else return math.min(a, b) end end function findfirstcombining(line, n) local a = string.find(line, "\204[\128-\191]", n) 712

-- From U0300,

local b = string.find(line, "\205[\128-\175]", n) -- to U036F. a = minornil(a, b) b = string.find(line, "\226\131[\144-\176]", n) -- U20D0 to U20F0 a = minornil(a, b) b = string.find(line, "\225\183[\128-\191]", n) -- U1DC0 to U1DFF a = minornil(a, b) return a end function is_utf8_continuation(byte) return byte < 191 and byte > 127 end function find_next_utf8_char(str, n) while str:byte(n) ~= nil and is_utf8_continuation(str:byte(n)) do n = n + 1 end return n end function combining_iter(str) local n = 0 return function () n = (n ~= nil) and findfirstcombining(str, n + 1) return n end end function dobuffer(line) local n1 = 0 local t = {} for n2 in combining_iter(line) do if n2 > n1 then local n3 = n2 repeat n3 = n3 - 1 until not is_utf8_continuation(line:byte(n3)) table.insert(t, string.sub(line, n1, n3 - 1)) 713

n1 = find_next_utf8_char(line, n2 + 1) local comb = {} table.insert(comb, "\\" .. string.sub(line, n2, n1 - 1) .. "{") table.insert(comb, string.sub(line, n3, n2 - 1) .. "}") n2 = findfirstcombining(line, n1) while n2 == n1 do n1 = find_next_utf8_char(line, n2 + 1) table.insert(comb, 1, "\\" .. line:sub(n2, n1 - 1) .. "{") table.insert(comb, "}") n2 = findfirstcombining(line, n1) end table.insert(t, table.concat(comb)) end end table.insert(t, string.sub(line, n1)) print(table.concat(t)) return table.concat(t) end luatexbase.add_to_callback("process_input_buffer", dobuffer, "combining_preprocessor", 1)

Answer by khaled-hosny unicode-math does not set \mathcode for Unicode accents the same it does with other Unicode characters like math italics, so TeX looks for them in the first math font which is Computer Modern Math Italic (cmmi10 in the log) which does not have the accents (not in the Unicode positions at least). But even if unicode-math did set the \mathcode the math accent will not be positioned properly (as you already noted), because accents must be called with \(U|XeTeX)mathaacent primitive for TeX to do its math accent positioning magic. It might be possible to make the accents active math characters and map them to the respective macros (unicode-math already does this sort of tricky to allow direct input of other Unicode characters), but this is left as an exercise to the reader (read: I don’t know how to do this and last time I 714

tried to understand that code I was on the verge of losing my sanity). The engine itself knows nothing about Unicode characters, it the responsibility of the user (or macro package writer) to tell it which character is to be treated as an accent or a big operator or an opening symbol etc. using the appropriate primitive and/or math code (otherwise things would be very inflexible).

Tags: unicode-math (Prev Q) (Next Q), unicode (Prev Q) (Next Q), mathmode (Prev Q) (Next Q)

Q: Spacing changes when using unicode-math range feature. Why? Tags: unicode-math (Prev Q) (Next Q), spacing (Prev Q) (Next Q) You can use the range feature of unicode-math to set the math font for a specific unicode slots or the macro accessing the glyph. I tried this with the sum sign & Latin Modern, see my example: Skip code block \documentclass{scrartcl} \usepackage{amsmath} \usepackage{unicode-math} % use unicode in math & setup math fonts \setmathfont{Asana Math} %\setmathfont[range=\sum]{Latin Modern Math} % substitute Sum sign \begin{document} Notice the different sum sign $\sum$, as intended. Notice also, the difference in spacing, not intended: \begin{equation} \begin{bmatrix} 0 & \frac{1}{2} & \frac{2}{3} \\ 715

\frac{3}{4} & 0 \frac{5}{6} & \frac{6}{7} \end{bmatrix} \begin{pmatrix} A \\ B \\ C \end{pmatrix} \end{equation} \end{document}

& \frac{4}{5} \\ & 0

However, not only the sum sign, but also the spacing in the matrices changes. With Latin Modern commented out (as in the example):

With

Latin Modern active (remove % before relevant line): is that? BTW, I’m using Lualatex from TeXLive 2012. Tags: unicode-math (Prev Q) (Next Q), spacing (Prev Q) (Next Q) User: psirus

716

Answer by khaled-hosny LuaTeX takes global math constants from the last defined font (I’m not yet sure if this can be considered a bug or a feature). A simple workaround is to call Asana Math again with an empty range (calling it without a range will undo previous font calls): Skip code block \usepackage{amsmath} \usepackage{unicode-math} % use unicode in math & setup math fonts \setmathfont{Asana Math} \setmathfont[range=\sum]{Latin Modern Math} % substitute Sum sign \setmathfont[range={}]{Asana Math} \begin{document} Notice the different sum sign $\sum$, as intended. Notice also, the difference in spacing, not intended: \begin{equation} \begin{bmatrix} 0 & \frac{1}{2} & \frac{2}{3} \\ \frac{3}{4} & 0 & \frac{4}{5} \\ \frac{5}{6} & \frac{6}{7} & 0 \end{bmatrix} \begin{pmatrix} A \\ B \\ C \end{pmatrix} \end{equation} \end{document}

Tags: unicode-math (Prev Q) (Next Q), spacing (Prev Q) (Next Q)

717

Q: How to use unicode-math with beamer and lualatex? Tags: unicode-math (Prev Q) (Next Q) According to a recent article in ”Die TeXnische Komödie”, this should be the way to get Latin Modern Math to work with lualatex and the latest TeXLive 2011: Skip code block \documentclass[professionalfonts]{beamer} \usepackage[english]{babel} \usepackage{iftex} \ifPDFTeX \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage{lmodern} \else \ifLuaTeX \usepackage{luatextra} \defaultfontfeatures{Ligatures=TeX,Numbers=OldStyle} \usepackage{unicode-math} \setmathfont{Latin Modern Math} \fi \fi \newcommand{\ip}[2]{(#1, #2)} \begin{document} \begin{frame}{Speaker's Name}{About Our Next Speaker} \LaTeX\ is good at typesetting mathematical formulas like \( x-3y + z = 7 \) or \( a_{1} > x^{2n} + y^{2n} > x' \) or \( \ip{A}{B} = \sum_{i} a_{i} b_{i} \). \end{frame} \end{document} It works (at least according to pdffonts), but unicode-math complains:

718

* unicode-math warning: "disable-beamer" * * Disabling beamer's math setup. * Please load beamer with the [professionalfonts] class option. And this message is repeated a dozen times: * * * * *

fontspec warning: "icu-feature-not-exist-in-font" OpenType feature 'Numbers=OldStyle' (+onum) not available for font 'LatinModernMath', with script 'Math', and language 'Default'.

What’s wrong with my setup? EDIT: The fontspec warnings go away if one removes the Numbers=OldStyle from the \defaultfontfeatures. EDIT2: I removed the ifxetex package and changed the \ifluatex to \ifLuaTeX. Tags: unicode-math (Prev Q) (Next Q) User: martin-schröder

Answer by loop-space Regarding the first message, there is a beamer class option professionalfont which sets an \if, specifically \[email protected] to decide whether beamer would handle some special font stuff or there was some other package to do it instead. unicode-math checks to see if that \if has been set to true and if not, it issues the warning and then sets it to true. So loading unicode-math ensures that that \if is set to true, but it might not be done as early as if you’d set the class option. However, if you do set the class option, then you will get the warning: ”professionalfont” is obsolete. Use font theme ”professionalfonts” instead There are two things to notice here. First is that the class option is not

719

professionalfonts (as unicode-math claims) but professionalfont. Second, that it is obsolete. Rather, you should issue the command: \usefonttheme{professionalfonts} somewhere in your preamble. What this does is: \mode{\[email protected]} so it sets the same \if but only in presentation mode. Thus it is ignored in article mode. Since the unicode-math test only checks for the class being beamer, and not for the beamerarticle package, this is consistent. Thus the correct preamble is: \documentclass{beamer} \usefonttheme{professionalfonts} \usepackage{unicode-math} Lastly, there should not be any actual problem if the middle line is missed since all it does is what unicode-math does when checking for the beamer class. Thus the actual effect of the middle line is to suppress the warning with the unicode-math package. (Andrew now goes off and changes the preamble of his presentations because he’d been getting that warning with the professionalfonts class option and not understanding why he got it.)

Answer by herbert Skip code block \documentclass[professionalfont]{beamer} \usepackage[english]{babel} \usepackage{iftex,ifxetex} \ifPDFTeX \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \usepackage{lmodern} \else \ifluatex \usepackage{unicode-math} 720

\defaultfontfeatures{Ligatures=TeX,Numbers=OldStyle} \setmathfont{Latin Modern Math} \setsansfont{Linux Biolinum O} \fi \fi \newcommand{\ip}[2]{(#1, #2)} \begin{document} \begin{frame}{Speaker's Name}{About Our Next Speaker} \LaTeX\ is good at typesetting mathematical formulas like \( x-3y + z = 7 \) or \( a_{1} > x^{2n} + y^{2n} > x' \) or \( \ip{A}{B} = \sum_{i} a_{i} b_{i} \). 012345 $012345$ ff ffl ffi \end{frame} \end{document}

Tags: unicode-math (Prev Q) (Next Q)

Q: pgfplots + unicode-math + ”kernel/command-already-defined”

lualatex

gives

the

Tags: unicode-math (Prev Q) (Next Q), pgfplots (Prev Q) (Next Q) With the following MWE compiled with lualatex, I get the error: ... LaTeX error: "kernel/command-already-defined" Control sequence \crampeddisplaystyle already defined. ... l.637 \um_new_cramped_style:N \crampeddisplaystyle 721

error

and the same error for \crampedtextstyle, \crampedscriptstyle, and \crampedscriptscriptstyle. Switching the loading order of pgfplots and unicode-math fixes the problem, as does compiling with xelatex. Prior to the most recent update of pgfplots (v1.12), this error was not present. How can I fix this error? \documentclass{article} \usepackage{pgfplots} \usepackage{unicode-math} \listfiles \pgfplotsset{compat=1.12} \begin{document} Test \end{document} Relevant listings from \listfiles: pgfplots.sty 2015/01/31 v1.12 Data Visualization (1.12) unicode-math.sty 2014/06/30 v0.7f Unicode maths in XeLaTeX and LuaLaTeX Tags: unicode-math (Prev Q) (Next Q), pgfplots (Prev Q) (Next Q) User: darthbith

Answer by christian-feuersänger Pgfplots unintionally defined additional unprefix forms of such macros. I have already fixed this in the developer version of pgfplots (thanks to the helpful remark of @DavidCarlisle). Switching the load order (unicode-math before pgfplots) is currently the most simple work-around (known to me).

Tags: unicode-math (Prev Q) (Next Q), pgfplots (Prev Q) (Next Q)

722

Q: Less vertical space in frac Tags: unicode-math (Prev Q) (Next Q), math-mode (Prev Q) (Next Q) I’m using unicode-math in lualatex with the Cambria Math fonts. Compared to Computer Modern math, there is too much vertical space between fractions. Is there a way I can achieve my adjustment without having to patch \frac? For example a fontspec or unicode-math option? i.e. I’m looking for an option to change the vertical space around the fraction bar. Edit: added xfrac case and +frac, +numr/+dnom. +frac just +sups all digits. Custom xfrac only works in math mode when enclosing the arguments in \text{19} but not with \text{#1}?!. LuaTeX-0.70.2, Cambria 5.96 Skip code block \documentclass{article} \usepackage{fontspec} \usepackage{xfrac} \usepackage{unicode-math} \setmathfont{Cambria Math} \setmainfont{Cambria} \newcommand{\otfrac}[2]{% \frac% {\raisebox{-.1em}{\scriptsize $#1$}}% {\raisebox{.15em}{\scriptsize $#2$}}% } \newcommand{\ofrac}[2]{% \text{% {\addfontfeature{VerticalPosition=Numerator}#1}% \divslash{}% {\addfontfeature{VerticalPosition=Denominator}#2} }% } 723

\begin{document} % tfracs look weird: \noindent here is a first ygygyg line of text\\ bit too large: $\frac{19}{30}$. $\otfrac{19}{30}$ better?\\ here is anothÁÁÁÁÁÁ line of text\\[.5em] % % default sfrac looks weirder: default sfrac text \sfrac{19}{30} math $\sfrac{19}{30}$\\ % % customising helps some: \DeclareInstance{xfrac}{default}{text}{ numerator-top-sep = -.1ex, denominator-bot-sep = -.1ex, slash-symbol=\divslash, } \DeclareCollectionInstance{plainmath}{xfrac}{mathdefault}{math}{ numerator-top-sep = -.2ex, denominator-bot-sep = -.1ex, scale-factor = 0.8333, scale-relative = true, slash-right-mkern = -0mu, slash-left-mkern = -0mu, slash-symbol=\text{\divslash} } \UseCollection{xfrac}{plainmath} custom sfrac text \sfrac{19}{30} math $\sfrac{19}{30}$\\ % % +frac feature just superscripts all digits {\addfontfeature{Fractions=On} +frac 19/30, bad: 24. } +numr/+dnom: \ofrac{19}{30} \\ % % customize sfrac this way: \DeclareInstance{xfrac}{default}{text}{ numerator-bot-sep = 0pt, denominator-bot-sep = 0pt, scaling = false, slash-symbol=\divslash, numerator-format={\addfontfeature{VerticalPosition=Numerator}#1}, denominator-format={\addfontfeature{VerticalPosition=Denominator}#1}, 724

} \ExplSyntaxOn \DeclareCollectionInstance{plainmath}{xfrac}{mathdefault}{math}{ numerator-top-sep = \c_max_dim, numerator-bot-sep = 0pt, denominator-bot-sep = 0pt, scaling = false, slash-right-mkern = 0mu, slash-left-mkern = 0mu, slash-symbol=\text{\divslash}, %------------------vvvv-- or no \text{}, doesn't matter. numerator-format={\text{\addfontfeature{VerticalPosition=Numerator}#1}}, denominator-format={\text{\addfontfeature{VerticalPosition=Denominator}#1}}, } \ExplSyntaxOff \UseCollection{xfrac}{plainmath} % nice otf custom sfrac text \sfrac{19}{30} % what?! math $\sfrac{19}{30}, \sfrac{\text{19}}{\text{30}}$\\ \end{document}

I’m not using \sfrac with anything other than digits as arguments anyway so I’ll use this instead for consistency, but a way to modify \tfrac would 725

still be interesting, or is \tfrac = \otfrac the best way? Tags: unicode-math (Prev Q) (Next Q), math-mode (Prev Q) (Next Q) User: pascal

Answer by philipp The positioning of numerators and denominators is controlled by a font parameter that can easily be modified in LuaLaTeX: Skip code block

\documentclass[pagesize=auto, version=last]{scrartcl} \usepackage{fontspec} \usepackage{unicode-math} \usepackage{luacode} \usepackage{luatexbase-mcb} \setmathfont{Cambria Math} \setmainfont{Cambria} \begin{luacode*} local function patch_cambria_frac(fontdata) if fontdata.psname == "CambriaMath" then local mc = fontdata.MathConstants mc.FractionNumeratorShiftUp = 0.4 * mc.FractionNumeratorShiftUp mc.FractionDenominatorShiftDown = 0.4 * mc.FractionDenominatorShiftDown end end luatexbase.add_to_callback("luaotfload.patch_font", patch_cambria_frac, "cambria \end{luacode*} \begin{document} $\frac{19}{30}$ \end{document}

Answer by qrrbrbirlbel Maybe this does help you \usepackage{amsmath} % load before unicode-math 726

\def\superfrac#1#2{\raisebox{.3ex}{\ensuremath{\genfrac{}{}{}2{#1}{#2}}}} In the document you can use it as \superfrac{19}{30}. The vertical alignment (.3ex) may need to be adjusted. The 2 denotes the scriptstyle. Todd Lehmann has created some interesting macros: Improved kerning in fractions?

Tags: unicode-math (Prev Q) (Next Q), math-mode (Prev Q) (Next Q)

Q: Invisible math characters with unicode-math and ntheorem Tags: unicode-math (Prev Q) (Next Q) When compiling this code with lualaTeX (from TeXLive 2011), Skip code block \documentclass{minimal} \usepackage{unicode-math} \usepackage{ntheorem,thmtools} \setmathfont{xits-math} \makeatletter \newtheoremstyle{mathfonttest} {\item[\[email protected] $ABC$ DEF $:!?$ ]} % 1. option {\item[$ABC$ DEF ]} % 2. option \makeatother \declaretheorem[style=mathfonttest]{test} \begin{document} \begin{test} % 1. option, ABC invisible Something. \end{test} \begin{test}[triggers 2. option] % 2. option, ABC visible Something. 727

\end{test} \end{document} the first ABC, and more generally any greek or latin character in inline math mode – when preceded by \[email protected] – is invisible and I have no clue why. What I want to do is use math code in optional or alternative description to a definition like ’1.1. Definition (of $pi$)’. Does anybody know how to solve this or circumvent it? Tags: unicode-math (Prev Q) (Next Q) User: k.stm

Answer by egreg The problem is that \[email protected] calls \[email protected] and this macro does \if b\expandafter\@car\[email protected]\@nil\boldmath\fi This is the reason for the disappearance: the font used is boldface and this causes \boldmath to come into action but XITS Math has no bold version. If you want to use ntheorem and math in the theorem labels, then you need to use a non boldface font. The most recent TeX distributions (TeX Live 2012) should have a bold version of XITS Math, so you can try updating yours.

Tags: unicode-math (Prev Q) (Next Q)

Q: Unicode math with amsmath, new error Tags: unicode-math (Prev Q) (Next Q) After applying the most recent ctan updates, the following MWE does not compile with lualuatex. There is an error given ending 728

with \cs_set_nopar:Npx that I can’t make sense of. \documentclass{article} \usepackage{amsmath} \usepackage{unicode-math} \begin{document} test \end{document} any ideas on how to work around this? Tags: unicode-math (Prev Q) (Next Q) User: grizzilus

Answer by joseph-wright Known issue, which can be tracked back via unicode-math to lualatex-math. This is fixed in the development tree for lualatex-math, and is on its way to CTAN so should be in TeX Live/MiKTeX soon. If really urgent, grab the fixed lualatex-math.

Tags: unicode-math (Prev Q) (Next Q)

Q: Arrow length in LuaTeX in combination with the unicode-math package Tags: unicode-math (Prev Q) (Next Q) I have a probably rather simple question: Is it possible to use the unicode-math package within LuaLaTeX such that arrows stretch when writing some longer expression above or below it? For example the following code with the package unicode-math loaded doesn’t produce stretched arrows and the text over the arrow is much longer 729

than the arrow itself: Skip code block % TeX engine: LuaLaTeX % TeX Live 2014 % TeX encoding = UTF-8 \documentclass{minimal} \usepackage{amsmath, unicode-math} \begin{document} $a \xrightarrow{b \to \infty} c$ \end{document} Tags: unicode-math (Prev Q) (Next Q) User: bfc

Answer by egreg I’d consider this a bug both in unicode-math, which should provide a good equivalent of \[email protected] when amsmath is loaded and of Latin Modern Math, that doesn’t provide a glyph for \harrowextender (U+23AF HORIZONTAL LINE EXTENSION). See the related question Why fontspec breaks extarrows package For your problem, you can do Skip code block \documentclass{article} \usepackage{amsmath,unicode-math} \makeatletter \AtBeginDocument{\Umathcharnumdef\[email protected]\Umathcodenum`- }% \[email protected] is minus \makeatother \begin{document} 730

$a \xrightarrow{b \to \infty} c$ \end{document} A better workaround should use \harrowextender when available: Skip code block \documentclass{article} \usepackage{amsmath,unicode-math} %\setmathfont{Asana Math} % if uncommented, \harrowextender would be used \makeatletter \AtBeginDocument{% \[email protected] \iffontchar\textfont\[email protected]\string"23AF \renewcommand{\relbar}{\mathrel\harrowextender}% \else \Umathcharnumdef\[email protected]\Umathcodenum`\fi} \makeatother \begin{document} $a \xrightarrow{b \to \infty} c$ \end{document}

The second code uses \[email protected] to ensure fonts are associated to 731

the math families (LaTeX normally doesn’t do this until the first formula is being typeset in order to avoid using up math families that couldn’t be unused in the document). With unicode-math, the math font defined by \setmathfont is associated to math family 2, so we check whether the character corresponding to \harrowextender exists in the font (see the e-TeX manual, texdoc etex for \iffontchar). If the character exists, we redefine \relbar to be that symbol as math relation. Otherwise, we resort to using a minus sign, under the name \[email protected] that’s used by amsmath in this context. What happens without the code is that \[email protected] becomes “choose character 0 in math family 2“, which is correct for the traditional TeX math fonts, but is not true any more for unicode-math. So in this case we redefine \[email protected] to be a math char having the same code as the minus sign (see the XeTeX manual, texdoc xetex, for more information about \Umath... commands).

Tags: unicode-math (Prev Q) (Next Q)

Q: How can I change math font with \setmathfont inside a group? Tags: unicode-math (Prev Q) (Next Q) Consider the following test file and compile it with LuaTeX (TeXLive 2016): Skip code block \documentclass{article} \usepackage[math-style = TeX]{unicode-math} \setmainfont{texgyretermes}[ Extension = .otf, UprightFont = *-regular, BoldFont = *-bold, ItalicFont = *-italic, BoldItalicFont = *-bolditalic, 732

] \setsansfont{texgyreadventor}[ Extension = .otf, UprightFont = *-regular, BoldFont = *-bold, ItalicFont = *-italic, BoldItalicFont = *-bolditalic, ] \setmathfont{Latin Modern Math} \begin{document} \begin{equation} \int_{t = 0}^{x^2} t dt \end{equation} \setmathfont[range=up/{greek,Greek,latin,Latin,num}]{texgyreadventor-regular} \setmathfont[range=it/{greek,Greek,latin,Latin,num}]{texgyreadventor-italic} \setmathfont[range = {}]{Latin Modern Math} \begin{equation} \int_{t = 0}^{x^2} t dt \end{equation} \setmathfont{Latin Modern Math} \begin{equation} \int_{t = 0}^{x^2} t dt \end{equation} % { % \setmathfont[range=up/{greek,Greek,latin,Latin,num}]{texgyreadventor-regular} % \setmathfont[range=it/{greek,Greek,latin,Latin,num}]{texgyreadventor-italic} % \setmathfont[range = {}]{Latin Modern Math} %

\begin{equation} 733

% \int_{t = 0}^{x^2} t dt % \end{equation} % } \end{document} If I uncomment the last lines, LuaTeX hangs forever. How can I change math font inside a group?

EDIT I’m well aware that I should not use a non math font to do math but, unfortunately, a sans serif math font does not yet exist, AFAIK. The problem does not appear to be linked with the fact that I use a non math font. Skip code block \documentclass{article} \usepackage[math-style = TeX]{unicode-math} \setmathfont{Latin Modern Math} \begin{document} \begin{equation} \int_{t = 0}^{x^2} t dt \end{equation} \setmathfont{Asana-Math} \begin{equation} \int_{t = 0}^{x^2} t dt \end{equation} \setmathfont{Latin Modern Math} \begin{equation} 734

\int_{t = 0}^{x^2} t dt \end{equation}

% { % \setmathfont{Asana-Math} % \begin{equation} % \int_{t = 0}^{x^2} t dt % \end{equation} % }

\end{document} However, as @cfr suggested, I should use \mathversion: the following works. Skip code block \documentclass{article} \usepackage[math-style = TeX]{unicode-math} \setmathfont[version=lm]{Latin Modern Math} \setmathfont[version=asana]{Asana-Math} \mathversion{lm} \begin{document} \begin{equation} \int_{t = 0}^{x^2} t dt \end{equation} \mathversion{asana} \begin{equation} \int_{t = 0}^{x^2} t dt \end{equation}

735

\mathversion{lm} \begin{equation} \int_{t = 0}^{x^2} t dt \end{equation}

{ \mathversion{asana} \begin{equation} \int_{t = 0}^{x^2} t dt \end{equation} } \end{document} Tags: unicode-math (Prev Q) (Next Q) User: cjorssen

Answer by cfr There are really two problems here. The first is that unicode-math really wants opentype fonts with a proper math table. It only works with fonts lacking this at all, as I understand it, because the configuration falls through to setting the applicable range to up, despite the font lacking anything which usually enables the setting of ranges etc. The usual way to set an alternative set of maths fonts is to declare an alternative maths version e.g. bold versus normal. unicode-math supports this. This basically works, as your example shows. However, the second problem is that it seems to be impossible to combine the use of range with version. Setting a range affects all maths versions rather than just the specified one, as I demonstrate in this question.

736

Tags: unicode-math (Prev Q) (Next Q)

Q: How can I avoid that a functions argument touches the brackets using unicode-math? Tags: unicode-math (Prev Q), miktex (Prev Q) (Next Q), spacing (Prev Q) (Next Q) Maybe, I am doing something wrong, but please have a look on the alignment in this formula: Skip code block % arara: lualatex \documentclass{article} \usepackage{mathtools} \usepackage[% ,math-style=ISO ]{unicode-math} \begin{document} $f(T)= T\cdot \dots$ \end{document}

That’s not very beautiful. The ”T” headnuts the right bracket and there is a lot of free space below the T (the brackets are too low). I could add some \, or similar, but I guess, I just don’t know how to set a function.

737

Edit: The compilation with XeLaTeX works fine. But I need it with LuaLaTeX. The Lua-version is: ”LuaTeX, Version beta-0.76.0-2013062820 (rev 4627)” I am getting a lot of luaotfload | load : auto-selecting default features for script: dflt luaotfload | load : path lookup of "latinmodern-math.otf" unsuccessful, falling back to file: in my main.log Tags: unicode-math (Prev Q), miktex (Prev Q) (Next Q), spacing (Prev Q) (Next Q) User: larifari

Answer by ulrike-fischer The file luatex-unicode-letters.tex differs between TL2013 and MiKTeX. The TL version deactivates (comments) all entries from \l 1D400 to \l 1D7CB and contains the comment: % XXX: luatex math italic correction bug % http://www.tug.org/pipermail/tex-live/2011-October/030295.html This sound as if there is a bug in LuaTeX and Tex Live has implemented a workaround by not setting some catcodes. If I copy the luatex-unicode-letters.tex to MiKTeX, update the FNDB and recreate the LuaLaTeX format the spacing is correct in MiKTeX too.

Tags: unicode-math (Prev Q), miktex (Prev Q) (Next Q), spacing (Prev Q) (Next Q)

OpenType Skip to questions,

738

Wiki by user peter-jansson OpenType is a development of TrueType through a collaboration between Microsoft and Adobe Systems. OpenType has become the standard for most platforms due to its cross-platform font files. OpenType is a free open standard. OpenType accommodates Unicode character encodings and up to 65536 glyphs.

Questions Q: How can I enable italic correction for LuaTeX? Tags: opentype (Prev Q) (Next Q), math-mode (Prev Q) (Next Q) LuaTeX ignores mathematical italic correction by default, as noted by Khaled Hosny. This leads to some awful errors when using some alphabet which is very slanted, like XITS’ mathematical script glyphs. For example, both $^*$ and $[�]$ result in intersecting glyphs. (As a side note, ConTeXt renders both correctly, while XeLaTeX renders the first correctly but not the second). Khaled did propose a workaround, but since it involves rebuilding the format, I’m not interested. Also, I can’t wait for the bugfix to happen (I have a thesis to deliver). So, is there a workaround that only involves some code in the preamble? A solution for XeLaTeX would also be valuable for me, since it’s very easy to switch to it (although I’d prefer to use LuaLaTeX). Tags: opentype (Prev Q) (Next Q), math-mode (Prev Q) (Next Q) User: mateus-araújo

Answer by george-nurser If you are using AMSLaTeX, then, following Vafa Khalighi’s email at http: //tug.org/pipermail/tex-live/2011-October/030337.html you seem to need to 739

do (1):

\everymath\expandafter{\the \everymath \luatexcatcodetable\CatcodeTableLaTeX} \everydisplay\expandafter{\the\everydisplay \luatexcatcodetable\CatcodeTableLaTeX} instead of simply (2) \everymath{\luatexcatcodetable\CatcodeTableLaTeX} \everydisplay{\luatexcatcodetable\CatcodeTableLaTeX} I myself found on a big book with a lot of AMSLaTeX that LuaLaTeX gave errors with (2) but worked fine with (1).

Answer by khaled-hosny Incidentally I was thinking about less invasive solution last night and it occurred to me using LuaTeX’s catcode tables might help. The code below will reset catcodes to the ”standard” LaTeX catcode table (whatever that means) inside math mode, I don’t know what side effects this might have (hopefully none). Skip code block \documentclass{article} \usepackage{unicode-math} \setmathfont{XITS Math} \everymath{\luatexcatcodetable\CatcodeTableLaTeX} \everydisplay{\luatexcatcodetable\CatcodeTableLaTeX} \begin{document} $^*$ \quad $[�]$ \end{document} A better solution would involve saving the current catcode table, switching to \CatcodeTableLaTeX using \everymath and then switching back to the saved catcode table after math (but there seem not to be an ”every after math” hook, so I’ve no idea how to do that), to localise the effect of switching catcode tables. Update: thanks to egreg’s comment below, it seems switching catcode table inside \everymath is already localised to math mode.

740

Tags: opentype (Prev Q) (Next Q), math-mode (Prev Q) (Next Q)

Q: lualatex: smallcaps and microtype don’t work together Tags: opentype (Prev Q) (Next Q), microtype (Prev Q) (Next Q) Compiling the following MWE with lualatex doesn’t produce small caps. There are no font warnings. Skip code block \documentclass{article} \usepackage{fontspec} \newfontfeature{Microtype}{protrusion=default, expansion=default} \defaultfontfeatures{Microtype} \setmainfont{Linux Libertine O} \begin{document} \textsc{foo} {\scshape bar} \end{document} Doing one of the following fixes this: • Don’t add Microtype to fontfeatures • compile with xelatex The system is a frozen TL 2011 on Archlinux. Tags: opentype (Prev Q) (Next Q), microtype (Prev Q) (Next Q) User: t-8ch

741

Answer by jörg You have a small error in your Microtype syntax. Change: \newfontfeature{Microtype}{protrusion=default, expansion=default}% comma to: \newfontfeature{Microtype}{protrusion=default;expansion=default}% semicolon Edit: If you want to use Linux Libertine consider the libertineotf package.

Tags: opentype (Prev Q) (Next Q), microtype (Prev Q) (Next Q)

Q: OpenType fonts for Metapost Labels Tags: opentype (Prev Q) (Next Q), metapost (Next Q) Is it possible to use OpenType fonts in MetaPost labels? I use MiKTeX 2.9. I hoped something like mpost --tex=dvilualatex .mp might work, but no luck. Suggestions? I tried this, but I get an empty box where my label should be, even if I use the default fonts. Skip code block \startMPdefinitions \stopMPdefinitions

\starttext \startMPpage beginfig(1); draw(0, 0)--(200,200); 742

dotlabel.bot("ABCDEFG", (100,100)); endfig; \stopMPpage \stoptext Tags: opentype (Prev Q) (Next Q), metapost (Next Q) User: colin-fraizer

Answer by aditya If you don’t mind using ConTeXt to generate your metapost figures you can just use: Skip code block % ConTeXt font setup. This is similar to fontspec % \usemodule[simplefonts] % \setmainfont[Pagella] \startMPdefinitions % Common MP code for all figures \stopMPdefinitions \starttext \startMPpage % MP figure. Text enclosed in btex ... etex is parsed using ConTeXt \stopMPpage ... \startMPpage ... \stopMPpage \stoptext And then compile it using context filename. PS: I am not sure what is the current status of ConTeXt on MikTeX. If MikTeX does not include ConTeXt, you could just install ConTeXt standalone (in a parallel tree) which is about 250MB. 743

Tags: opentype (Prev Q) (Next Q), metapost (Next Q)

Q: Asymptote with lualatex and otf fonts Tags: opentype (Prev Q) (Next Q) Consider the following simple asymptote file: Skip code block import settings; import three; settings.tex = 'lualatex'; settings.outformat = 'pdf'; texpreamble("\usepackage{luatex85} \usepackage[math-style = TeX]{unicode-math}"); draw('$x$', O -- X); draw('$y$', O -- Y); draw('$z$', O -- Z); asy crashes. Here is an slightly edited output of asy -vv t.asy: Skip code block Using configuration directory /home/christophe/.asy Using history /home/christophe/.asy/history Welcome to Asymptote version 2.38 cd /tmp Processing t Loading plain from /usr/share/asymptote/plain.asy [...] lualatex \scrollmode lualatex -output-format=dvi \nonstopmode\input t_.tex This is LuaTeX, Version 0.95.0 (TeX Live 2016) 744

restricted system commands enabled. LaTeX2e patch level 3 Babel and hyphenation patterns for 1 language(s) loaded. (./t_.tex (/usr/local/texlive/2016/texmf-dist/tex/latex/base/article.cls Document Class: article 2014/09/29 v1.4h Standard LaTeX document class (/usr/local/texlive/2016/texmf-dist/tex/latex/base/size12.clo)) (/usr/local/texlive/2016/texmf-dist/tex/generic/luatex85/luatex85.sty) (/usr/local/texlive/2016/texmf-dist/tex/latex/unicode-math/unicode-math.sty (/usr/local/texlive/2016/texmf-dist/tex/generic/ifxetex/ifxetex.sty) (/usr/local/texlive/2016/texmf-dist/tex/generic/oberdiek/ifluatex.sty) (/usr/local/texlive/2016/texmf-dist/tex/latex/l3kernel/expl3.sty (/usr/local/texlive/2016/texmf-dist/tex/latex/l3kernel/expl3-code.tex) (/usr/local/texlive/2016/texmf-dist/tex/latex/l3kernel/l3dvips.def)) (/usr/local/texlive/2016/texmf-dist/tex/latex/ucharcat/ucharcat.sty) (/usr/local/texlive/2016/texmf-dist/tex/latex/l3packages/xparse/xparse.sty) (/usr/local/texlive/2016/texmf-dist/tex/latex/l3packages/l3keys2e/l3keys2e.sty) (/usr/local/texlive/2016/texmf-dist/tex/latex/fontspec/fontspec.sty (/usr/local/texlive/2016/texmf-dist/tex/luatex/luaotfload/luaotfload.sty(using write cache: /home/christophe/.texlive2016/texmf-var/luatex-cache/generic)(usin g read cache: /usr/local/texlive/2016/texmf-var/luatex-cache/generic /home/chri stophe/.texlive2016/texmf-var/luatex-cache/generic) luaotfload | main : initialization completed in 0.090 seconds) (/usr/local/texlive/2016/texmf-dist/tex/latex/fontspec/fontspec-luatex.sty (/usr/local/texlive/2016/texmf-dist/tex/latex/base/fontenc.sty (/usr/local/texlive/2016/texmf-dist/tex/latex/euenc/eu2enc.def) (/usr/local/texlive/2016/texmf-dist/tex/latex/euenc/eu2lmr.fd)(compiling luc: / usr/local/texlive/2016/texmf-var/luatex-cache/generic/fonts/otl/lmroman10-regul ar.luc)(load luc: /home/christophe/.texlive2016/texmf-var/luatex-cache/generic/ fonts/otl/lmroman10-regular.luc))(compiling luc: /usr/local/texlive/2016/texmfvar/luatex-cache/generic/fonts/otl/lmroman12-regular.luc)(load luc: /home/chris tophe/.texlive2016/texmf-var/luatex-cache/generic/fonts/otl/lmroman12-regular.l uc) (/usr/local/texlive/2016/texmf-dist/tex/xelatex/xunicode/xunicode.sty (/usr/local/texlive/2016/texmf-dist/tex/latex/tipa/t3enc.def(compiling luc: /us r/local/texlive/2016/texmf-var/luatex-cache/generic/fonts/otl/lmromanslant12-re gular.luc)(load luc: /home/christophe/.texlive2016/texmf-var/luatex-cache/gener ic/fonts/otl/lmromanslant12-regular.luc)(compiling luc: /usr/local/texlive/2016 /texmf-var/luatex-cache/generic/fonts/otl/lmroman12-italic.luc)(load luc: /home 745

/christophe/.texlive2016/texmf-var/luatex-cache/generic/fonts/otl/lmroman12-ita lic.luc)(compiling luc: /usr/local/texlive/2016/texmf-var/luatex-cache/generic/ fonts/otl/lmroman12-bold.luc)(load luc: /home/christophe/.texlive2016/texmf-var /luatex-cache/generic/fonts/otl/lmroman12-bold.luc) (/usr/local/texlive/2016/texmf-dist/tex/latex/euenc/eu2lmss.fd)(compiling luc: /usr/local/texlive/2016/texmf-var/luatex-cache/generic/fonts/otl/lmsans12-regul ar.luc)(load luc: /home/christophe/.texlive2016/texmf-var/luatex-cache/generic/ fonts/otl/lmsans12-regular.luc)) (/usr/local/texlive/2016/texmf-dist/tex/latex/graphics/graphicx.sty (/usr/local/texlive/2016/texmf-dist/tex/latex/graphics/keyval.sty) (/usr/local/texlive/2016/texmf-dist/tex/latex/graphics/graphics.sty (/usr/local/texlive/2016/texmf-dist/tex/latex/graphics/trig.sty) (/usr/local/texlive/2016/texmf-dist/tex/latex/graphics-cfg/graphics.cfg) (/usr/local/texlive/2016/texmf-dist/tex/latex/graphics-def/dvips.def)))) (/usr/local/texlive/2016/texmf-dist/tex/latex/fontspec/fontspec.cfg))) (/usr/local/texlive/2016/texmf-dist/tex/latex/base/fix-cm.sty (/usr/local/texlive/2016/texmf-dist/tex/latex/base/ts1enc.def)) (/usr/local/texlive/2016/texmf-dist/tex/latex/filehook/filehook.sty) (/usr/local/texlive/2016/texmf-dist/tex/latex/unicode-math/unicode-math-luatex. sty (/usr/local/texlive/2016/texmf-dist/tex/lualatex/lualatex-math/lualatex-math.st y (/usr/local/texlive/2016/texmf-dist/tex/latex/etoolbox/etoolbox.sty)) (/usr/local/texlive/2016/texmf-dist/tex/latex/unicode-math/unicode-math-table.t ex))) No file t_.aux. (/usr/local/texlive/2016/texmf-dist/tex/latex/tipa/t3cmr.fd)(compiling luc: /us r/local/texlive/2016/texmf-var/luatex-cache/generic/fonts/otl/latinmodern-math. luc)(load luc: /home/christophe/.texlive2016/texmf-var/luatex-cache/generic/fon ts/otl/latinmodern-math.luc) [1] [2] [3] (./t_.aux)) 401 words of node memory still in use: 3 hlist, 1 vlist, 1 rule, 7 glue, 4 attribute, 45 glue_spec, 4 attribute_lis t, 1 write nodes avail lists: 1:1,2:31,3:8,4:2,5:10,6:2,7:22,8:1,9:6 Output written on t_.dvi (3 pages, 2408 bytes). Transcript written on t_.log. dvips -R -Pdownload35 -D600 -q -ot_.ps t_.dvi kpathsea:make_tex: Invalid fontname `[latinmodern-math]:mode=base;script=math;lang dvips: Font [latinmodern-math]:mode=base;script=math;language=DFLT; not found; usi 746

dvips: ! invalid char 119909 from font [latinmodern-math]:mode=base;script=math;la gs -q -dBATCH -P -dSAFER -sDEVICE=eps2write -sOutputFile=/dev/null t_.ps GPL Ghostscript 9.20: Unrecoverable error, exit code 1 I have to stop the process with Ctrl-C. This seems to be related with otf fonts. Is this a bug of asymptote, luatex, dvips, fontspec? Any idea for a workaround? Tags: opentype (Prev Q) (Next Q) User: cjorssen

Answer by cjorssen Thanks to John Bowman, the issue is now fixed in asymptote source code. By the way, the \usepackage{luatex85} does not seem to be mandatory anymore.

Tags: opentype (Prev Q) (Next Q)

Q: LuaLaTeX OpenType style sets by 4-character style set code Tags: opentype (Prev Q) This is partially answered by other questions which the TeX search found for me, but not in a comprehensive manner. I am a writer, not a mathematican or academic. I write fiction. So, my needs are only a subset of what TeX has to offer. I’ve already mastered what I need to know with pdfLaTeX and microtype. I can create and edit fonts, am licensed for a number of commerical fonts (such as Adobe Garamond Pro), and post-process the resulting PDF using Acrobat Pro. Until now, I decomposed OpenType fonts into Type 1 with LY1 encoding, so that pdfLaTeX could understand them. Different OpenType style sets were decomposed to different fonts, which I called separately, each time I needed 747

a particular style set. So far, so good. Understand that I do not use any of the TeX fonts, in any format. Now I am trying to use LuaLaTeX to directly read OpenType fonts. The nonworking features of microtype won’t be a problem, as the working features in LuaLaTeX suffice for my needs. I already have LuaLaTeX working with a simple, sample document that uses an OpenType font but not any OpenType features. I’ll be darned if I can figure out how to select OpenType features. I’ve looked through available docs, and online here, for examples. What I’ve seen are some code examples that select a feature by common name, rather than by the 4-character style set designation. Example: Numbers={OldStyle,Proportional}, But most style sets do not have a common name. So, what I do I do? I’m looking for something like this (pseudo-code): In the preamble: \newcommand\useThisStyleSet[3]{opentype font name}{4-character style code}{string \newcommand\myStyle[1]{\useThisStyleSet{Adobe Garamond Pro}{c2sc}{$1}} \newcommand\myOtherStyle[1]{\useThisStyleSet{Adobe Caslon Pro}{ss03}{$1}} \newcommand\myNextStyle[1]{\useThisStyleSet{Source Sans Pro}{loca}{$1}} In the document body: \myStyle{The quality} of mercy \myOtherStyle{is not} \myNextStyle{strained.} Tags: opentype (Prev Q) User: user103221

Answer by thérèse Here’s an updated version of the summary I made for myself when I began using fontspec.

748

Skip code block

| tag | fontspec option | comments |------+--------------------------------------+----------------------------------| abvm | Diacritics=[No]AboveBase | default | afrc | Fractions=Alternate | | anum | Numbers=Arabic | luatex only: see manual §10.3 | blvm | Diacritics=[No]BelowBase | default | c2pc | Letters=UppercasePetiteCaps | | c2sc | Letters=UppercaseSmallCaps | | calt | Contextuals=[No]Alternate | default in xetex, not in luatex | case | Letters=Uppercase | | clig | Ligatures=[No]Contextual | default | cpsp | Kerning=Uppercase | | cswh | Contextuals=[No]Swash | | cv01 | CharacterVariant=1 | see manual §10.8 | dlig | Ligatures=Rare/Discretionary | | dnom | VerticalPosition=Denominator | | expt | CJKShape=Expert | | falt | Contextuals=[No]LineFinal | | fina | Contextuals=[No]WordFinal | has sometimes worked in xetex | frac | Fractions=On[/Off] | | fwid | CharacterWidth=Full | for Asian fonts | halt | CharacterWidth=AlternateHalf | | hist | Style=Historic | | hkna | Style=HorizontalKana | | hlig | Ligatures=Historic | | hwid | CharacterWidth=Half | | init | Contextuals=[No]WordInitial | has sometimes worked in xetex | ital | Style=Italic | | jp78 | CJKShape=JIS1978 | | jp83 | CJKShape=JIS1983 | | jp90 | CJKShape=JIS1990 | | kern | Kerning=On[/Off] | default | liga | Ligatures=[No]Common | default | lnum | Numbers=Uppercase/Lining | | mark | Diacritics=[No]MarkToBase | default | medi | Contextuals=[No]Inner | has sometimes worked in xetex 749

| | | | | | | | | | | | | | | | | | | | | | | | | | | | | |

mkmk nalt nlck numr onum ordn palt pcap pnum pwid qwid rand rlig ruby salt sinf size smcp smpl ss01 subs sups swsh titl tnum trad twid unic vkna zero

| | | | | | | | | | | | | | | | | | | | | | | | | | | | | |

Diacritics=[No]MarkToMark Annotation=#… CJKShape=NLC VerticalPosition=Numerator Numbers=Lowercase/OldStyle VerticalPosition=Ordinal CharacterWidth=AlternateProportional Letters=PetiteCaps Numbers=Proportional CharacterWidth=Proportional CharacterWidth=Quarter Letters=Random Ligatures=[No]Required Style=Ruby Style=Alternate or Alternate=… VerticalPosition=ScientificInferior SizeFeatures={…} and OpticalSize=… Letters=SmallCaps CJKShape=Simplified StylisticSet=1 VerticalPosition=Inferior VerticalPosition=Superior Style=Swash Style=TitlingCaps Numbers=Monospaced CJKShape=Traditional CharacterWidth=Third Letters=Unicase Style=VerticalKana Numbers=[No]SlashedZero

| | | | | | | | | | | | | | | | | | | | | | | | | | | | | |

default see manual §10.14

default see manual §10.9

default for some fonts; see manual

see also realscripts package

(Ignore the color, which is this web site taking my ASCII table for .tex source.) Note that defaults may vary by script; see Khaled Hosny’s remarks at article.gmane.org/gmane.comp.tex.xetex/15187. To judge from the manual at §28.0.12, there are also vertical kerning options, probably to be explained in §10.17. 750

Tags: opentype (Prev Q)

Unicode Skip to questions, Wiki by user stefan-kottwitz unicode is for questions about Unicode (an international standard for character encoding) and its implementations. XeTeX and LuaTeX provide Unicode support, thus ConTeXt as well if using one of these engines. For LaTeX, the UTF-8 implementation is the most common, provided by the inputenc package: \usepackage[utf8]{inputenc} For questions about input encodings use input-encodings.

Questions Q: Migrating from pdfTeX to LuaTeX: Problems with reproducing output for legacy projects Tags: unicode (Prev Q) (Next Q) I’m currently analyzing and evaluating a migration process from pdfTeX to LuaTeX for our current TeX workflow. With LuaTeX being a fork of pdfTeX and packages like luainputenc at hand it seemed promising to reproduce pdfTeX’s output using LuaTeX when sacrificing (some or most of) LuaTeX’s new features. Currently, however, I’m stuck and need your help to decide whether it’s worth digging deeper or accepting what I found out. There are two problems I’m facing. 751

Here’s the first problem. Engines: pdfTeX 3.1415926-2.4-1.40.13 and LuaTeX beta-0.70.2-2012052410 (both from TeX Live 2012) with --output-format=pdf. When using UTF-8 input ([utf8x]{inputenc} for pdfTeX, [utf8x]{luainputenc} for LuaTeX) and T1 encoded fonts ([T1]{fontenc}) the output from both engines differs for some non-T1 characters. MWE: Skip code block \documentclass{article} \usepackage[utf8x]{luainputenc} \usepackage[T1]{fontenc} \renewcommand{\rmdefault}{lmr} \begin{document} \begin{tabular}{@{}l*{10}{p{7mm}@{}}} Some T1 characters: & \# & \$ & \% & Ă & Ň & § & @ & Æ & ß & £ \\[1.5mm] Some non-T1 characters: & ‡ & ÿ & ‰ & … & ¶ & ½ & ĩ & µ & | | & | | \\ \end{tabular} \end{document} Notes: luainputenc is forwarding to inputenc if called from pdfTeX. The output is the same when using an \ifluatex and loading inputenc and luainputenc separetely. The spaces between the bars in the last two columns of the second row are supposed to be a Unicode NO-BREAK SPACE (U+00A0) and a THIN SPACE (U+2009).

pdfTeX output: (everything fine here) LuaTeX output:

(notice the last five columns of the second row)

This problem does most certainly exist for other characters as well, these are 752

just some I encountered. Is there a way to get the pdfTeX output from LuaTeX? The problem is the same with different T1 encoded fonts, try mathpazo if you want. Using a different font encoding is not an option here as the task at hand is to migrate TeX engines, not fonts or their encodings. Am I perhaps missing a pdfTeX package that has to be replaced for LuaTeX usage? The lutf8x (notice the leading L) luainputenc package option does not help here either. (Which is no suprise as its purpose is different.) What I’m trying to use here, according to its manual, is the ”UTF-8 legacy mode” of luainputenc, i.e. mimicing the behavior of inputenc in pdfTeX by making non-ASCII characters active to determine the correct bit length of characters and so on. Maybe the problem is not the input side (afaik luainputenc’s job of translating input bytes into LICR) but the output side (afaik translating LICR into glyph positions of the font used)? Maybe LuaTeX is just translating to Unicode positions, not regarding glyph positions of the font, like the EU2 encoding? Anyway, where does the problem come from? Can it be helped and if so, how? Btw: It works fine with LuaTeX when using an OpenType-Font with fontspec and EU2 encoding, but that’s not the primary goal here.

And here’s the second problem. It’s closely tied to the first one and can be reproduced using the MWE above. When using --output-format=dvi pdfTeX is producing a DVI file that dvips has no problem with. When using a LuaTeX DVI file dvips stops with something like This is dvips(k) 5.992 Copyright 2012 Radical Eye Software (www.radicaleye.com) ' LuaTeX output 2012.08.01:1700' -> ohnexml-luatex.ps dvips: ! invalid char 297 from font ec-lmr10 This is how I actually came up with the suspicion that for the first problem Unicode positions and not font encoding specific glyph positions are written to the output file as 297 is the decimal Unicode point of ĩ (second row, fourth last column in the MWE above). 753

If a solution to the first problem does not solve this problem transitively, how can this one be helped? Thank you for your thoughts. Tags: unicode (Prev Q) (Next Q) User: patrick-bergner

Answer by ulrike-fischer At first you should imho better use utf8 instead of utf8x. utf8x is unmaintained and has problems e.g. with biblatex. (You will have to set up the some missing definitions for pdflatex). You will also have to add some definitions for lualatex as it will map - as you already found out - undeclared chars simply to their unicode position. Here e.g. two definitions for ½ & µ: Skip code block

\documentclass{article} \usepackage[utf8]{luainputenc} \usepackage[T1]{fontenc} \usepackage{textcomp} \renewcommand{\rmdefault}{lmr} \DeclareUnicodeCharacter{00BD}{\textonehalf} \DeclareUnicodeCharacter{00B5}{\textmu} \begin{document} \begin{tabular}{@{}l*{10}{p{7mm}@{}}} Some T1 characters: & \# & \$ & \% & Ă & Ň & § & @ & Æ & ß & £ \\[1.5mm] Some non-T1 characters: & ‡ & ÿ & ‰ & … & ¶ & ½ & µ %ĩ & & | | & | | \\ \end \end{document}

Tags: unicode (Prev Q) (Next Q)

754

Q: LuaLaTeX and hyperref ate my document (properties). How do I get them back? Tags: unicode (Prev Q) (Next Q), hyperref (Prev Q) (Next Q) I use hyperref for a number of reasons, but among other things it sets up the document properties up well. As long as I compile with XeLaTeX that is. As soon as I compile with LuaLaTeX, everything is a jumble. There are many more fields with issues in my real project, but here is an MWE using just the title field: Skip code block \documentclass{scrartcl} \usepackage{polyglossia} \setmainlanguage{turkish} \makeatletter \usepackage[hidelinks]{hyperref} \AtBeginDocument{% \hypersetup{% pdftitle = {\@title} } }{} \makeatother \title{RAB'BİN GÜNÜ} \begin{document} Title in document properties should match: RAB'BİN GÜNÜ \end{document} Compile with xelatex gives me: Title: RAB’BİN GÜNÜ But lualatex eats Unicode for lunch and has indigestion: Title: RAB’BÄ°N GÃœNÃœ How do I get proper Unicode characters into the document property fields when compiling with LuaLaTeX? Tags: unicode (Prev Q) (Next Q), hyperref (Prev Q) (Next Q)

755

User: caleb

Answer by egreg The indigestion is avoided by passing the unicode option to hyperref: Skip code block \documentclass{scrartcl} \usepackage{polyglossia} \setmainlanguage{turkish} \makeatletter \usepackage[hidelinks,unicode]{hyperref} \AtBeginDocument{% \hypersetup{% pdftitle = {\@title} } }{} \makeatother \title{RAB'BİN GÜNÜ} \begin{document} Title in document properties should match: RAB'BİN GÜNÜ \end{document}

756

Here’s the output of pdfinfo -enc UTF-8 test.pdf (only the relevant parts) LuaLaTeX Title: Subject: Keywords: Author: Creator: Producer: CreationDate: ModDate:

RAB'BİN GÜNÜ

LaTeX with hyperref package LuaTeX-0.79.1 Tue Mar 24 12:01:09 2015 Tue Mar 24 12:01:09 2015

XeLaTeX Title: Creator: Producer: CreationDate:

RAB'BİN GÜNÜ LaTeX with hyperref package xdvipdfmx (20140317) Tue Mar 24 11:58:05 2015

Answer by wipet The reason why the behavior differs when LuaTeX or XeTeX is used, is explained here. The XeTeX uses xdvipdfmx and this converter sets the UTF8 to UCS2 conversion automatically. On the other hand, when we are using direct pdfTeX primitives (like in LuaTeX) then the UTF8 to UCS2 conversion must be done at macro level. And the hyperref package does this when the mentioned unicode option is set.

Tags: unicode (Prev Q) (Next Q), hyperref (Prev Q) (Next Q)

757

Q: Write18: LuaTeX has an encoding problem, where XeLaTeX does not Tags: unicode (Prev Q) (Next Q), shell-escape (Prev Q) (Next Q) xelatex (with option --shell-escape) compiles this document fine: \documentclass{article} \usepackage{fontspec} \begin{document} LuaTeX is not \immediate\write18{echo uber | sed y/u/ü/ > inc.tex} % or: \directlua{os.execute("echo uber | sed y/u/ü/ > inc.tex")} \input{inc.tex}. \end{document} lualatex (with --shell-escape) returns this error: sed: -e expression #1, char 7: strings for `y' command are different lengths Obviously LuaLaTeX has an encoding problem and treats “ü” as two characters, where XeLaTeX gets things fine. Is there any workaround? Tags: unicode (Prev Q) (Next Q), shell-escape (Prev Q) (Next Q) User: berts

Answer by heiko-oberdiek LuaTeX resets the locale settings to C, the documentation says at the end of section ”3.2 LUA changes”: In stock LUA, many things depend on the current locale. In LUATEX, we can’t do that, because it makes documents unportable. While LUATEX is running if forces the following locale settings: LC_CTYPE=C LC_COLLATE=C LC_NUMERIC=C Then sed does not see an Unicode character, encoded as UTF-8, but two bytes. 758

In case of sed the setting LC_CTYPE=en_US.UTF-8 helps: \documentclass{article} \usepackage{fontspec} \begin{document} LuaTeX is not \immediate\write18{echo uber | env LC_CTYPE=en_US.UTF-8 sed y/u/ü/ > inc.tex} \input{inc.tex}. \end{document}

Tags: unicode (Prev Q) (Next Q), shell-escape (Prev Q) (Next Q)

Q: How to write infix macro/newcommand? Tags: unicode (Prev Q) (Next Q), macros (Prev Q) (Next Q) Is it possible to write a new command/macro in infix syntax instead of prefix syntax; especially I’d like to have this for $\frac{a}{b}$. I use LuaLaTeX and with \newunicodechar{�}{\overline} I can write �{blah} and this is expanded to \overline{blah}. Analogously I’d like to have $\frac{a}{b}$ to be something like {a}�{b} or a÷b which would be much more readable. Tags: unicode (Prev Q) (Next Q), macros (Prev Q) (Next Q) User: epsilonhalbe

Answer by boris TeX already has primitive \over; try ${a \over b}$.

Tags: unicode (Prev Q) (Next Q), macros (Prev Q) (Next Q)

759

Q: How to insert a specific unicode character (such as the ZWNJ symbol) into the text stream via lua code compiled by Lua(La)TeX? Tags: unicode (Prev Q), symbols (Prev Q) (Next Q) How does one instruct Lua(La)TeX -- specifically, the lua code invoked via a \directlua directive -- to insert a non-ASCII unicode symbol, such as a ”zero width non-joiner” symbol (code U+200C), into the text stream? I already know how to do this inside the body of a (Lua)LaTeX document -I’d type something like stuff\char"200C{}morestuff But how does one do this from inside lua code?

Addendum to (hopefully...) clarify what I’m trying to get done. If there’s a string in the input stream such as xyz123, I’d like to insert a specific character (this evil invisible ZWNJ character...) between xyz and 123, so that the input stream now is xyz123 I already have the code to (i) find all instances of xyz123 in the input stream and (ii) find the insertion point for the ZWNJ character inside the string xyz123. What I’m stuck with is trying to figure out how to insert the ZWNJ character (a ”node” in luatex speak? of what type?) at the insertion location. Tags: unicode (Prev Q), symbols (Prev Q) (Next Q) User: mico

Answer by michal.h21 In luatex, there is unicode library included. It acts as replacement for string library, so to print some unicode code point, you can use the char function: function unicode2utf(c) -- As parameter pass hexadecimal unicode code point return unicode.utf8.char(tonumber(c,16)) 760

end print(unicode2utf("038F")) This will print the omega symbol, as invisible space isn’t best character to test :)

Tags: unicode (Prev Q), symbols (Prev Q) (Next Q)

Ligatures Skip to questions, Wiki by user n.n. In writing and typography, a ligature occurs where two or more graphemes are joined as a single glyph. Ligatures usually replace consecutive characters sharing common components and are part of a more general class of glyphs called ”contextual forms”, where the specific shape of a letter depends on context such as surrounding letters or proximity to the end of a line.

Questions Q: Any suggestions/requests for features for a new package that allows disabling ligatures for (pre)selected words? Tags: ligatures (Prev Q) (Next Q) I’m starting to put together a LaTeX package, which I hope to distribute broadly, that • provides lualatex code to disable ligation of character pairs and triplets for selected words (globally within the document for all selected words, but not globally over all possible ligature instances); 761

• provides a pre-assembled list of English-language words for which TeX’s f-ligatures -- f-f, f-i, f-l, ff-i, and ff-l -- should be suppressed (note that there are seven ways that ligation suppression can occur: f-f, f-i, f-l, ff-i, ff-l, f-fi, and f-fl); • provides the proper kerning amounts, which can be quite different from zero, separately for each of the seven different ways of disabling ligation and for each of the following font families – Latin Modern, – selected font families of the tex-gyre font group, and – (possibly) selected other opentype font families as well for regular (upright), bold, italic, and bold-italic font shapes; • provides reasonably straightforward mechanisms for users to add additional words to the default list as well as to define their own ligation exception lists for ligature pairs and triplets not among TeX’s ”standard five” f-ligatures. Before going too far along in the process of creating this package, and risking having to start over more or less from scratch after releasing a first version of the planned package and getting user feedback, I thought it might be worth pausing and soliciting suggestions and requests (and discouragement too!) from interested members of this group as to the features they’d like to see in such a package. Background I take it for granted that users of this group know that TeX (i) provides mechanisms for automatic ligation of the ”ff”, ”fi”, ”fl”, ”ffi”, and ”ffl” character combinations and (ii) provides not just one but four [4!] mechanisms for suppressing ligation feature on an ad-hoc, i.e., instance by instance basis; see, e.g., p. 56 of Eijkhout’s book TeX by Topic. Interestingly, one of the four methods -- inserting an empty brace group, {}, between the characters in question -- does not work in xe(la)tex and lua(la)tex, i.e., ligation is not suppressed if this method is employed. In the TeXBook, Knuth cites ”shelfful” as a word for which the ”ff” ligature should be suppressed. The general principle that suggests/requires ligation

762

suppression may be expressed as: ligatures should/must not cross morpheme boundaries. Morphemes, loosely speaking, are the smallest linguistic units (whether words or word particles) that contain distinct meaning, as in ”shelf” and ”ful[l]” in the preceding example. Other candidate words -- I’ve assembled well over a hundred such words in the meantime -- are ”selfish”, ”halflife” and ”pdflatex” (ouch!), ”stuffiness”, ”scofflaw” and ”cufflink”, ”wolffish” (yes, there is such a beast), and ”safflower”, to name some examples of each of the other six cases for which ligatures ought to be suppressed. To the best of my knowledge, there exists no general method yet that allows TeX/LaTeX users to create a ligation exception list that could be loaded, say, in the document’s preamble and which offers a ”turnkey solution” to the various issues related to ligature suppression. (For instance, if ligation is to be suppressed for ”f-l” for some group of words, the kerning amounts needed to obtain the proper amount of separation between the ”f” and ”l” character can differ considerably depending on (i) the font family in use and (ii) whether the text is set in an upright, bold, italic, or bold-italic shape.) Thus, writers are left to their own devices and, more often than not, fail to suppress ligation when needed. Incidentally, whereas this problem is generally not too virulent in English-language documents, it seems to be far more serious in other languages, such as German, which feature composite words much more frequently. Of course, the failure to suppress ligatures selectively for certain words is not an issue that’s confined to TeX and LaTeX. Many general-purpose word processing packages, including Word, either don’t offer ligation at all or they require it to be enabled via some set of menu choices that most users are apparently not even aware of. (And, once it’s enabled, most users don’t seem to know how to disable it selectively for certain words...) Whereas some ”professional” packages, such as Adobe’s InDesign, do offer the option to enable character ligation globally, they do not seem to offer a method for specifying a list of words in advance for which character ligation should be suppressed. Open Questions I’d like to solicit your opinions, advice, and comments on the following issues: • The code I have to instruct TeX to suppress ligation for a specified 763

list of words is based on lua(la)tex. Hence, the package requires the luatex engine; it will not run under either pdf(la)tex or xe(la)tex. [See the answers to the questions Can one (more or less automatically) suppress ligatures for certain words? and Porting the luatex/ConTeXt module ”translate” to lualatex for details on the lualatex code involved.] Given that many (most?!) LaTeX users don’t even seem to know about lualatex yet (and many still use the .tex -> .dvi -> .ps -> .pdf route, i.e., don’t seem to be familiar or comfortable with pdf(la)tex), is requiring lualatex effectively going to kill the package’s usability for all but a tiny minority of TeX users? Or, is it safe and/or reasonable to assume that even though lualatex may not exactly be in widespread use at the present time, it will be used more commonly in two or three years, say? • Are there already lists of words for which f-ligatures should be avoided, whether in English or in other languages? I’m not aware of such lists, leading me to assemble my own list of more than a hundred such words in the meantime. However, if anyone is aware of such word lists - especially if they’re accessible to the public -- I’d really appreciate knowing about them. • How important might it be to make the package usable for users of fonts other than Latin Modern? Obviously, with hundreds (thousands?, tens of thousands?) of opentype fonts in existence, many of which feature at least the set of five f-ligatures, it’s quite impossible for me (or anyone else!) to maintain a list of the kerning amounts neede to fix the ligation exceptions for all of these fonts. Of course, I’ll include Latin Modern as well as some of the fonts in the TeX Gyre distributions for treatment in the package. Which other font families should I consider? • Suggestions for font families for which not to bother with creating ligation exception adjustments? For instance, some font families have a lowercase-f with a very pronounced right-overhang; in these cases, suppressing the ”f-i” and ”f-l” ligatures would require moving the ”i” and ”l” characters so far over to the right, to avoid a collision with the ”f”, that an ugly visual hole or gap inside the word would result -creating an even worse typographical problem. • Any suggestions for a snappy and/or catchy name for this package?!

764

Comments and suggestions on other topics -- as long as they’re related to the issues at hand -- are obviously also welcome! Addendum: I’ve followed up on Mark Everitt’s suggestion and found doncherry’s question, over in English.SE, about words for which ligation should be avoided. I’ve posted my current list of such words as an answer to doncherry’s question.

Second Addendum: It’s been suggested I provide the following piece of information, for anyone who comes across this posting and might be wondering if anything has come of the announced efforts. The comments and answers I received were, in fact, extremely helpful in the creation of the selnolig package. This package performs automated selective ligature suppression for German (f-ligatures, aka common ligatures, only) and English (common and rare ligatures) language documents. This package is fairly stable now but still subject to various potential improvements. Comments and suggestions always welcome! Tags: ligatures (Prev Q) (Next Q) User: mico

Answer by simifilm There is the perl program rmligs which does this job for German (German being a language where this is needed quite often). Unfortunately, the word list itself doesn’t seem to be available. I also don’t know how good the list is; it probably follows pre-reform orthographic rules. Maybe you can reach its author. There is a project for improved German hyphenation which has quite extensive word lists. Maybe they can be of help as well. As for the question whether it’s smart to rely on LuaLaTeX I say: go ahead. One problem of the TeX world is exactly how slowly people adapt to new tools. But if no one starts, no one will move. The more attractive tools exist for modern engines, the more people will actually start to use them. EDIT: And since I’m a huge fan of Stempel Garamond and Frutiger, these fonts should definitely be considered. ;) Seriously though: Couldn’t the

765

package just remove wrong ligatures for all fonts and only care about proper kerning for a selected few?

Answer by aditya Since you are writing a luatex module, store your data as a lua table so that it may be reused by other formats or programs. For TeX modules, data is often stored as TeX macros, e.g. \suppressligature{selfish}{self{}ish} etc. This makes it hard to use the same data in other formats/programs and leads to a lot of duplication of effort. A better solution would be to store the data is a separate lua file as thirddata = thirdata or {} thirddata.ligatures = thirddata.ligatures or {} local suppress = { ["selfish"] = {"self", "ish"}, .... } thirddata.ligatures.suppress = suppress etc. It is relatively easy to read the lua table and generate the appropriate TeX macros, while parsing TeX macros is always a pain.

Answer by doncherry luatex: As there doesn’t seem to be a solution to this problem without luatex, you might as well be hopeful that your package will recruit new luatex users. What’s the microtype situation for luatex, does the current release work for it? If not, I’d stick with pdflatex. fonts: You could take the font poll as inspiration, so Palatino and Linux Libertine would be other fonts to consider. names: How about smartliga / smartligs or cleverliga / cleverligs?

766

Tags: ligatures (Prev Q) (Next Q)

Q: How to suppress the operation of a luatex-defined macro on a string if the string is part of macro or a label Tags: ligatures (Prev Q) (Next Q) I’m working towards creating a lualatex-based package that lets users automatically suppress the use of ligatures (for now, ff, fi, fl, ffi, ffl, and ft) for selected words. (For background see this question.) The package is set to work with both English and German language words. The MWE below, which is a very much stripped down version of the package, shows how to suppress the insertion of ligatures for four selected words -- two English, two German. (The correct hyphenation of the selected words -- both at the nonligation points and potentially elsewhere in the words -- is also taken care of. The little red dashes in the output image, generated by of the showhyphens package, indicate where LuaLaTeX thinks it’s OK to insert hyphenation breaks.) Here’s the problem I’m trying to solve: The package’s main routine (implemented as a lua callback function that operates on process_input_buffer) turns out to be way too greedy for its own good: It tries to perform string substitution operations on everything in the input buffer, including the names and arguments of TeX macros. To make the package suitable for field work, I have to find a way to prevent the main text translation macro from operating on • string snippets that are parts of TeX macros and on • the arguments of select instructions, such as \label and \ref. (There are probably other cases where the substitution shouldn’t be applied either.) Are there any conditionals -- or how might one go about creating such conditionals? -- to check if a string for which a match is found is part of either an already-defined macro or an argument of a \label or \ref (or \varioref, 767

\cref, etc) macro? Alternatively, how might one prevent outright the substitution macro from operating on (i) any TeX macros and (ii) the arguments of selected macros? A couple of quick illustrations of these problems: • Suppose that there’s a macro in a document named named \bookshelfful. (Not exactly likely, of course, but this is just meant to provide an example.) For such a macro, I don’t want my macro operating on it, as it would end up being transformed into \bookshelf \nobreak\hskip0pt \discretionary{\char\hyphenchar\font}{}{\kern\KERN} \nobreak\hskip0pt ful. Arggh. • Should there be a label in the document named ”thm:cufflinks” (yeah, sure!), it must not get translated into ”thm:cuff\nobreak\hskip0pt \discretionary{\char\hyphenchar\font}{}{\kern\KERN} \nobreak\hskip0pt links”. Double arrgh. Skip code block

% !TEX TS-program = lualatex \documentclass[12pt]{article} \usepackage[margin=1in]{geometry} \usepackage[no-math]{fontspec} %% work around a bug in luaotfload (cf. https://tex.stackexchange.com/q/47031/5 \setmainfont[Renderer=Basic]{Latin Modern Roman} \defaultfontfeatures{Ligatures={TeX,Common}} \usepackage{showhyphens} % show all hyphenation points \usepackage{luatexbase,luacode} \begin{luacode*} do local replace = {} local filter = function ( buf ) for key, val in pairs ( replace ) do buf = string.gsub ( buf, key, val ) end 768

return buf end function translateinput ( arg1,arg2 ) -- with discretionary hyphen replace[arg1]=string.gsub(arg2,"|%*|",[[\kernandhyph ]]) end function enablefilters() luatexbase.add_to_callback('process_input_buffer', filter, 'filter') end end \end{luacode*} \newcommand\enableinputtranslation{ \directlua{ enablefilters() } } \newcommand{\kernandhyph}{% \nobreak\hskip0pt% \discretionary{\char\hyphenchar\font}{}{\kern\KERN}% \nobreak\hskip0pt% } \newcommand\translateinput[2]{ \directlua{ translateinput ( "\luatexluaescapestring{#1}", "\luatexluaescapestring{#2}" ) } } % some substitution rules \translateinput{lfful}{lf|*|ful} \translateinput{fflink}{ff|*|link} \translateinput{iflich}{if|*|lich} 769

%% e.g., shelf-ful(s) bookshelf-ful(s) %% cuff-link(s) %% reif-lich begreif-lich tarif-lich

\translateinput{uflauf}{uf|*|lauf} \translateinput{ufform}{uf|*|form} \newlength\KERN \setlength\KERN{0.07ex}

%% %%

auf-laufen auf-formen

% trial value for amount of kern to be inserted

\begin{document} shelfful cufflink unbegreiflich Auflaufform \quad \emph{versus} \enableinputtranslation

% turn on input translation

shelfful cufflink unbegreiflich Auflaufform \end{document}

Tags: ligatures (Prev Q) (Next Q) User: mico

Answer by taco-hoekwater Here is my solution to this problem, which also uses the ligaturing callback (reusing lots of code from the earlier answer). Instead of attempting to do the actual hyphenation in the processing function, my code one inserts whatsit nodes at the key spots. Those whatsit nodes then prohibit ligature building at those spots. Skip code block \documentclass{article} \usepackage{fontspec} \usepackage{luacode}%,luatexbase} 770

\setmainfont[Renderer=Basic]{Latin Modern Roman} %\defaultfontfeatures{Ligatures={TeX,NoCommon}} %\setmainfont{Linux Libertine O} \usepackage[margin=1cm]{geometry} \begin{luacode} local glyph = node.id('glyph') local glue = node.id("glue") local whatsit = node.id("whatsit") local userdefined for n,v in pairs(node.whatsits()) do if v == 'user_defined' then userdefined = n end end local identifier = 123456 -- any unique identifier local noliga={} debug=false function debug_info(s) if debug then texio.write_nl(s) end end local blocknode = node.new(whatsit, userdefined) blocknode.type = 100 blocknode.user_id = identifier function process_ligatures(nodes,tail) local s={} local current_node=nodes--node.copy(nodes) local build_liga_table = function(strlen,t) local p={} for i = 1, strlen do p[i]=0 end for k,v in pairs(t) do debug_info("Match: "..v[3]) local c= string.find(noliga[v[3]],"|") local correction=1 while c~=nil do debug_info("Position "..(v[1]+c)) 771

p[v[1]+c-correction] = 1 c = string.find(noliga[v[3]],"|",c+1) correction=correction+1 end end debug_info("Liga table: "..table.concat(p, "")) return p end local apply_ligatures=function(head,ligatures) local i=1 local hh=head local last=node.tail(head) for curr in node.traverse_id(glyph,head) do if ligatures[i]==1 then debug_info("Current glyph: "..unicode.utf8.char(curr.char)) node.insert_before(hh,curr, node.copy(blocknode)) hh=curr end last=curr if i==#ligatures then debug_info("Leave node list on position: "..i) break end i=i+1 end if(last~=nil) then debug_info("Last char: "..unicode.utf8.char(last.char)) end--]] end for t in node.traverse(nodes) do if t.id==glyph then s[#s+1]=string.lower(unicode.utf8.char(t.char)) elseif t.id== glue then local f=string.gsub(table.concat(s,""),"[\\?!,\\.]+","") -- add all interpun local throwliga={} for k, v in pairs(noliga) do local count=1 local match= string.find(f,k) 772

while match do count=match debug_info("pattern match: "..f .." - "..k) local n = match + string.len(k)-1 table.insert(throwliga,{match,n,k}) match= string.find(f,k,count+1) end end if #throwliga==0 then debug_info("No ligature substitution for: "..f) else debug_info("Do ligature substitution for: "..f) local ligabreaks=build_liga_table(f:len(),throwliga) apply_ligatures(current_node,ligabreaks) end s={} current_node=t end end -- node.ligaturing(nodes) -- not needed, luaotfload does ligaturing end function suppress_liga(s,t) noliga[s]=t end function drop_special_nodes (nodes,tail) for t in node.traverse(nodes) do if t.id == whatsit and t.subtype == userdefined and t.user_id == identifier t node.remove(nodes,t) node.free(t) end end end luatexbase.add_to_callback("ligaturing", process_ligatures,"Filter ligatures", 1) --luatexbase.add_to_callback("ligaturing", drop_special_nodes,"Drop filter ligatur \end{luacode} \newcommand\suppressligature[2]{ \directlua{ suppress_liga("\luatexluaescapestring{#1}","\luatexluaescapestring{#2}") 773

} } \newcommand\debugon{% \directlua{ debug=true } } \begin{document} \suppressligature{fifi}{f|ifi} \suppressligature{grafi}{graf|i} \suppressligature{lfful}{lf|ful} \suppressligature{fflink}{ff|link} \suppressligature{iflich}{if|lich} \suppressligature{uflauf}{uf|lauf} \suppressligature{ufform}{uf|form} \debugon shelfful cufflink unbegreiflich Auflaufform offen \end{document} As you can see, the code does not do any ligaturing at all (!) as that is handled by luaotfload in the pre_linebreak_filter. However, this also creates a minor glitch: the added whatsits also prevent kerning at those spots, but they cannot be removed here because that would re-enable the ligatures once luaotfload comes into play. I do not know enough of the internals of lualatex to fix this (minor) problem.

Answer by topskip (too long for a comment) I have tried and tried, but I can’t find a good solution. @michal.h21 has 774

tried with the ligaturing callback, but this, as he writes, fails when using complex rendering mode in LuaTeX. So I’ve tried to hook into the pre_linebreak_filter which has all ligatures in their place, but I have problems breaking the ligatures apart. Say for example you have a ligature ffi and want to suppress ligaturing between f and fi. TeX (or the font subsystem) has already created the ligature when I am in the pre_linebreak_filter and you can break them apart, but only in a predefined way: in the word ”fluffiest” the second ligature is made of the ligature ”ff” and ”i” thus it is ”ffi”. The ligature ”ff” is, obviously, made of ”f” and ”f”. Now it would be easy to split at ”ff|i” - I keep the ff-ligature and insert a space before the ”i”. But to separate the ”ffi” at ”f|fi” I would have to create a new ligature (”fi”), but this is almost impossible (not technically, I could create the necessary data structures, but the logic how to create ligatures is in the font subsystem). Therefore the pre_linebreak_filter is not a good place to do the un-ligaturing. But if we move forward (towards the original input of TeX), it is impossible to parse the input and get all occurrences of the words: \documentclass{article} \begin{document} \newcommand\auflauf{Auflauf} \newcommand\form{form} \auflauf\form \end{document} The word is still ”ligatured” but you won’t be able to parse this with the method you want in your question. This leads to my result: it is not possible without hooking into the font subsystem (in this case luaotfload).

Tags: ligatures (Prev Q) (Next Q)

775

Q: Ligature suppression algorithm fails if the word in question contains an Umlaut (dieresis) before the ligature Tags: ligatures (Prev Q) (Next Q) This is a follow-up posting prompted by Taco Hoekwater’s recent excellent answer to a question I posed a few months ago. It concerns the use of the ligature suppression algorithm for words (mainly, but not exclusively, Germanlanguage words) that contain Umlaute (diereses). Taking Taco’s MWE as the starting point (not reproduced below because it’s quite long), add the instructions

\suppressligature{lffach}{lf|fach} %% no f-ligature in words containing the string \suppressligature{rflich}{rf|lich} %% ditto for words containing the string "rflic \suppressligature{mpfflug}{mpf|flug} and the following six words (which all contain potential f-ligature glyphs): elffach zwölffach %% ff ligature to be suppressed verwerflich dörflich %% fl ligature to be suppressed Kampfflugzeug Düsenkampfflugzeug %% ffl ligature to be replaced with f-fl after \begin{document}. This results in the following output:

Notice that the three words which do not contain an Umlaut before the | ligature suppression point are treated correctly, i.e., the ff, fl, and ffl ligatures are broken up in the manner indicated by the applicable \suppressligature commands. In contrast, ligature suppression fails for the second set of three words -- apparently because they contain an Umlaut. This happens with words containing an ä Umlaut as well, by the way. Furthermore, I’ve determined that this problem only appears to happen with words that contain an Umlaut before the ligature suppression point. Words 776

that contain an Umlaut after the ligature suppression point indicated by a corresponding \suppressligature instruction are treated correctly. E.g., when supplying the instruction \suppressligature{uflös}{uf|lös}, the words auflösen and Auflösung are both rendered without the fl ligature. A word about my TeX setup: I mostly run TeXLive2011 and use TeXWorks as my editor program. However, the problem also occurs under MiKTeX2.9, with all the latest updates installed, and with WinEdt7.0 as the editor. Both editors are fully unicode-aware. Question: How does Taco’s code need to be edited/modified to circumvent the problem(s) described in this posting? Tags: ligatures (Prev Q) (Next Q) User: mico

Answer by taco-hoekwater The problem is that string.find returns a byte location, and in this case you want to have a character index when comparing nodes to strings. The solution is to replace table.insert(throwliga,{match,n,k}) with table.insert(throwliga,{prefix_length(f,match),n,k}) where prefix_length is defined like this: local prefix_length = function(word,byte) return unicode.utf8.len(string.sub(word,0,byte)) end Which simply returns the length in characters of the prefix of word that ends at byte. Note: This change only fixes the current problem, it does not solve cases where there are unicode characters inside the strings in the noliga table. Please do not ask me to write that as well, there should be some challenge left ;)

777

Tags: ligatures (Prev Q) (Next Q)

Q: How do I customize a LuaLaTeX cmap? Tags: ligatures (Prev Q) (Next Q) I’m working on a system that uses database content to produce PDFs in a variety of languages. I’m currently working on Armenian. What we’ve developed so far uses pdfLaTeX. I made a special encoding to handle Armenian and got it all working, only to discover that the five ligatures in FreeSerif that had underscores in the glyph names ended up not being copyable or searchable. For example, copying the ligature glyph m_n_armenian ends up with ”mn,” and \pdfglyphtounicode doesn’t seem able to override the default behavior of treating the ASCII letters separated by underscores as being the desired target characters for copying and pasting. I explored using XeLaTeX, but found that colored footnotes spanning multiple pages lose their color on the second page. pdfcolfoot fixes this problem in pdfLaTeX, but the required color stacks aren’t available in XeLaTeX. Having just discovered that LuaLaTeX doesn’t have this limitation, I’m checking to see if it will do what I want it to do. Given that LuaLaTeX seems to be the successor to pdfLaTeX, we should probably move that direction if LuaLaTeX can do everything we need done. \documentclass[14pt]{memoir} \usepackage{fontspec} \setmainfont[Script=Armenian]{Freeserif} \pdfcompresslevel=0 \begin{document} � � � � � �� �� �� �� �� \end{document}

778

The first line of text above contains the five Armenian ligatures in question, unicode characters FB13 through FB17. The second line are the total of ten characters that make up these five ligatures, from the range 0500 to 05FF. Compiling this with LuaLaTeX, I end up with two lines of the five ligatures displayed correctly. But when I copy and paste, I end up with two lines of five ligatures, not the ten characters. I want to override this default behavior. I want the cmap in the PDF to specify:







instead of: But I can’t figure out how to alter the cmaps at all via LuaLaTeX. I’ve found http://www.luatex.org/svn/branches/0.70.x/source/texk/web2c/luatexdir/ font/tounicode.w but I’m not sure that the functions there are accessible via macros. I think I need to keep the content of the PDFs identical to the content of the database. Otherwise, someone may take content from the database and search for it within a PDF, and never be able to find it since the ten characters when paired up are replaced by the ligature characters. What should I do? Can the cmaps be tinkered with via LuaLaTeX? I have a much more difficult language to work with next, and I think I’m going to need this level of control over the cmaps. Tags: ligatures (Prev Q) (Next Q) User: pickle

Answer by pickle In the preamble, include: \usepackage{luacode}. \end{document}, include the following: 779

Just before

Skip code block

\begin{luacode*} tounicodevalues = { [64275] = "05740576", [64276] = "05740565", [64277] = "0574056B", [64278] = "057E0576", [64279] = "0574056D", } for i,f in font.each() do if (string.match(f.name, "FreeSerif") and string.match(f.name, "script=arm for u, v in next, tounicodevalues do f.characters[u].tounicode = v end font.fonts[i] = f end end \end{luacode*} Why before \end{document}? Because you want to do this after LuaLaTeX already knows what all of the fonts are that it will actually be using. Why restrict the routine to certain matching fonts? This avoids the error of trying to change fonts that have already been accessed, such as line10, which is forbidden. This code could be wrapped in a TeX macro and placed in the preamble, and then called just before \end{document}. This example doesn’t use the luacode package: Skip code block \newcommand{\tounicode}[2][]{\directlua0{ tounicodevalues = { [64275] = "05740576", [64276] = "05740565", [64277] = "0574056B", [64278] = "057E0576", [64279] = "0574056D", } 780

for i,f in font.each() do if (string.match(f.name, "#1") and string.match(f.name, "#2")) then for u, v in next, tounicodevalues do f.characters[u].tounicode = v end font.fonts[i] = f end end }} \begin{document} � � � � � \tounicode[script=armn]{FreeSerif} \end{document} Using fontspec, I added the font feature, HyphenChar={1418}, which changes the hyphenation character to the Armenian hyphen. Doing so results in the altering-already-accessed-font error when using the above function, unless additional matching criteria is added using an optional argument such as ”script=armn.” To find out what the font names are that you are trying to match, add the following code to the above function. for i,f in font.each() do texio.write_nl("["..i.."] => "..f.name) end

Answer by graham-douglas LuaTeX’s mechanism for defining fonts offers the following route to constructing the /ToUnicode entry. The following text is taken from section 7 Font structure (page 153 of the LuaTeX manual for beta 0.71.0): The usage of tounicode is this: if this font specifies a tounicode=1 at the top level, then LuaTEX will construct a /ToUnicode entry for the pdf font (or font subset) based on the character-level 781

tounicode strings, where they are available. If a character does not have a sensible Unicode equivalent, do not provide a string either (no empty strings). If the font-level tounicode is not set, then LuaTEX will build up /ToUnicode based on the TEX code points you used, and any character-level tounicodes will be ignored. At the moment, the string format is exactly the format that is expected by Adobe CMap files (utf-16BE in hexadecimal encoding), minus the enclosing angle brackets. This may change in the future. Small example: the tounicode for a fi ligature would be 00660069.

Tags: ligatures (Prev Q) (Next Q)

Q: LuaTeX does not respect brace groups used for disabling ligatures Tags: ligatures (Prev Q) I noticed the following strange behavior of LuaTeX. I am not sure if it is intentional or not. The minimal example is, fi f{}i f{i} {f}i f\/i \bye (This is the complete document, plain TeX, thus no package or whatsoever to effect the results) Here is the pdfTeX output

782

Which is as expected. And here is the LuaTeX output

Grouping using curly braces appears to have no effect at all, i.e, it does not disable the use of ligatures. The log files shows that both pdftex and luatex use exactly the same type1 fonts, as expected. So it is not a thing with handling of Opentype, which I initially suspected. Is this a bug (I think it is) or intended behavior of luatex? I am using the versions of pdftex and luatex from up-to-date TeXLive 2016 Tags: ligatures (Prev Q) User: yan-zhou

Answer by egreg From the LuaTeX manual (version 0.95)

783

Using a kern is the only way, as far as I can see. Either \/ or \kern0pt would do.

Tags: ligatures (Prev Q)

Errors Skip to questions, Wiki by user martin-scharrer Error messages which mostly show (La)TeX code should be marked as a code block (indent with 4 spaces or the {} button), not as a quotation (>). Error messages which mostly show file paths and no code, like File not found or similar errors, should be placed between and HTML tags to avoid wrong syntax highlighting. Otherwise in e.g. c:\localtexmf\latex the two directories would be highlighted as macros because of the preceding backslashes \. 784

Questions Q: Tex capacity exceeded compiling only 50 lines latex file (pdftex), seg. fault (lualatex) Tags: errors (Prev Q) (Next Q), verbatim (Next Q) This is one of the strangest things I’ve seen in Latex (and I have seen many strange things). 50 lines of code, almost all of it is verbatim. Any small change to the verbatim can cause the error to go away. it seems random. I managed to get it to 50 lines verbatim and still show the error. But if I make small change, remove 2-3 lines or delete an empty line, the error could go away or it might stay. it is random. Here is the code: Skip code block \documentclass[11pt]{book}%ext \usepackage[T1]{fontenc} \usepackage{verbatim} \usepackage{amsmath,mathtools} \usepackage[utf8]{inputenc} %DO NOT USE WIT LUALATEX, only with pdflatex \usepackage{graphicx} \usepackage{breqn} %do not use this with tex4ht. added 4/2/16 \begin{document} \section{How to implement Steepest descent for finding minumum of $f(x,y)$ ?} function nma_problem_2() close all; del = 0.05; u1 = 0:del:20; u2 = -10:del:15; [u1,u2] = meshgrid(u1,u2); plot(0,0); xlim([0 20]); ylim([-5 15]); 785

hold on; [u(1),u(2)] = ginput(1); t=text(1.08*u(1),u(2),sprintf('[%2.1f,%2.1f]',u(1),u(2))); t.FontSize=8; t.Color='red'; x = fminsearch(@objectiveFunc, u); %used to find the minumum in order to show %progress towards it hold on; plot(x(1),x(2),'*r') plot(u(1),u(2),'or') MAX_ITER = 50; REL_TOL = 10^(-4); stepSize = -1; %optimal [p,levelSets] = steepestDescentPoints(u,MAX_ITER,REL_TOL,stepSize,... @objectiveFunc,@gradientFunc); [C,h] = contour(u1,u2,z,levelSets); %,'ShowText','on'); if length(p(:,1))>1 for k=1:length(p)-1 line([p(k,1),p(k+1,1)],[p(k,2),p(k+1,2)]); %draw line between each step drawnow; pause(.2); title(sprintf('starting from [%3.3f,%3.3f], f(u)=%3.3f, step = %d',... u(1),u(2),norm(objectiveFunc(u)),k)); end end \end{document} Please make sure not to modify the code before seeing the error, as any small change to the verbatim code, could mask the error away! I also put the above source as in this folder Here is the error Skip code block pwd /media/data/latex/standalone_2 786

pdflatex foo.tex This is pdfTeX, Version 3.14159265-2.6-1.40.16 (TeX Live 2015) (preloaded format=p restricted \write18 enabled. entering extended mode (./foo.tex LaTeX2e patch level 2 Babel and hyphenation patterns for 79 languages loaded. (/usr/local/texlive/2015/texmf-dist/tex/latex/base/book.cls Document Class: book 2014/09/29 v1.4h Standard LaTeX document class (/usr/local/texlive/2015/texmf-dist/tex/latex/base/bk11.clo)) (/usr/local/texlive/2015/texmf-dist/tex/latex/base/fontenc.sty (/usr/local/texlive/2015/texmf-dist/tex/latex/base/t1enc.def)) (/usr/local/texlive/2015/texmf-dist/tex/latex/fancybox/fancybox.sty Style option: `fancybox' v1.4 (tvz) ) (/usr/local/texlive/2015/texmf-dist/tex/latex/fancyvrb/fancyvrb.sty Style option: `fancyvrb' v2.7a, with DG/SPQR fixes, and firstline=lastline fix (tvz) (/usr/local/texlive/2015/texmf-dist/tex/latex/graphics/keyval.sty)) (/usr/local/texlive/2015/texmf-dist/tex/latex/amsmath/amsmath.sty For additional information on amsmath, use the `?' option. (/usr/local/texlive/2015/texmf-dist/tex/latex/amsmath/amstext.sty (/usr/local/texlive/2015/texmf-dist/tex/latex/amsmath/amsgen.sty)) (/usr/local/texlive/2015/texmf-dist/tex/latex/amsmath/amsbsy.sty) (/usr/local/texlive/2015/texmf-dist/tex/latex/amsmath/amsopn.sty)) (/usr/local/texlive/2015/texmf-dist/tex/latex/mathtools/mathtools.sty (/usr/local/texlive/2015/texmf-dist/tex/latex/tools/calc.sty) (/usr/local/texlive/2015/texmf-dist/tex/latex/mathtools/mhsetup.sty)) (/usr/local/texlive/2015/texmf-dist/tex/latex/base/inputenc.sty (/usr/local/texlive/2015/texmf-dist/tex/latex/base/utf8.def (/usr/local/texlive/2015/texmf-dist/tex/latex/base/t1enc.dfu) (/usr/local/texlive/2015/texmf-dist/tex/latex/base/ot1enc.dfu) (/usr/local/texlive/2015/texmf-dist/tex/latex/base/omsenc.dfu))) (/usr/local/texlive/2015/texmf-dist/tex/latex/graphics/graphicx.sty (/usr/local/texlive/2015/texmf-dist/tex/latex/graphics/graphics.sty (/usr/local/texlive/2015/texmf-dist/tex/latex/graphics/trig.sty) (/usr/local/texlive/2015/texmf-dist/tex/latex/latexconfig/graphics.cfg) (/usr/local/texlive/2015/texmf-dist/tex/latex/pdftex-def/pdftex.def 787

(/usr/local/texlive/2015/texmf-dist/tex/generic/oberdiek/infwarerr.sty) (/usr/local/texlive/2015/texmf-dist/tex/generic/oberdiek/ltxcmds.sty)))) (/usr/local/texlive/2015/texmf-dist/tex/latex/breqn/breqn.sty (/usr/local/texlive/2015/texmf-dist/tex/latex/l3kernel/expl3.sty (/usr/local/texlive/2015/texmf-dist/tex/latex/l3kernel/expl3-code.tex) (/usr/local/texlive/2015/texmf-dist/tex/latex/l3kernel/l3pdfmode.def)) (/usr/local/texlive/2015/texmf-dist/tex/latex/breqn/flexisym.sty (/usr/local/texlive/2015/texmf-dist/tex/latex/breqn/cmbase.sym) (/usr/local/texlive/2015/texmf-dist/tex/latex/breqn/mathstyle.sty))) (./foo.aux ) (/usr/local/texlive/2015/texmf-dist/tex/context/base/supp-pdf.mkii [Loading MPS to PDF converter (version 2006.09.02).] ) (/usr/local/texlive/2015/texmf-dist/tex/generic/oberdiek/pdftexcmds.sty (/usr/local/texlive/2015/texmf-dist/tex/generic/oberdiek/ifluatex.sty) (/usr/local/texlive/2015/texmf-dist/tex/generic/oberdiek/ifpdf.sty)) (/usr/local/texlive/2015/texmf-dist/tex/latex/oberdiek/epstopdf-base.sty (/usr/local/texlive/2015/texmf-dist/tex/latex/oberdiek/grfext.sty (/usr/local/texlive/2015/texmf-dist/tex/generic/oberdiek/kvdefinekeys.sty)) (/usr/local/texlive/2015/texmf-dist/tex/latex/oberdiek/kvoptions.sty (/usr/local/texlive/2015/texmf-dist/tex/generic/oberdiek/kvsetkeys.sty (/usr/local/texlive/2015/texmf-dist/tex/generic/oberdiek/etexcmds.sty))) (/usr/local/texlive/2015/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg)) (/usr/local/texlive/2015/texmf-dist/tex/latex/base/t1cmtt.fd) Overfull \hbox (75.69456pt too wide) in paragraph at lines 50--50 []\T1/cmtt/m/n/10.95 x = fminsearch(@objectiveFunc, u); %used to find the minum um in order to show[] Overfull \hbox (30.4276pt too wide) in paragraph at lines 50--50 []\T1/cmtt/m/n/10.95 [p,levelSets] = steepestDescentPoints(u,MAX_ITER,REL_TOL,s tepSize,...[] Overfull \hbox (41.74434pt too wide) in paragraph at lines 50--50 []\T1/cmtt/m/n/10.95 line([p(k,1),p(k+1,1)],[p(k,2),p(k+1,2)]); %draw line betw een each step[] Overfull \hbox (41.74434pt too wide) in paragraph at lines 50--50 []\T1/cmtt/m/n/10.95 title(sprintf('starting from [%3.3f,%3.3f], f(u)=%3.3f, tep = %d',...[]

788

s

Underfull \vbox (badness 10000) has occurred while \output is active ! TeX capacity exceeded, sorry [main memory size=8000000]. ,->\leavevmode \kern \[email protected] \char `\, l.50 \endverbatim} ! ==> Fatal error occurred, no output PDF file produced! Transcript written on foo.log. standalone_2> This that will go the error to go away: change the line \section{How to implement Steepest descent for finding minumum of $f(x,y)$ ?} to \section{How to implement Steepest descent for finding minumum of f ?} also delete the empty line after verbatim i.e. change \begin{verbatim} function nma_problem_2() to \begin{verbatim} function nma_problem_2() also remove the breqn package will remove the error. And many other little things like this. The error can go away by random. May be it is breqn fault again, I do not know. question is: How to resolve this error? What is causing it? TL 2015 on Linux. Error also shows on windows under miktex. btw, lualatex core dumps on this file also Skip code block standalone_2>lualatex foo.tex This is LuaTeX, Version beta-0.80.0.1 (TeX Live 2015) (rev 5863) restricted \write18 enabled. (./foo.tex 789

LaTeX2e patch level 2 Babel and hyphenation patterns for 79 languages loaded. (/usr/local/texlive/2015/texmf-dist/tex/latex/base/book.cls Document Class: book 2014/09/29 v1.4h Standard LaTeX document class (/usr/local/texlive/2015/texmf-dist/tex/latex/base/bk11.clo)) (/usr/local/texlive/2015/texmf-dist/tex/latex/base/fontenc.sty (/usr/local/texlive/2015/texmf-dist/tex/latex/base/t1enc.def)) (/usr/local/texlive/2015/texmf-dist/tex/latex/tools/verbatim.sty) (/usr/local/texlive/2015/texmf-dist/tex/latex/amsmath/amsmath.sty For additional information on amsmath, use the `?' option. (/usr/local/texlive/2015/texmf-dist/tex/latex/amsmath/amstext.sty (/usr/local/texlive/2015/texmf-dist/tex/latex/amsmath/amsgen.sty)) (/usr/local/texlive/2015/texmf-dist/tex/latex/amsmath/amsbsy.sty) (/usr/local/texlive/2015/texmf-dist/tex/latex/amsmath/amsopn.sty)) (/usr/local/texlive/2015/texmf-dist/tex/latex/mathtools/mathtools.sty (/usr/local/texlive/2015/texmf-dist/tex/latex/graphics/keyval.sty) (/usr/local/texlive/2015/texmf-dist/tex/latex/tools/calc.sty) (/usr/local/texlive/2015/texmf-dist/tex/latex/mathtools/mhsetup.sty)) (/usr/local/texlive/2015/texmf-dist/tex/latex/base/inputenc.sty Package inputenc Warning: inputenc package ignored with utf8 based engines. ) (/usr/local/texlive/2015/texmf-dist/tex/latex/graphics/graphicx.sty (/usr/local/texlive/2015/texmf-dist/tex/latex/graphics/graphics.sty (/usr/local/texlive/2015/texmf-dist/tex/latex/graphics/trig.sty) (/usr/local/texlive/2015/texmf-dist/tex/latex/latexconfig/graphics.cfg) (/usr/local/texlive/2015/texmf-dist/tex/latex/pdftex-def/pdftex.def (/usr/local/texlive/2015/texmf-dist/tex/generic/oberdiek/infwarerr.sty) (/usr/local/texlive/2015/texmf-dist/tex/generic/oberdiek/ltxcmds.sty)))) (/usr/local/texlive/2015/texmf-dist/tex/latex/breqn/breqn.sty (/usr/local/texlive/2015/texmf-dist/tex/latex/l3kernel/expl3.sty (/usr/local/texlive/2015/texmf-dist/tex/latex/l3kernel/expl3-code.tex) (/usr/local/texlive/2015/texmf-dist/tex/latex/l3kernel/l3pdfmode.def)) (/usr/local/texlive/2015/texmf-dist/tex/latex/breqn/flexisym.sty (/usr/local/texlive/2015/texmf-dist/tex/latex/breqn/cmbase.sym) (/usr/local/texlive/2015/texmf-dist/tex/latex/breqn/mathstyle.sty))) (./foo.aux ) (/usr/local/texlive/2015/texmf-dist/tex/context/base/supp-pdf.mkii [Loading MPS to PDF converter (version 2006.09.02).] 790

) (/usr/local/texlive/2015/texmf-dist/tex/generic/oberdiek/pdftexcmds.sty (/usr/local/texlive/2015/texmf-dist/tex/generic/oberdiek/ifluatex.sty) (/usr/local/texlive/2015/texmf-dist/tex/generic/oberdiek/ifpdf.sty) (/usr/local/texlive/2015/texmf-dist/tex/generic/oberdiek/luatex-loader.sty (/usr/local/texlive/2015/texmf-dist/scripts/oberdiek/oberdiek.luatex.lua))) (/usr/local/texlive/2015/texmf-dist/tex/latex/oberdiek/epstopdf-base.sty (/usr/local/texlive/2015/texmf-dist/tex/latex/oberdiek/grfext.sty (/usr/local/texlive/2015/texmf-dist/tex/generic/oberdiek/kvdefinekeys.sty)) (/usr/local/texlive/2015/texmf-dist/tex/latex/oberdiek/kvoptions.sty (/usr/local/texlive/2015/texmf-dist/tex/generic/oberdiek/kvsetkeys.sty (/usr/local/texlive/2015/texmf-dist/tex/generic/oberdiek/etexcmds.sty))) (/usr/local/texlive/2015/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg)) (/usr/local/texlive/2015/texmf-dist/tex/latex/base/t1cmtt.fd) Overfull \hbox (75.69456pt too wide) in paragraph at lines 28--28 [][]\T1/cmtt/m/n/10.95 x = fminsearch(@objectiveFunc, u); %used to find the min umum in order to show[] Overfull \hbox (30.4276pt too wide) in paragraph at lines 37--37 [][]\T1/cmtt/m/n/10.95 [p,levelSets] = steepestDescentPoints(u,MAX_ITER,REL_TOL ,stepSize,...[] Overfull \hbox (41.74434pt too wide) in paragraph at lines 43--43 [][]\T1/cmtt/m/n/10.95 line([p(k,1),p(k+1,1)],[p(k,2),p(k+1,2)]); %draw line be tween each step[] Overfull \hbox (41.74434pt too wide) in paragraph at lines 46--46 [][]\T1/cmtt/m/n/10.95 title(sprintf('starting from [%3.3f,%3.3f], f(u)=%3.3f, step = %d',...[] Underfull \vbox (badness 10000) has occurred while \output is active ! TeX capacity exceeded, sorry [node memory size=385258750]. ,->\leavevmode \kern \[email protected] \char `\, l.49 end Segmentation fault Tags: errors (Prev Q) (Next Q), verbatim (Next Q) 791

User: nasser

Answer by egreg The error is due to breqn, of course. Only one definition for an active character can be valid at a given time. Since you have a math comma in the section title, this goes in the header and, with that long verbatim, it gets typeset when verbatim is active, which gives a different meaning to the active comma. Here’s a minimal example showing the issue. Skip code block \documentclass[11pt]{book} \usepackage{breqn} \setlength{\textheight}{2cm} % to shorten the input \begin{document} \section{$f(x,y)$} \begin{verbatim} x x x x x \endverbatim} \end{document} Here’s a fix to \[email protected], which is responsible for defining a new meaning for active characters in verbatim. Skip code block \documentclass[11pt]{book} \usepackage{breqn} \makeatletter 792

\def\[email protected]#1{% \catcode`#1\active \begingroup\lccode`\~`#1\relax \lowercase{\endgroup \ifdefined~% \expandafter\def\expandafter~\expandafter{% \expandafter\relax \expandafter\ifmmode ~% in math mode use the meaning given by breqn \else \leavevmode\kern\[email protected]\char`#1\relax \fi }% \else \def~{\leavevmode\kern\[email protected]\char`#1}% \fi }% } \makeatother \setlength{\textheight}{2cm} \begin{document} \section{$f(x,y)$} \begin{verbatim} x x x x x \endverbatim} \end{document}

Answer by david-carlisle The main problem is the breqn math comma being written to the mark used 793

in headings while verbatim is active. which gives a classic fragile command in moving argument cryptic error. \hbox hides this (a better fix allowing the comma to be used normally may be posted later) The fact that luatex segfaults after the runaway argument is a separate lower level bug (or not a bug). The code uses arbitrary amounts of memory as it is in an infinite loop, so in classic tex it hits a hard limit but luatex just allocates more and more memory until it runs out of memory of your actual hardware. Skip code block \documentclass[11pt]{book}%ext \usepackage[T1]{fontenc} \usepackage{verbatim} \usepackage{amsmath,mathtools} \usepackage[utf8]{inputenc} %DO NOT USE WIT LUALATEX, only with pdflatex \usepackage{graphicx} \usepackage{breqn} %do not use this with tex4ht. added 4/2/16

\begin{document} \section{How to implement Steepest descent for finding minumum of

\begin{verbatim} function nma_problem_2() close all; del = 0.05; u1 = 0:del:20; u2 = -10:del:15; [u1,u2] = meshgrid(u1,u2); plot(0,0); xlim([0 20]); ylim([-5 15]); hold on; 794

$f(x\hbox{,}y)$

[u(1),u(2)] = ginput(1); t=text(1.08*u(1),u(2),sprintf('[%2.1f,%2.1f]',u(1),u(2))); t.FontSize=8; t.Color='red'; x = fminsearch(@objectiveFunc, u); %used to find the minumum in order to show %progress towards it hold on; plot(x(1),x(2),'*r') plot(u(1),u(2),'or') MAX_ITER = 50; REL_TOL = 10^(-4); stepSize = -1; %optimal [p,levelSets] = steepestDescentPoints(u,MAX_ITER,REL_TOL,stepSize,... @objectiveFunc,@gradientFunc); [C,h] = contour(u1,u2,z,levelSets); %,'ShowText','on'); if length(p(:,1))>1 for k=1:length(p)-1 line([p(k,1),p(k+1,1)],[p(k,2),p(k+1,2)]); %draw line between each step drawnow; pause(.2); title(sprintf('starting from [%3.3f,%3.3f], f(u)=%3.3f, step = %d',... u(1),u(2),norm(objectiveFunc(u)),k)); end end \endverbatim} \end{document}

Tags: errors (Prev Q) (Next Q), verbatim (Next Q)

795

Q: After MiKTeX update when using LuaLaTeX: Package pgf Error: Driver file “pgfsys-luatex.def” not found Tags: errors (Prev Q) (Next Q), tikz-pgf (Prev Q) (Next Q), miktex (Prev Q) (Next Q), external-files (Next Q) I just updated my MiKTeX instance to the latest packages and am using the LuaLaTeX compiler. Whenever a document relies on pgf I get the following error: ! Package pgf Error: Driver file ``pgfsys-luatex.def'' not found.. I found this Bug report, https://sourceforge.net/p/pgf/bugs/384/, where someone provides the missing file (he simply renamed another driver and did little changes apparently), but this really doesn’t solve my problems. The missing file error goes away with this driver, but for example setting aspectratio=169 as a beamer option is fully ignored while it worked perfectly fine with LuaLaTeX before the MiKTeX update. A minimal example would be: \documentclass{article} \usepackage{pgf} \begin{document} Compile me with lualatex.exe \end{document} With the driver from the linked bug report and the following MWE: \documentclass[aspectratio=169]{beamer} \begin{document} Foo \end{document} I only get the default Aspect Ratio of 4:3. Before the MiKTeX update I correctly got 16:9, even with LuaLaTeX. I tried purging and reinstalling MiKTeX. It did not help. How can I compile pgf-based documents with LuaLaTeX correctly again?

796

Tags: errors (Prev Q) (Next Q), tikz-pgf (Prev Q) (Next Q), miktex (Prev Q) (Next Q), external-files (Next Q) User: foo-bar

Answer by engbird As an alternative to \RequirePackage{luatex85} I opted to try out the experimental miktex packages (enabled with the checkbox on the main screen of Update (Admin) for MikTeX as described and illustrated: http://miktex. org/kb/miktex-next). Then in order to ensure everything was successfully registered(?) I went to Settings (Admin) for MikTeX and on the ”General” tab, I clicked RefreshFNDB. Despite using the new experimental package of LuaTeX 0.95 I still had to copy the contents of https://sourceforge.net/p/pgf/bugs/_discuss/thread/ 44f8dcf2/9dc8/attachment/pgfsys-luatex.def to my texmf structure (I placed it in a secondary structure in texmf\tex and re-scanned the roots from Settings (Admin) for MikTeX on the ”Roots” tab.

Tags: errors (Prev Q) (Next Q), tikz-pgf (Prev Q) (Next Q), miktex (Prev Q) (Next Q), external-files (Next Q)

Q: why lualatex gives erorr ”Too many open files” but pdflatex does not on same latex file? Tags: errors (Prev Q) (Next Q) Using TL 2015 on Linux. I have a latex file which includes graphics, all in pdf format. All the images are included using the call

\includegraphics[width=\textwidth,height=\textheight,keepaspectratio]{rules/file_n There is a total of 1860 such images, all in pdf format.

797

When I compile this file using lualatex, at some stage, when it gets to image number 1016, it fails with the error Too many open files. Compiling the same file with pdflatex gives no error ! Is there a limitation on how images one can include in a latex file when using lualatex or is this a bug? It looks like lualatex includegraphics version is not closing file handles when loading images and running out of file handles. This is on Linux mint 7.2. Since the file is large. I have put the file and the images it loads using \includegraphics in one zip file (80 MB). The link is at the bottom of this post. To reproduce, please download the zip file, unzip it using the command unzip file.zip and it will create a new folder called lualatex_error/ and inside this folder there is the one file report.tex and the folder that includes all the images. Then typing lualatex report.tex will give the error lualatex: ./rules/1016.pdf: Too many open files From the report.log This is LuaTeX, Version beta-0.80.0 (TeX Live 2015) (rev 5238) (format=lualatex 2015.7.9) 31 JUL 2015 12:28 restricted \write18 enabled. lualatex_error>which lualatex /usr/local/texlive/2015/bin/x86_64-linux/lualatex The zip file is in this folder (This is a link to the folder where the zip file is in. Not a direct link to the zip file). 80 MB size. Any other information I can give please let me know. Tags: errors (Prev Q) (Next Q) User: nasser

Answer by cfr 798

I can confirm this behaviour. To test: Create 1860 copies of example-image-1x1.pdf (or other image of your choosing) named 1.pdf, 2.pdf,..., 1860.pdf. If you use bash and you have TeX Live 2015 installed in the standard place, you can use the following commands:

i=0; while [ $i -le 1860 ] ; do ((i++)); cp /usr/local/texlive/current/texmf-dist/ Then create the following document: Skip code block

\documentclass{article} \usepackage{graphicx} \usepackage{expl3,xparse} \ExplSyntaxOn \int_new:N \l_nasser_loop_int \tl_new:N \l_nasser_file_tl \NewDocumentCommand \icing { } { \int_set:Nn \l_nasser_loop_int { 0 } \int_do_while:nNnn { \l_nasser_loop_int } < { 1860 } { \int_incr:N \l_nasser_loop_int \tl_set:Nn \l_nasser_file_tl { \int_use:N \l_nasser_loop_int } \includegraphics[width=\textwidth,height=\textheight,keepaspectratio]{\l_nasse } } \ExplSyntaxOff \begin{document} \icing \end{document} This compiles fine with pdflatex. With lualatex, it fails with the following error: lualatex: ./1024.pdf: Too many open files I will refrain from posting the output pdflatex produces: you will either have to take my word for it or follow the procedure above.

799

Tags: errors (Prev Q) (Next Q)

Q: MiKTeX’s LuaLaTeX and minitoc: ”I can’t write on file ...mtc” Tags: errors (Prev Q) (Next Q), miktex (Prev Q) (Next Q) When compiling the code below with LuaLaTeX I get the error: ”I can’t write on file ’test.mtc’”. Any ideas on how to resolve this? (Btw, the file test.mtc is there and contains the word ”Contents”) Skip code block \documentclass{report} \usepackage{lipsum} \usepackage[tight]{minitoc} \dominitoc[n] \begin{document} \tableofcontents \chapter{Test} \minitoc \lipsum \section{Test} \lipsum \subsection{Test} \lipsum \subsubsection{Test} \lipsum \end{document} Tags: errors (Prev Q) (Next Q), miktex (Prev Q) (Next Q) User: wox 800

Answer by ulrike-fischer There is a lonely \closein\@inputcheck\relax in minitoc.sty which imho belongs in the definition above it: Skip code block \documentclass{report} \usepackage{lipsum} \usepackage[tight]{minitoc} \makeatletter \def\[email protected]#1{% \@[email protected]\@[email protected] \[email protected]@checkfiles \IfFileExists{#1}{% \immediate\openin\@inputcheck #1\relax \[email protected]{}{\[email protected]@LI\relax}{\[email protected]}\[email protected] % }% {\@[email protected]}% \else \@[email protected]% \fi \closein\@inputcheck\relax}%moved in the definition \makeatother \dominitoc[n] \begin{document} \tableofcontents \chapter{Test} \minitoc \lipsum \section{Test} \lipsum \subsection{Test} \lipsum 801

\subsubsection{Test} \lipsum \end{document}

Tags: errors (Prev Q) (Next Q), miktex (Prev Q) (Next Q)

Q: How to place a dot below for example: e? Tags: errors (Prev Q) (Next Q), bugs (Next Q) After I updated my TL2016 (Windows) environment (10 minutes ago) compiling documents containing for example \d{e} or \d e throws an error message. The following MWE should demonstrate this: Skip code block \documentclass{book} \usepackage{fontspec} \usepackage[% main=english, ]{babel}% \begin{document} \chapter{How to place a dot below for example: e?} \d e The command throws the error messages:\\ Extra \textbackslash{}else. \textbackslash{}d e\\ Extra \textbackslash{}fi. \textbackslash{}d e \end{document} 802

Tags: errors (Prev Q) (Next Q), bugs (Next Q) User: latexfan

Answer by david-carlisle Line 84 of latex/base/tuenc.def is \relax\detokenize{#2}^^a0\else#2\fi Please edit to say \if\relax\detokenize{#2}\relax^^a0\else#2\fi I’ll get an update to the release this evening, sorry.

Tags: errors (Prev Q) (Next Q), bugs (Next Q)

Q: Who’s at fault with this error concerning csquotes and LuaLaTeX? Tags: errors (Prev Q) (Next Q) I ran into this with the package lilyglyphs but I’m not sure whose fault this error is. When I compile the following with lualatex: \documentclass{article} \usepackage{csquotes} \MakeOuterQuote{"} \EnableQuotes \begin{document} \directlua{print("hello")} \end{document} I get an error saying

803

\directlua]:1: unexpected symbol near '\'. l.6 \directlua{print("hello")} Now suppose that I do not directly write \directlua in my document, but I include a package that does it internally. Such as \documentclass{article} \usepackage{fontspec, csquotes, lilyglyphs} \MakeOuterQuote{"} \EnableQuotes \begin{document} \wholeNote \end{document} I have no knowledge why compilation fails, because the error now becomes ! Missing number, treated as zero.

\begingroup l.7 \end {document} From my user point of view I did nothing wrong, because I’m using the public API provided by the packages. The csquotes documentation specifically says: Note that all characters are automatically checked for validity as they are allocated. This package will reject characters which are unsuitable as active quotes... In sum, the following characters will be considered as reserved by this package: A–Z a–z 0–9 . , ; : ! ? ' - # $ % & ^ _ ` ~ \ @ * { } [ ] So my question is whose fault is this error? • My fault, the user’s fault, because I should have known (but how?) that even though the quote is not listed as unsuitable in the csquotes manual, it actually is? • The fault of the implementation or documentation of csquotes for failing to mention " as unsuitable? • The fault of the implementation of the \directlua command because it doesn’t prevent LaTeX catcode changes/active characters from im804

pacting its argument? • A shortcoming of TeX itself because of its global state based architecture? Tags: errors (Prev Q) (Next Q) User: marczellm

Answer by ulrike-fischer Your first example and your second are actually quite different errors. The first is your fault (see Davids answer), but the second is a bug in lilyglyphs lua code. But the problem is not the quote in \directlua. As the command is defined in lilyglyphs the catcode of the ” is frozen there and so not problematic. lilyglyphs uses tex.sprint to print the char, and the argument contains a ". As tex.sprint uses by default the current active catcode regime this explodes. You can tell tex.sprint to use another catcode table. (I’m not quite sure if \CatcodeTableLaTeX I used the best one, but it works): Skip code block \documentclass{article} \usepackage{fontspec, csquotes,lilyglyphs} %copied from lilyglyphs \begin{luacode} documentdata = documentdata or { } local stringformat = string.format local texsprint = tex.sprint local slot_of_name = luaotfload.aux.slot_of_name documentdata.fontchar = function (chr) local chr = slot_of_name(font.current(), chr, false) if chr and type(chr) == "number" then texsprint 805

(\the\CatcodeTableLaTeX, stringformat ([[\char"%X"]], chr)) end end \end{luacode} \MakeOuterQuote{"} \EnableQuotes \begin{document} \wholeNote \end{document}

Answer by david-carlisle Sorry but since you ask, I’d say it was your fault:-) Having made a character active you should have known to make it safe before passing to Lua. For example: \documentclass{article} \usepackage{csquotes} \MakeOuterQuote{"} \EnableQuotes \begin{document} \directlua{print(\string"hello\string")} \end{document} See Ulrike’s answer for the second example.

Tags: errors (Prev Q) (Next Q)

806

Q: How to raise a LaTeX warning from within Lua code? Tags: errors (Prev Q) (Next Q) I want to raise a warning from within Lua code. With advice from the LuaTeX wiki and LaTeX 2 for class and package writers, I arrived at the following (working) solution: \documentclass{article} \begin{document} Foo \directlua{ myvar = "\noexpand\\PackageWarning{mypackage}{Hello, I am a warning.}" tex.print(myvar) } \end{document} This seems unnecessarily complex, considering that raising an error is as easy as: \directlua{ tex.error("Hi, I'm an error!") } While I’m aware that tex.error is a generic TeX error and the warning I’m producing is a package-specific warning, I still think for both generic LaTeX warnings (if that exists?) and package-specific warnings (as well as package-specific errors, probably), there should be an easier way. Is there one? Tags: errors (Prev Q) (Next Q) User: doncherry

Answer by cybersingularity Someone who is more familiar with Lua will almost certainly have better ideas... egreg’s idea from the comments makes things slightly easier: consider using the [[...]] string syntax so you don’t need to escape the string (but 807

there will still be issues if the string itself contains a ]] etc), and use eTeX’s \unexpanded so you don’t need to worry so much about putting \noexpand everywhere. See also some of the suggestions about \directlua on a different question. As I previously mentioned in a comment, bypassing/emulating the LaTeX commands for this is probably not a good idea. LaTeX’s commands for this are slightly more complicated than you might first think, and might get patched/hooked into. Even rewriting LaTeX in Lua (replacing eg \PackageWarning with something that invokes a Lua script/function) wouldn’t necessarily help in the latter situation. I think the best you could do would be to write your own Lua function that invokes LaTeX’s \PackageWarning, taking care to escape parameters etc as appropriate. (Sorry, I’m not proficient enough to attempt that.) Compare the terminal output from the following: Skip code block

\documentclass{article} \PackageWarningNoLine{mypackage}{Hello, I am a warning} \PackageWarning{mypackage}{Hello, I am a warning} \directlua{ texio.write_nl("term and log", [[\unexpanded{Package mypackage Warning: Hello, I a tex.print([[\unexpanded{\PackageWarning{mypackage}{Hello, I am a warning}}]]); } \begin{document} \end{document} I have used "term and log" here because (as egreg explained), LaTeX normally writes to an \@unused stream that is never open, so the output appears both on the terminal and in the log file. The output is Package mypackage Warning: Hello, I am a warning.

Package mypackage Warning: Hello, I am a warning on input line 3.

808

Package mypackage Warning: Hello, I am a warning. Package mypackage Warning: Hello, I am a warning on input line 1. Note also that the line numbers from the Lua version are wrong, even when the real \PackageWarning command is invoked. For reference, some relevant definitions from latex.ltx: Skip code block \def\[email protected]@protect{\let\protect\string} \def\@spaces{\space\space\space\space} \ifnum\inputlineno=\[email protected] \let\[email protected]\@empty \else \def\[email protected]{ on input line \the\inputlineno} \fi \DeclareRobustCommand{\GenericWarning}[2]{% \begingroup \def\MessageBreak{^^J#1}% \[email protected]@protect \immediate\write\@unused{^^J#2\[email protected]^^J}% \endgroup } \def\PackageWarning#1#2{% \GenericWarning{% (#1)\@spaces\@spaces\@spaces\@spaces }{% Package #1 Warning: #2% }% } \def\PackageWarningNoLine#1#2{% \PackageWarning{#1}{#2\@gobble}% }

Tags: errors (Prev Q) (Next Q)

809

Q: How to get csquotes, polyglossia with german and hyperref work together? Tags: errors (Prev Q) (Next Q), polyglossia (Prev Q) (Next Q), hyperref (Prev Q) (Next Q) I found a strange problem which seems to be unique to the combination of polyglossia with german language together with csquotes and hyperref. Skip code block % XeLaTeX \documentclass{article} \usepackage{polyglossia} \setmainlanguage{german} \usepackage{csquotes} \MakeOuterQuote{"} \usepackage{hyperref} \begin{document} \section{Section with "quote"} "Quote in Text" \section{Section with \enquote{quote}} \enquote{Quote in Text} \end{document} Both, \enquote and the " shorthand, work fine in normal text but in section headings they cause this error (plus some following errors): ! Argument of " has an extra }.

\par l.16 \section{Section with \enquote{quote}} Theres no problem with \setmainlanguage{english} and with PDFLaTeX (and babel) it works too.

810

My workaround ist to use „quotes“ directly but it takes away the flexibility provided by csquotes.

Update The following MWE with also following file list still reproduces the error. Skip code block % XeLaTeX \documentclass{article} \usepackage{polyglossia} \setmainlanguage{german} \usepackage{csquotes} \MakeOuterQuote{"} \usepackage{hyperref} \begin{document} \section{Section with \enquote{quote}} \enquote{Quote in Text} \end{document} Skip code block *File List* article.cls size10.clo polyglossia.sty etoolbox.sty etex.sty makecmds.sty xkeyval.sty xkeyval.tex fontspec.sty expl3.sty expl3-code.tex

2007/10/19 v1.4h Standard LaTeX document class 2007/10/19 v1.4h Standard LaTeX file (size option) 2014/05/21 v1.33.5 Babel replacement for XeLaTeX and LuaTeX 2011/01/03 v2.1 e-TeX tools for LaTeX 1998/03/26 v2.0 eTeX basic definition package (PEB) 2009/09/03 v1.0a extra command making commands 2014/05/25 v2.7 package option processing (HA) 2014/05/25 v2.7 key=value parser (HA) 2014/06/21 v2.4a Font selection for XeLaTeX and LuaLaTeX 2014/09/15 v5423 L3 programming layer (loader) 2014/09/15 v5423 L3 programming layer 811

l3unicode-data.def 2014/08/12 v5276 L3 Unicode data l3xdvipdfmx.def xparse.sty 2014/09/15 v5423 L3 Experimental document command parser fontspec-patches.sty 2014/06/21 v2.4a Font selection for XeLaTeX and LuaLaTe X fontspec-xetex.sty 2014/06/21 v2.4a Font selection for XeLaTeX and LuaLaTeX fontenc.sty eu1enc.def 2010/05/27 v0.1h Experimental Unicode font encodings eu1lmr.fd 2009/10/30 v1.6 Font defs for Latin Modern xunicode.sty 2011/09/09 v0.981 provides access to latin accents and many oth er characters in Unicode lower plane eu1lmss.fd 2009/10/30 v1.6 Font defs for Latin Modern graphicx.sty 2014/04/25 v1.0g Enhanced LaTeX Graphics (DPC,SPQR) graphics.sty 2009/02/05 v1.0o Standard LaTeX Graphics (DPC,SPQR) trig.sty 1999/03/16 v1.09 sin cos tan (DPC) graphics.cfg 2010/04/23 v1.9 graphics configuration of TeX Live xetex.def 2014/07/25 v4.03 LaTeX color/graphics driver for XeTeX (RRM/JK) fontspec.cfg ifluatex.sty 2010/03/01 v1.3 Provides the ifluatex switch (HO) ifxetex.sty 2010/09/12 v0.6 Provides ifxetex conditional gloss-german.ldf polyglossia: module for german babelsh.def 2013/04/30 Babel common definitions for shorthands Taken verbatim from babel.def (2013/04/15 v3.9e) csquotes.sty 2011/10/22 v5.1d context-sensitive quotations csquotes.def 2011/10/22 v5.1d csquotes generic definitions csquotes.cfg hyperref.sty 2012/11/06 v6.83m Hypertext links for LaTeX hobsub-hyperref.sty 2012/05/28 v1.13 Bundle oberdiek, subset hyperref (HO) hobsub-generic.sty 2012/05/28 v1.13 Bundle oberdiek, subset generic (HO) hobsub.sty 2012/05/28 v1.13 Construct package bundles (HO) infwarerr.sty 2010/04/08 v1.3 Providing info/warning/error messages (HO) ltxcmds.sty 2011/11/09 v1.22 LaTeX kernel commands for general use (HO) ifvtex.sty 2010/03/01 v1.5 Detect VTeX and its facilities (HO) intcalc.sty 2007/09/27 v1.1 Expandable calculations with integers (HO) ifpdf.sty 2011/01/30 v2.3 Provides the ifpdf switch (HO) etexcmds.sty 2011/02/16 v1.5 Avoid name clashes with e-TeX commands (HO) kvsetkeys.sty 2012/04/25 v1.16 Key value parser (HO) 812

kvdefinekeys.sty 2011/04/07 v1.3 Define keys (HO) pdftexcmds.sty 2011/11/29 v0.20 Utility functions of pdfTeX for LuaTeX (HO) pdfescape.sty 2011/11/25 v1.13 Implements pdfTeX's escape features (HO) bigintcalc.sty 2012/04/08 v1.3 Expandable calculations on big integers (HO) bitset.sty 2011/01/30 v1.1 Handle bit-vector datatype (HO) uniquecounter.sty 2011/01/30 v1.2 Provide unlimited unique counter (HO) letltxmacro.sty 2010/09/02 v1.4 Let assignment for LaTeX macros (HO) hopatch.sty 2012/05/28 v1.2 Wrapper for package hooks (HO) xcolor-patch.sty 2011/01/30 xcolor patch atveryend.sty 2011/06/30 v1.8 Hooks at the very end of document (HO) atbegshi.sty 2011/10/05 v1.16 At begin shipout hook (HO) refcount.sty 2011/10/16 v3.4 Data extraction from label references (HO) hycolor.sty 2011/01/30 v1.7 Color options for hyperref/bookmark (HO) auxhook.sty 2011/03/04 v1.3 Hooks for auxiliary files (HO) kvoptions.sty 2011/06/30 v3.11 Key value format for package options (HO) pd1enc.def 2012/11/06 v6.83m Hyperref: PDFDocEncoding definition (HO) hyperref.cfg 2002/06/06 v1.2 hyperref configuration of TeXLive url.sty 2013/09/16 ver 3.4 Verb mode for urls, etc. hxetex.def 2012/11/06 v6.83m Hyperref driver for XeTeX puenc.def 2012/11/06 v6.83m Hyperref: PDF Unicode definition (HO) stringenc.sty 2011/12/02 v1.10 Convert strings between diff. encodings (HO) rerunfilecheck.sty 2011/04/15 v1.7 Rerun checks for auxiliary files (HO) t3cmr.fd 2001/12/31 TIPA font definitions nameref.sty 2012/10/27 v2.43 Cross-referencing by name of section gettitlestring.sty 2010/12/03 v1.4 Cleanup title references (HO) csquotes-section.out csquotes-section.out se-ascii-print.def 2011/12/02 v1.10 stringenc: Printable ASCII characters *********** Tags: errors (Prev Q) (Next Q), polyglossia (Prev Q) (Next Q), hyperref (Prev Q) (Next Q) User: tobi

Answer by egreg The quoting mechanism using " conflicts with the Babel shorthands that 813

German polyglossia sets up. This actually happens also with pdflatex and babel, where the " used for quoting simply kills the babel shorthands without warning. So the method can be recommended neither with babel nor with polyglossia. If you really don’t need the shorthands, do \usepackage{polyglossia} \setmainlanguage{german} \shorthandoff{"} \usepackage{csquotes} \MakeOuterQuote{"}

Tags: errors (Prev Q) (Next Q), polyglossia (Prev Q) (Next Q), hyperref (Prev Q) (Next Q)

Q: Outputfile generated on error Tags: errors (Prev Q) (Next Q) If I run this example: \documentclass{article} \begin{document} Foo \newpage \barbaz \end{document} using lualatex --halt-on-error minimal.tex The log yields: !

==> Fatal error occurred, no output PDF file produced!

814

However, a file minimal.pdf is created (although I cannot open it). This seems to occur due to the first page being written. This confuses my buildsystem. pdflatex does not create such a file. How do I switch lualatex to the expected behavior? Is this a bug? Tags: errors (Prev Q) (Next Q) User: choeger

Answer by akira-kakuto There was a bug in pdfgen.w, that the condition to remove a broken pdf in the case of a fatal error was wrong. Thus the broken pdf was not removed. As an answer, we have to wait for the next release, or have to build a new binary ourselves by using sources which will be updated soon.

Tags: errors (Prev Q) (Next Q)

Q: l3names error in lualatex (\reserveinserts{32}) Tags: errors (Prev Q) I have the following ’test file’ in which I am working, works without problems when compiling with ’(La/Xe/pdf) TeX’ but throws an error when compiling with ’LuaLaTeX’: Skip code block Package: l3names 2012/09/24 v4230 L3 Namespace for primitives ) Runaway argument? ! Forbidden control sequence found while scanning use of \next.

\par l.66 \reserveinserts 815

{32} I suspect you have forgotten a `}', causing me to read past where you wanted me to stop. I'll try to recover; but if the error is serious, you'd better type `E' or `X' now and fix your file. the file is as follows: Skip code block

\documentclass{article} \usepackage{soulutf8} \usepackage[math]{blindtext} \usepackage{xwatermark} %\usepackage[verbose=silent]{microtype} \usepackage{xcolor} \usepackage{ifpdf,ifluatex,ifxetex} \newif\ifxetexorluatex \ifxetex \xetexorluatextrue \else \ifluatex \xetexorluatextrue \else \xetexorluatexfalse \fi \fi \ifxetexorluatex \usepackage[no-math]{fontspec} \setmainfont[Ligatures=TeX,RawFeature=+onum]{Linux Libertine O} \setsansfont[RawFeature=+pnum]{Linux Biolinum O} \newfontfamily{\biolinum}{Linux Biolinum O} \newcommand{\bitext}[1]{\biolinum #1}% \newwatermark[allpages,fontsize=2.0cm,align=center,color=gray!45,angle=45,xpos \else \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage{fourier} \usepackage[rm]{libertine} 816

\renewcommand{\sfdefault}{LinuxBiolinumO-LF} \newwatermark[allpages,color=gray!45,angle=45,fontfamily=LinuxBiolinumO-OsF,sc \fi \begin{document} \sodef\textss{}{.3em}{0.6em}{0pt} \noindent \begin{center} \textbf{\textss{\large\scshape «Universidad de Concepci\'{o}n»}} \end{center} \Blinddocument \end{document} Use ’TexLive 2012’ in Win32/Linux (updated). Check the documentation of l3names, but it is a ’little’ advanced for my level, any suggestions or help would be appreciated. regards Pablo Tags: errors (Prev Q) User: pablo-gonzález-l

Answer by heiko-oberdiek A minimal example would have been: \documentclass{article} \usepackage{xwatermark} \usepackage{fontspec} \begin{document} \end{document} After analysis the example becomes: \RequirePackage{catoptions}% loaded by xwatermark \outer\def\foo{}% outer macro as \reserveinserts \RequirePackage{capt-of}% package does not matter \foo \csname @@end\endcsname % end of job, after the error Or \RequirePackage{catoptions} 817

\outer\def\foo{} \makeatletter \ifnextcharTF[{\typeout{yes}}{\typeout{no}}\foo \@@end After \RequirePackage[options]{package} there is an additional optional argument for a minimal requested release date. These macros are redefined by package catoptions. However the test for an optional [ not only uses the usual \futurelet, but the next token is also read in as macro argument (\[email protected]@xtcharacter). That fails if the next token is an outer macro. Workaround: \documentclass{article} \usepackage{xwatermark}% or catoptions \makeatletter \let\[email protected]@ifbrack\[email protected] \renewcommand*{\[email protected]}{\@ifnextchar[} \makeatother ...

Answer by ahmed-musa Thanks to Heiko. I will upload an update of catoptions to CTAN. In the meantime here is a patch. The problem wasn’t due to a bug: \outer is an odd type that I didn’t foresee could appear. Master Heiko knows why I am rather wary of LaTeX kernel’s \@ifnextchar. Skip code block \documentclass{article} \usepackage{xwatermark} \makeatletter % Copy this to end of catoptions: \edef\[email protected]@[email protected]{% \unexpanded{\expandafter\[email protected]@[email protected]@a\meaning\@[email protected]}% \detokenize{outer macro}:\[email protected] } \edef\[email protected]{% \def\noexpand\[email protected]@[email protected]@a##1\detokenize{outer macro}:##2\[email protected] 818

} \[email protected]{\@nameuse{@\ifblankTF{#2}{second}{first}oftwo}} \def\[email protected]#1#2#3{% \ifcase0% \ifcat\noexpand\@[email protected]\bgroup 1\fi \ifcat\noexpand\@[email protected]\egroup 1\fi \[email protected]@[email protected]{1}{0}\relax \let\next\[email protected]@xtcharacter \else \def\next{\endgroup\[email protected]}% \fi \next{#1}{#2}{#3}% } % End of patch. \makeatother \usepackage{soulutf8} \usepackage[math]{blindtext} \usepackage{xcolor} \usepackage{ifpdf,ifluatex,ifxetex} \newif\ifxetexorluatex \ifcase0\ifxetex\else\ifluatex\else 1\fi\fi\relax\xetexorluatextrue\fi \ifboolTF{xetexorluatex}{% \usepackage[no-math]{fontspec} \setmainfont[Ligatures=TeX,RawFeature=+onum]{Linux Libertine O} \setsansfont[RawFeature=+pnum]{Linux Biolinum O} \newfontfamily{\biolinum}{Linux Biolinum O} \newcommand{\bitext}[1]{\biolinum #1}% \newwatermark[allpages,fontsize=2.0cm,align=center,color=gray!45, angle=45,xpos=0,ypos=0]{\textbf{\bitext{Preliminar 2012}}} }{% \usepackage[T1]{fontenc} \usepackage[utf8]{inputenc} \usepackage{fourier} % There is a problem with the option 'rm' for libertine: % \usepackage[rm]{libertine} \usepackage{libertine} \renewcommand{\sfdefault}{LinuxBiolinumO-LF} \newwatermark[allpages,color=gray!45,angle=45, 819

fontfamily=LinuxBiolinumO-OsF,scale=2.5,xpos=0,ypos=0]{Preliminar 2012} }% \begin{document} \sodef\textss{}{.3em}{0.6em}{0pt} \begin{center} \textbf{\textss{\large\scshape «Universidad de Concepci\'{o}n»}} \end{center} \noindent\Blinddocument \end{document} Here is a fuzz: \outer\def\foo{} \iftrue\ifnextcharTF*\relax\relax\foo\fi \iftrue\ifnextcharTF*\relax\relax\fi \ifnextcharTF*\relax\relax\iftrue\fi

Tags: errors (Prev Q)

Microtype Skip to questions, Wiki by user n.n. microtype is a package that provides a LaTeX interface to the microtypographic extensions that were introduced by pdfTeX and have since also propagated to LuaTeX and XeTeX: most prominently, character protrusion and font expansion, furthermore the adjustment of interword spacing and additional kerning, as well as hyphenatable letterspacing (tracking) and the possibility to disable all or selected ligatures.

820

Questions Q: How to set expansion and protrusion for TeX Gyre Pagella using LuaLaTeX? Tags: microtype (Prev Q) (Next Q), protrusion (Prev Q) (Next Q) For my documents, I have often used the mathpazo package combined with microtype and have found the result to be really good. Because now I need to create PDFs which contain a variety of diacritics and which should be easy to copy from, I have decided to use LuaTeX with TeX Gyre Pagella. Initially I had difficulty getting microtype to work, but thanks to Alabay’s answer in How to set-up LuaTeX, Microtype, with Minion Pro, Myriad Pro I have made it. Still, I’m struggling with protrusion settings. Given the following code: Skip code block \documentclass[a4paper, 12pt, oneside, article]{memoir} \usepackage{fontspec} \defaultfontfeatures{Ligatures=TeX} \newfontfeature{Microtype}{protrusion=default;expansion=default;} \setmainfont[Microtype,Numbers=OldStyle]{TeX Gyre Pagella} \usepackage{microtype} \usepackage{blindtext} \begin{document} \blindtext \end{document}

821

LuaTeX produces this: I must say I don’t quite like the fact that the punctuation marks protrude so far from the margin. Is there a way I can change the default settings? I have tried to do this in various ways (e.g. by changing factor in microtype), but to no success. Ideally, I would like to get a similar result as when I run pdfTeX with mathpazo:

Another (but related) thing is setting expansion for TeX Gyre Pagella. Can 822

I do it, and if so, how? Tags: microtype (Prev Q) (Next Q), protrusion (Prev Q) (Next Q) User: jemp

Answer by ulrike-fischer You can change the default factor like this (5 is not a sensible value but shows the effect quite good: Skip code block \documentclass[a4paper, 12pt, oneside, article]{memoir} \usepackage{fontspec} \defaultfontfeatures{Ligatures=TeX} \newfontfeature{Microtype}{protrusion=default;expansion=default;} \directlua{fonts.protrusions.setups.default.factor=5} \setmainfont[Microtype,Numbers=OldStyle]{TeX Gyre Pagella} \usepackage{microtype} \usepackage{blindtext} \begin{document} \blindtext \end{document} For a more fine grained change you should copy the default table from otfl-font-dum.lua (fonts.protrusions.setups['default']). Move it to e.g. prottest.lua, change default to test, adapt the values and then use it like this: \directlua{require("prottest.lua");} \newfontfeature{Microtype}{protrusion=test;expansion=default;} (I didn’t test this recently so I’m not sure if this still works.)

Tags: microtype (Prev Q) (Next Q), protrusion (Prev Q) (Next Q)

823

Q: hanging punctuation with microtype and luaLaTeX Tags: microtype (Prev Q) (Next Q)

I want to get this style of hanging punctuation: Quotation marks «...» „...“, brackets (...) [...] {...} and bullets are put beyond the left margin. Quotation marks, brackets, periods, and commas are set outside the right margin. Hyphens (both in compound words and between the syllables of a word that’s divided at the end of a line) should not fall outside the margin full-length, but rather be hung one third or half of their length. I try to achieve this by using the \SetProtrusion command according to the manual (page 12): Skip code block

% !TeX encoding = UTF-8 % !TeX TS-program = lualatex \documentclass[a4paper,14pt]{extarticle} \usepackage[russian]{babel} \usepackage{fontspec} \usepackage{xltxtra} \usepackage{csquotes} \defaultfontfeatures{Renderer=Basic,Mapping=tex-text,Scale=MatchLowercase} \setmainfont{Charis SIL}[Mapping=tex-text,Scale=MatchLowercase] \setromanfont{Charis SIL}[Mapping=tex-text,Scale=MatchLowercase] \setsansfont{PT Sans}[Mapping=tex-text,Scale=MatchLowercase] \setmonofont{PT Mono}[Mapping=tex-text,Scale=MatchLowercase] \usepackage[protrusion=true,expansion=true,final,babel=true,factor=2000]{microtype \SetProtrusion {encoding = *} 824

{ \textquotedblleft = {4000, }, \textquotedblright = { ,4000}, . = { , 4000} « = {4000, }, » = { ,4000}, ( = {4000, }, ) = { ,4000} }

\begin{document} \noindent\enquote{������������� ������������ �������� �������� �� ����������������� ������� �������� �, ����� ���� ��� ��� �������������� ����� ���) ���� ����� ������ ������ (��� ������� ����! ��� ����� ����. ������� ������� ���� ����������� ���...) � «������������� ������������ �������� �������� �� ����������������� ������� �������� �, ����� ���� ��� ��� ������, �� (������ � ���� �������������� ����� ���) ���� ����� ������ ������ (��� ������� ����! ��� ����� ����. ������� ������� ���� ����������� ���...) � \end{document} But it doesn’t work:

(If it matters, I use LuaLaTeX from MikTeX on Windows 7) Tags: microtype (Prev Q) (Next Q) User: max

Answer by robert 825

Your settings are never applied because in the first argument to \SetProtrusion you only specify the encoding. microtype will always try to load the best matching settings, and since settings for Charis SIL exist, they will be applied instead. Drawing from this answer, you can overwrite settings by first loading the configuration file and then redefining these settings: Skip code block \usepackage[protrusion=true,expansion=true,final,babel=true]{microtype} % default \LoadMicrotypeFile{CharisSIL} \SetProtrusion [ name = Charis-default ] { } { \textquotedblleft = {1000, }, \textquotedblright = { ,1000}, \quotedblbase = {1000, }, % = „ . = { , 1000}, % there was a comma missing here {,} = { , 1000}, % this comma needs to be masked « = {1000, }, » = { ,1000}, ( = {1000, }, ) = { ,1000}, - = { ,500} } For the other shapes, you can then simply load these settings: \SetProtrusion [ name = Charis-it, load = Charis-default ] {}{} \SetProtrusion [ name = Charis-sc, load = Charis-default ] {}{} (I must say that I find these settings weird, since they are contrary to the idea that microtypographical tweaks should be discreet and not jump out at 826

the reader – as elaborated here)

Tags: microtype (Prev Q) (Next Q)

Q: How can I fix a problem where italics prevent line breaking when using microtype? Tags: microtype (Prev Q) (Next Q), protrusion (Prev Q) (Next Q) I wish to use protrusion and expansion from microtype as I like the look you get with them. I use amsthm and typeset theorems in italic as usual (with \theoremstyle{plain}). With microtype enabled, LaTeX fails to break some lines where the last item on the line is something in italic. I get three failures to break nicely with my included example. I have microtype 2.5 and use lualatex with Latin Modern Roman. I have a working example, though it’s not very minimal. If I remove much more the ancillary changes to formatting hide the problem I suspect is a bug. The issue doesn’t seem to be with the fact I’m using hyphenated words like Erdos-Hajnal, since the line break failure also occurs on other lines, and problems even occur in my bibliography where some portions of the reference text are in italics. The problem also occurs for me if I remove the \usepackage{fontspec} line. If I remove that line and compile with pdflatex there are no problems. (Fairly) Minimal Example: Skip code block \documentclass[a4paper,twoside]{scrartcl} \usepackage[UKenglish]{babel} \usepackage{amsmath,amsthm} \usepackage{fontspec,blindtext} \usepackage[babel,protrusion=true,expansion]{microtype} \theoremstyle{plain} 827

\newtheorem{thm}{Theorem}[section] \newtheorem{prop}[thm]{Proposition} \newtheorem{conj}[thm]{Conjecture}

\begin{document} \begin{conj} For all graphs $H$ there is an $\epsilon > 0$ such that for all sufficiently large \end{conj} \begin{prop} A short dummy paragraph.

Let $\epsilon_2=\delta\epsilon_1$, where $\deltafor /F "usebackq" %f in (`kpsewhich hyph-de-1901.lic.txt`) do more "%f" on the command-line. Note the backquotes surrounding the kpsewhich calls!

Answer by topskip I’ve got no error when compiling with LuaTeX, but hyphsubst doesn’t seem to work with LuaTeX. You can verify by running the following document with LuaTeX: \RequirePackage[german=ngerman-x-latest]{hyphsubst} \documentclass{minimal} \usepackage[german]{babel} \begin{document} \showhyphens{Meister} \end{document} It should report Meis-ter but reports Mei-ster. With luatex -recorder test.tex you can look into the generated .fls file and see that only the file hyph-de-1901.pat.txt gets loaded.

Answer by egreg hyphsubst simply changes the number associated to the control sequence that LaTeX uses when choosing a language.

872

For instance \selectlanguage{ngerman} executes, among other things, \language\[email protected] and \[email protected]man is defined at format creation to be the number "1E (on my machine, it can vary according to the language.dat file). The number corresponding to ngerman-x-latest is (on my machine) "4. When one says \RequirePackage[german=ngerman-x-latest]{hyphsubst} the basic action is to change the meaning of \[email protected] into "4; more precisely, the action is \chardef\[email protected]=\csname [email protected]\endcsname Of course, if the languages are not preloaded, as it happens with LuaLaTeX, this can’t work (precautions are taken in the package so as a correct assignment is performed even if the meaning of \csname [email protected]\endcsname was \relax). That’s why we end with the patterns for English, I guess. A possible step towards a solution Apparently, LuaLaTeX knows about the correct numbers, so what’s needed is to force loading the correct language. A test: Skip code block \documentclass{article} %% print the numbers \typeout{ngerman: \number\csname [email protected]\endcsname} \typeout{ngerman-x-latest: \number\csname [email protected]\endcsname} \usepackage{hyphsubst} \usepackage[ngerman]{babel} \begin{document}

873

\typeout{Current language: \number\language} \HyphSubstLet{ngerman}{ngerman-x-latest} \typeout{Current language: \number\language} \end{document} The relevant part of the log file shows ngerman: 30 ngerman-x-latest: 4 [...] Current language: 30 Current language: 4 so the value of \language seems to be correctly set. However the .fls file reports only

INPUT /usr/local/texlive/2011/texmf-dist/tex/generic/hyph-utf8/patterns/txt/hyph-d INPUT /usr/local/texlive/2011/texmf-dist/tex/generic/hyph-utf8/patterns/txt/hyph-d INPUT /usr/local/texlive/2011/texmf-dist/tex/generic/hyph-utf8/patterns/txt/hyph-d which seems to mean that the hyphenation patterns for ngerman-x-latest are not loaded. I’ve tried to add something like %% Load the new language \setbox0=\vbox{ \everypar{}\begin{hyphenrules}{ngerman-x-latest}abc\end{hyphenrules} } in the preamble or in the document, in order to see if the patterns are loaded, but this doesn’t seem so.

Tags: hyphenation (Prev Q) (Next Q)

874

Q: How to avoid a linebreak before a comma in Lua(La)TeX? Tags: hyphenation (Prev Q) (Next Q) This is a (somewhat late) follow up to the question How to avoid a linebreak before a comma? where @MostlyHarmless shows that a line break may be introduced after a word ending with a hyphen even if it is followed by a comma. In the comments section of that question @topskip says: If you use LuaTeX, we could provide you a solution that forbids a line break before a comma. So here I’d like to find a solution in Lua(La)TeX. The MWE to work with is the same: \documentclass[11pt, a4paper]{scrartcl} \usepackage[ngerman]{babel} \begin{document}

aaDas ist ein Absatz. Das ist ein Absatz. Das ist ein Absatz. Es gibt zeit-, tempe \end{document}

And the output is the same as well: Tags: hyphenation (Prev Q) (Next Q) User: georgd

Answer by michal.h21 You can use simple node processing callback to do that. I’ve created simpl package containg such callback, hyphencomma.sty: Skip code block \ProvidesPackage{hyphencomma} 875

\RequirePackage{luacode}

\begin{luacode*} local glyph_id = node.id "glyph" local penalty_id = node.id "penalty" local hyphenc = string.byte "-" local commac = string.byte "," local function prevent_hyphencomma(head) for n in node.traverse_id(glyph_id,head) do if n.char == hyphenc then -- we need to find node after the next node. directly following is automatic local next = n.next.next if next.id == glyph_id and next.char == commac then -- create penalty node local penalty = node.new("penalty") penalty.penalty = 10000 -- remove discretionary head = node.remove(head,n.next) -- insert penalty head = node.insert_after(head, n, penalty) end end end return head end

luatexbase.add_to_callback("pre_linebreak_filter", prevent_hyphencomma, "Prevent h \end{luacode*} \endinput The prevent_hypencomma function processes nodes of each paragraph before the linebreak. There are many node types, but most important for are glyph nodes, which contains particular characters. To match nodes of this type, we must know it’s node id, which we can find with: 876

local glyph_id = node.id "glyph" with node.traverse_id iterator, we process the node list, filtering only nodes with glyph id. Each node has some fields, depending on its type. We can find glyphs character code with char field. It is character number, not string, so we must test for hyphen char code, not -. For ASCII characters, we can get the char code with string.byte function. After each hyphen glyph, discretionary node is inserted, so we need to skip it to find next node and test it whether it is comma glyph. If it is, we must remove the discretionary node and insert penalty to prevent the linebreak. The result:

Tags: hyphenation (Prev Q) (Next Q)

Q: Latin text not hyphenated at all with LuaLaTeX and polyglossia Tags: hyphenation (Prev Q) (Next Q), polyglossia (Prev Q) (Next Q) I recently noticed that there are numerous under- and overfull hboxes in the document I’m working on. Further inspection revealed that such problems almost always arose when there was Latin text involved; seemingly, LaTeX doesn’t see any hyphenation points, so it can’t break lines and paragraphs end up looking ugly. This is a MWE: Skip code block \documentclass{article}

877

\usepackage{polyglossia} \setdefaultlanguage{english} \setotherlanguage[variant=classic]{latin} \begin{document} \showhyphens{\textenglish{amusing}} \showhyphens{\textlatin{instigare}} \end{document} Compiling this code with LuaLaTeX yields a log file; here are the relevant fragments: [][] \EU2/lmr/m/n/10 amus-ing [][] \EU2/lmr/m/n/10 instigare Omitting the variant option of the Latin language (variant=classic) does not change the result. I have left out some things, such as the font setup, which, from what I have seen in my investigations, is involved in the matter (don’t know why, though). However, I hope the example provided is enough — if it isn’t, please, ask. For the record, this question seems somewhat relevant, although I haven’t been able to extrapolate the results to my case. EDIT: This is another MWE aimed at XeLaTeX, under which -as pointed out by egreg- it seems to work: Skip code block \documentclass{article} \usepackage{polyglossia} \usepackage{xltxtra} \setdefaultlanguage{english} \setotherlanguage[variant=classic]{latin} \begin{document} \showhyphens{\textenglish{amusing}} \showhyphens{\textlatin{instigare}} 878

\end{document} In the corresponding log file: \EU1/lmr/m/n/10 amus-ing []\EU1/lmr/m/n/10 in-sti-gare Tags: hyphenation (Prev Q) (Next Q), polyglossia (Prev Q) (Next Q) User: kalrish

Answer by egreg It’s a bug in gloss-latin.ldf that doesn’t advertise the pattern file name for LuaLaTeX. Workaround: do it yourself. Skip code block \documentclass{article} \usepackage{polyglossia} \setdefaultlanguage{english} \setotherlanguage[variant=classic]{latin} \setotherlanguage{italian} \makeatletter \def\[email protected]{% \language=\[email protected] \[email protected]@[email protected]@ii{classiclatin}% } \makeatother

\begin{document} \message{\the\language -->}\showhyphens{amusing} \begin{otherlanguage*}{latin} 879

\message{\the\language -->}\showhyphens{instigare} \end{otherlanguage*} \begin{otherlanguage*}{italian} \message{\the\language -->}\showhyphens{istigare} \end{otherlanguage*} \end{document} Here’s the output on the terminal; note that 54 is exactly the number assigned to the classic Latin hyphenation patterns. 0--> Underfull \hbox (badness 10000) in paragraph at lines 16--16 [][] \EU2/lmr/m/n/10 amus-ing 54--> Underfull \hbox (badness 10000) in paragraph at lines 19--19 [][] \EU2/lmr/m/n/10 in-sti-gare 51--> Underfull \hbox (badness 10000) in paragraph at lines 23--23 [][] \EU2/lmr/m/n/10 isti-ga-re

Answer by arthur-reutenauer I have fixed the bug in Polyglossia with this commit and will make an upload to CTAN shortly. Many thanks to Enrico for investigating and suggesting a workaround.

Tags: hyphenation (Prev Q) (Next Q), polyglossia (Prev Q) (Next Q)

Q: Does polyglossia with LuaLaTeX hyphenate greek text? Tags: hyphenation (Prev Q) (Next Q), polyglossia (Prev Q) (Next Q) Is there a way to tell polyglossia to hyphenate a Greek text when run with LuaLaTeX? I tried quite a lot (greek as defaultlanguage, as 880

backgroundlanguage, as otherlanguage, with german, with english, with this and that font, \let\greektext\relax ...), but whatever I do, it doesn’t hyphenate. Sometimes LuaLaTeX hyphenates with babel and XeLaTeX hyphenates with nearly the same usepackages, though the gets somewhat bolder and fuzzy under XeLaTeX (why???), so I prefer LuaLaTeX. The answers to similar question in this forum don’t help me at all. The most miminimal WE looks like this: Skip code block

% -*- mode: latex; TeX-engine: luatex; coding: utf-8; -*\documentclass[paper=a6]{scrartcl} \usepackage{showhyphens} \usepackage{fontspec} \newfontfamily\greekfont{GFS Porson} \usepackage{polyglossia} \setdefaultlanguage[variant=ancient]{greek} \begin{document} ΣΩ.\quad Ο����� ������, � ��� ����, ��������, �� � ��� �������� �� ����� Φ������ ��� Π���������, Μ����������� �

� �� ��� �� ������� �������� �� �’\,�� ������ ������� �������� ��� ����� �� ��� ���� ���� �� ��� ������� ��� ������ ��

���� ��� ����� �� ��� ����� ��� ��������, � �� ������� �� ��������� ����� �� ���� ��� �����, � ����� ���������� ��� ��� \end{document} Tags: hyphenation (Prev Q) (Next Q), polyglossia (Prev Q) (Next Q) User: alexander-wittmann

Answer by ulrike-fischer Hyphenation seems to work fine with babel (but I don’t understand greek): Skip code block \documentclass[paper=a6]{scrartcl} \usepackage{showhyphens} \usepackage{fontspec} \newfontfamily\greekfont{GFS Porson} \usepackage[greek]{babel} 881

\languageattribute{greek}{ancient} \begin{document} \greekfont ΣΩ.\quad Ο����� ������, � ��� ����, ��������, �� � ��� �������� �� ����� Φ������ ��� Π���������,

� �� ��� �� ������� �������� �� �’\,�� ������ ������� �������� ��� ����� �� ��� ���� ���� �� ��� ������� ��� ������ ��

���� ��� ����� �� ��� ����� ��� ��������, � �� ������� �� ��������� ����� �� ���� ��� �����, � ����� ���������� ��� ��� \end{document}

Tags: hyphenation (Prev Q) (Next Q), polyglossia (Prev Q) (Next Q)

Q: How to disable hyphenation in lualatex? Tags: hyphenation (Prev Q) (Next Q) I am using the mechanism outlined in this answer to generate a text-only version of a fairly complex document for spell-checking. This is my first attempt to use lualatex, so this might be littered with issues, but for the most part it does what I want it to do: Skip code block \documentclass{article} \usepackage{luatexbase} \usepackage{lipsum} \usepackage{filecontents} \usepackage{ifluatex} \begin{filecontents*}{luaFunctions.lua} -- clear the file file = io.open("output.txt", "w") file:write() exportParagraph = false function exportText (head) 882

if exportParagraph == false then --if you return nil no pdf will be created -- return nil return head end -- open the file in append-modus local out = io.open("output.txt", "a") local wordCounter = 0 -- loop over all hboxes in the current paragraph for line in node.traverse_id (node.id("hlist"), head) do -- loop over each element in the line for item in node.traverse (line.list) do -- check if the element is a char if item.id == node.id("glyph") then out:write(string.char(item.char)) -- check if the element is a 'space' elseif item.id == node.id("glue") then wordCounter = wordCounter + 1 out:write(" ") end end -- a newline in the file after each (tex)line out:write("\n") end wordCounter = wordCounter - 1 out:write("Words: "..wordCounter.."\n") -- a newline in the file after each paragraph out:write("\n") assert(out:close()) exportParagraph = false

883

--if you return nil no pdf will be created -- return nil return head end

function disableLigatures(head) -- disable ligatures end function SetExportParagraph(export) exportParagraph = export end luatexbase.add_to_callback("ligaturing", disableLigatures, "disableLigatures") luatexbase.add_to_callback("post_linebreak_filter", exportText, "exportText") \end{filecontents*} \ifluatex \directlua{dofile("luaFunctions.lua")} \fi \def\exportParagraph{% \ifluatex \directlua{SetExportParagraph(true)} \fi }

\begin{document} \exportParagraph ff fi Lorem ipsum dolor sit amet, \textbf{consectetuer adipiscing elit. Ut purus e vestibulum ut, placerat ac, adipiscing vitae, felis.} Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna. Donec vehicula augue eu neque. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Mauris ut leo. Cras viverra metus rhoncus sem. Nulla et lectus vestibulum urna fringilla ultrices. Phasellus eu tellus sit amet tortor gravida placerat. Integer sapien est, iaculis in, pretiu quis, viverra ac, nunc. Praesent eget sem vel leo ultrices bibendum. Aenean 884

faucibus. Morbi dolor nulla, malesuada eu, pulvinar at, mollis ac, nulla. Curabitur auctor semper nulla. Donec varius orci eget risus. Duis nibh mi, congue eu, accumsan eleifend, sagittis quis, diam. Duis eget orci sit amet orci dignissim rutrumrutrumrutrumrutrumrutrumrutrumrutrumrutrumrutrumrutrumrutrumrutrumrutrumrutr

Nam dui ligula, fringilla a, euismod sodales, sollicitudin vel, wisi. Morbi auctor lorem non justo. Nam lacus libero, pretium at, lobortis vitae, ultricies et tellus. Donec aliquet, tortor sed accumsan bibendum, erat ligula aliquet magna, vitae ornare odio metus a mi. Morbi ac orci et nisl hendrerit mollis. Suspendisse ut massa. Cras nec ante. Pellentesque a nulla. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aliquam tincidunt urna. Nulla ullamcorper vestibulum turpis. Pellentesque cursus luctus mauris. \exportParagraph Nulla malesuada porttitor diam. Donec felis erat, congue non, volutpat at, tincidunt tristique, libero. Vivamus viverra fermentum felis. Donec nonummy pellentesque ante. Phasellus adipiscing semper elit. Proin fermentum massa ac quam. Sed diam turpis, molestie vitae, placerat a, molestie nec, leo. Maecenas lacinia. Nam ipsum ligula, eleifend at, accumsan nec, suscipit a, ipsum. Morbi blandit ligula feugiat magna. Nunc eleifend consequat lorem. Sed lacinia nulla vitae enim. Pellentesque tincidunt purus vel magna. Integer non enim. Praesent euismod nunc eu purus. Donec bibendum quam in tellus. Nullam cursus pulvinar lectus. Donec et mi. Nam vulputate metus eu enim. Vestibulum pellentesque felis eu massa. \end{document}

In the generated output, the nonsense word rutrumrutrumrutrumrutrumrutrumrutrumrutrumrutr at the end of the first paragraph will be hyphenated: [...] ac, nulla. Cur- abitur auctor semper nulla. Donec varius orci eget risus. Duis nibh mi, congue eu, accumsan eleifend, sagittis quis, diam. Duis eget orci sit amet orci dignissim rutrumrutrumrutrumrutrumrutrumrutrumrutrumrutrumrutrumrutrumrutrumrutrumrutrumrutrum. Words: 134 This happens throughout my entire text and makes spell-checking the text 885

rather hard. Is there a way to disable hyphenation for this hack (I’m hesitant to call it a solution) entirely? Tags: hyphenation (Prev Q) (Next Q) User: vwegert

Answer by michal.h21 There exists several node processing callbacks in luatex, post_linebreak_filter which you use is not best for your purpose, as you have to deal with node lists broken into lines. Much more suitable is pre_linebreak_filter, which is called before line break. I also found some bugs in your code, which showed when I tried to use fontspec package and some non ascii characters. First I will post modified file: Skip code block \documentclass{article} \usepackage{luatexbase} \usepackage{fontspec} %\setmainfont{TeX Gyre Schola} \usepackage{lipsum} \usepackage{filecontents} \usepackage{ifluatex} \begin{filecontents*}{luaFunctions.lua} -- clear the file local file = io.open("output.txt", "w") file:write() file:close() local char = unicode.utf8.char exportParagraph = false function exportText (head, listtype) --[[ 886

-- it is better to solve this using attributes if exportParagraph == false then --if you return nil no pdf will be created -- return nil return head end --]] -- open the file in append-modus local out = io.open("output.txt", "a") local wordCounter = 0 local charcount = 0 local function traverse(h) local word = false for item in node.traverse (h) do local skip = node.has_attribute(item, luatexbase.attributes.wordcounton) if skip == 2 then -- check if the element is a char if item.id == node.id("glyph") then if node.is_node(item.components) then traverse(item.components) else out:write(char(item.char)) charcount = charcount + 1 word = true end elseif item.id == node.id("hlist") or item.id == node.id("vlist") or item.id == node.id("insert") or item.id == node.id("adjust") then -- out:write(item.id..","..item.subtype.."[") traverse(item.head) -- out:write "]" -- check if the element is a 'glue'. this means not only space elseif item.id == node.id("glue") and item.subtype == 0 then -- glue nodes doesn't have to be spaces, count only after word 887

if word then wordCounter = wordCounter + 1 charcount = charcount + 1 end word = false out:write(" ") end end end -- if word then wordCounter = wordCounter + 1 end end -- loop over all hboxes in the current paragraph --for line in node.traverse_id (node.id("hlist"), head) do -- loop over each element in the line traverse(head) -- a newline in the file after each (tex)line out:write("\n") --end -- wordCounter = wordCounter - 1 out:write("Words: "..wordCounter) out:write(", characters: "..charcount) out:write(", list type: "..listtype.."\n") -- a newline in the file after each paragraph out:write("\n") assert(out:close()) --exportParagraph = false --if you return nil no pdf will be created -- return nil return head end

function disableLigatures(head) 888

-- disable ligatures end function SetExportParagraph(export) exportParagraph = export end luatexbase.add_to_callback("ligaturing", disableLigatures, "disableLigatures") luatexbase.add_to_callback("pre_linebreak_filter", exportText, "exportText") \end{filecontents*} \ifluatex \newluatexattribute\wordcounton \directlua{dofile("luaFunctions.lua")} \fi \def\startExportParagraph{% \ifluatex \wordcounton = 2 %\directlua{SetExportParagraph(true)} \fi } \def\stopExportParagraph{% \ifluatex \wordcounton = 1 \fi }

\begin{document} \startExportParagraph \noindent ff fi Lorem ipsum dolor sit amet, příliš žluťoučký text s diakritikou dash\footnote{you should test some options} -- \hbox{how does that work?} \textbf{consectetuer adipiscing elit. Ut purus elit, vestibulum ut, placerat ac, adipiscing vitae, felis.} Curabitur dictum gravida mauris. Nam arcu libero, nonummy eget, consectetuer id, vulputate a, magna. 889

Donec vehicula augue eu neque. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Mauris ut leo. Cras viverra metus rhoncus sem. Nulla et lectus vestibulum urna fringilla ultrices. Phasellus eu tellus sit amet tortor gravida placerat. Integer sapien est, iaculis in, pretiu quis, viverra ac, nunc. Praesent eget sem vel leo ultrices bibendum. Aenean faucibus. Morbi dolor nulla, malesuada eu, pulvinar at, mollis ac, nulla. Curabitu eu, accumsan eleifend, sagittis quis, diam. Duis eget orci sit amet orci dignissim rutrumrutrumrutrumrutrumrutrumrutrumrutrumrutrumrutrumrutrumrutrumrutrumrutrumrutr \begin{tabular}{ll} what & about\\ tables&? \end{tabular} \begin{itemize} \item you also want to save itemize \item items \end{itemize}

You can \stopExportParagraph stop word countinh in the middle of \startExportParag

Nam dui ligula, fringilla a, euismod sodales, sollicitudin vel, wisi. Morbi auctor lorem non justo. Nam lacus libero, pretium at, lobortis vitae, ultricies et tellus. Donec aliquet, tortor sed accumsan bibendum, erat ligula aliquet magna, vitae ornare odio metus a mi. Morbi ac orci et nisl hendrerit mollis. Suspendisse ut massa. Cras nec ante. Pellentesque a nulla. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aliquam tincidunt urna. Nulla ullamcorper vestibulum turpis. Pellentesque cursus luctus mauris. \stopExportParagraph Nulla malesuada porttitor diam. Donec felis erat, congue non, volutpat at, tincidunt tristique, libero. Vivamus viverra fermentum felis. Donec nonummy pellentesque ante. Phasellus adipiscing semper elit. Proin fermentum massa ac quam. Sed diam turpis, molestie vitae, placerat a, molestie nec, leo. Maecenas lacinia. Nam ipsum ligula, eleifend at, accumsan nec, suscipit a, ipsum. Morbi blandit ligula feugiat magna. Nunc eleifend consequat lorem. Sed lacinia 890

nulla vitae enim. Pellentesque tincidunt purus vel magna. Integer non enim. Praesent euismod nunc eu purus. Donec bibendum quam in tellus. Nullam cursus pulvinar lectus. Donec et mi. Nam vulputate metus eu enim. Vestibulum pellentesque felis eu massa. \end{document} There was global variable file used, which interfered with some variable in fontspec. All private variables should be local!. file also weren’t closed. When dealing with unicode characters, we cannot use string.char function, but we must unicode.utf8.char instead. Then I rewrote node traversing loop as recursive function, because sub lists may occur in a node list and we must process them as well. See traverse function. I modified the document interface, introducing two macros: startExportParagraph and stopExportParagraph. luatex mechanism of node attributes is used, allowing more flexible switching of counting, even in the middle of paragraphs. I also added character counting. I added some more test cases: Skip code block ff fi Lorem ipsum dolor sit amet, příliš žluťoučký text s diakritikou dash\footnote{you should test some options} -- \hbox{how does that work?} \textbf{consectetuer adipiscing elit. Ut purus elit,... \begin{tabular}{ll} what & about\\ tables&? \end{tabular} \begin{itemize} \item you also want to save itemize \item items \end{itemize}

You can \stopExportParagraph stop word countinh in the middle of \startExportParag which is saved in the output.txt as: 891

Skip code block 1you should test some options Words: 4, characters: 29, list type: insert

ff fi Lorem ipsum dolor sit amet, příliš žluťoučký text s diakritikou dash1 -- how what about tables ? Words: 4, characters: 20, list type: • you also want to save itemize Words: 7, characters: 30, list type: • items Words: 2, characters: 6, list type: You can the paragraph. Words: 4, characters: 22, list type: as you can see, footnotes produce its own paragraph, which shows before the paragraph they appear in. ligatures are breaked int components, so ffi and fi are counted correctly. But this also causes dash to be broken into --. Bullets in itemize environments are counted as words, I have to investigate how to solve this issue. Also character counts are wrong.

Answer by david-carlisle If you are not looking for a lua solution (which is no doubt possible) you can use the classic Tex version \begin{document}\language-1 will turn off hyphenation

Tags: hyphenation (Prev Q) (Next Q)

892

Q: LuaTeX cyrillic hyphenation problems Tags: hyphenation (Prev Q) (Next Q), babel (Prev Q) (Next Q), miktex (Prev Q) (Next Q) I am trying to use LuaTeX (LuaLaTeX) in MiKTeX 2.9 and I’m stuck with getting it to load cyrillic hyphenation patterns. I’m quite new to LuaTeX, so maybe there’s something special about hyphenation and language support in it? Here’s my sample document: Skip code block \documentclass{article} \usepackage{fontspec} \defaultfontfeatures{Ligatures=TeX} \usepackage[russian]{babel} \setmainfont{Charis SIL} \title{���������} \author{�����} \date{} \begin{document} \maketitle \begin{abstract} ���� ������: ��������� \LuaTeX. \end{abstract} ��������. ����� ������� ������ ��� �������� ���������: ���������������������� ����. \end{document} I get no hyphenation and overfull hbox in this example. Same text hyphenates nicely in XeTeX and pdfTeX. 893

Tags: hyphenation (Prev Q) (Next Q), babel (Prev Q) (Next Q), miktex (Prev Q) (Next Q) User: grey-teardrop

Answer by taco-hoekwater I just realized that it could be that the non-hyphenation is because of character codes. The latest luatex’s from texlive have a file luatex-unicodeletters.tex that sets the lowercase codes for non-latin letters, and chances are that that is not in miktex (yet). I put a copy of that file up under the link above, you could try to \input that file, perhaps it fixes things.

Answer by ulrike-fischer Additional comment to Tacos answer. To add luatex-unicode-letters.tex to your lualatex format: Save luatex-unicode-letters.tex in ”a local root”/tex/generic/luatexconfig. Put the following code in a file lualatex.ini and save it ”a local root”/tex/latex/latexconfig. Renew the FNDB and then regenerate the lualatex format. Edit: And here the code for lualatex.ini I mentioned: Skip code block % $Id$ % Karl Berry, originally written 2008. public domain. % must be done first (activation of primitives) \input lualatexiniconfig.tex \input luatex-unicode-letters.tex \input pdftexconfig.tex % pdf output by default. \scrollmode \let\dump\relax \input latex.ltx \input lualatexquotejobname.tex \pdfprimitive\dump 894

Tags: hyphenation (Prev Q) (Next Q), babel (Prev Q) (Next Q), miktex (Prev Q) (Next Q)

Q: Redefining the emdash so as to allow hyphenation Tags: hyphenation (Prev Q) OK, so I use the emdash as follows: someword---anotherword, but the problem is this prevents hyphenation of both words around the dash. I can fix this by replacing --- with \textemdash, but I was wondering, is there any way to redefine the --- ”command” with \textemdash? I use LuaTeX. Related to this issue issue I’ve found this and this, but neither provides an acceptable solution... Thanks in advance! Tags: hyphenation (Prev Q) User: wmnorth

Answer by thruston The extdash package does what you want, but you have to type \--- instead of ---. \documentclass{minimal} \usepackage[shortcuts]{extdash} \begin{document} someword\---anotherword \end{document} See also this longer discussion elsewhere on TeXSE.

Tags: hyphenation (Prev Q)

895

Babel Skip to questions, Wiki by user n.n. babel is a package that manages culturally-determined typographical (and other) rules, and hyphenation patterns for a wide range of languages. A document may select a single language to be supported, or it may select several, and the document may then switch from one language to another in a variety of ways.

Questions Q: Who maintains babel now? Tags: babel (Prev Q) (Next Q) Who manages babel now? It is said on CTAN that Johannes L. Braams is no longer active on this package. I’d like to contribute babel’s support for Russian in LuaLaTeX. Tags: babel (Prev Q) (Next Q) User: igor-kotelnikov

Answer by mojca-miklavec The right contact for language related issues in LuaLaTeX might be Arthur Reutenauer who just took over development of Polyglossia. Polyglossia has not been ported to LuaLaTeX yet, but it should only be a matter of time until it gets ported.

896

(Of course you may also submit your babel files to CTAN as long as they don’t break pdfLaTeX.)

Answer by javier-bezos Babel is again maintained: html .

http://www.tex-tipografia.com/babel_news.

Tags: babel (Prev Q) (Next Q)

Q: How to fix this interaction bug between pgfplots and babelfrench module? Tags: babel (Prev Q) (Next Q), pgfplots (Prev Q) (Next Q) Here is an example of a minimum non-working case which is generating the bug: Skip code block \documentclass{standalone} \usepackage{luatextra} \usepackage[frenchb]{babel} \usepackage{pgfplots} \begin{document} \begin{tikzpicture} \begin{axis} \legend{a}; \end{axis} \end{tikzpicture} \end{document} 897

I get this:

error: /usr/share/texmf-dist/tex/generic/babel-french/frenchb.lua:62: attempt to i . \endpgfpicture ...globally \endgroup \hss \egroup \[email protected]@[email protected] l.36 \end{tikzpicture} If I remove the legend away, this is working well. But well, the legend is usually kind of a required piece of information in a graph. EDIT: I just installed the latest TL version (net install): the bug is still there! Tags: babel (Prev Q) (Next Q), pgfplots (Prev Q) (Next Q) User: user15283

Answer by paul-gaborit With recent version of frenchb (v3.1b), there is no bug. If you try the following code, there is no error: Skip code block \documentclass{standalone} \usepackage{luatextra} \usepackage[frenchb]{babel} \usepackage{pgfplots} \begin{document} \begin{tikzpicture} \begin{axis} \legend{a} \end{axis} \end{tikzpicture} \end{document} 898

Advice: If you compile a document via lualatex with frenchb (older than v3.1b) and tikz don’t add superfluous active character in your TikZ code ! (In your example, the superfluous character is ;)

Tags: babel (Prev Q) (Next Q), pgfplots (Prev Q) (Next Q)

Q: How to get LuaLaTeX to work with babel’s \textgreek? Tags: babel (Prev Q) (Next Q) I’m completely at a loss with how to get LuaLaTeX to output Greek text. I have tested the following MWE with PDFLaTeX and LuaLaTeX on both TeXlive 2009 (Linux) and TeXlive 2011 (Win32) and in both cases PDFLaTeX produces the expected output while LuaLaTeX seems to gobble up the Greek text and then do nothing with it. Skip code block \documentclass{minimal} % Use LGRx if installed else LGR. % Forcing one or the other makes no difference either. \IfFileExists{lgrxenc.def}{% \usepackage[LGRx,T1]{fontenc}}{% \usepackage[LGR,T1]{fontenc}} %\fi \usepackage{lmodern,trace,ifluatex} \usepackage[greek,british]{babel} \unless\ifluatex \usepackage[utf8]{inputenc} \fi \begin{document} % pdflatex: OK. %lualatex: "��������" is missing from the output, % and the sum total of output from \traceon is this: % {into \tracingonline=1} % {the character �} 899

% {end-group character }} Triangle: \textgreek{\traceon ��������}. \end{document} Tags: babel (Prev Q) (Next Q) User: kahen

Answer by egreg If you want to use the original CB fonts for Greek, there is a way out, but you need to have lgrenc.dfu, so I’ll assume it’s available along with its sibling lgrxenc.def: Skip code block \documentclass{minimal} \usepackage[LGRx,T1]{fontenc} \usepackage{lmodern,ifluatex} \usepackage[greek,british]{babel} \ifluatex \let\LtxDeclareUnicodeCharacter\DeclareUnicodeCharacter \def\DeclareUnicodeCharacter#1{% \catcode\string"#1=\active \begingroup \lccode`~=\string"#1\relax \lowercase{\endgroup \protected\def~}} \input{lgrenc.dfu} \let\DeclareUnicodeCharacter\LtxDeclareUnicodeCharacter \else \usepackage[utf8]{inputenc} \fi \begin{document} Triangle: \textgreek{��������}. \end{document} With LuaLaTeX I use lgrenc.dfu for a different purpose, that is for activating the Greek characters and defining them to the required meaning.

900

However I don’t see the advantages of using LuaLaTeX, in this case.

Tags: babel (Prev Q) (Next Q)

Q: Chinese, Russian and English (and Arabic, and Thai, if possible) in LuaLaTeX Tags: babel (Prev Q) (Next Q) following up on THIS QUESTION, I want to embed the solution in a document (Beamer presentation) I compile (in English) with LuaLaTeX, but I just don’t find the way. I just want to include a slide with text in different languages and the code for teaching purposes, but it is the first time I try to write something in a non-latin alphabet... But my document needs LuaLaTeX (and I actually like it!). Additionally, if someone knows how to include text in a couple of other nonlatin alphabets as well, like Arabic and Thai, it would be much appreciated. So this it the code I want to embed in my document compiled with LuaLaTeX: Skip code block

\documentclass[12pt]{article} \usepackage[margin=1in]{geometry} \usepackage[T1,T2A]{fontenc} \usepackage[utf8]{inputenc} \usepackage[russian, english]{babel}% note - it is recommended to specify the vari \usepackage[encapsulated]{CJK} \usepackage{setspace} \doublespacing \usepackage{natbib} \begin{document} \selectlanguage{russian} �����

901

\begin{CJK}{UTF8}{gbsn} �� \end{CJK} \selectlanguage{english} Here is some text in English. \selectlanguage{russian} ����� \end{document} Tags: babel (Prev Q) (Next Q) User: danicee

Answer by musarithmia Here I demonstrate only how to use fontspec to select many different fonts for different languages in one document. I use a main font that already covers a wide Unicode range, and then select other fonts as appropriate. I used fonts either available in TeXLive or freely available elsewhere. Compile with lualatex. Note that for Hebrew and Arabic you have to use \luatextexdir TRT to set the right-to-left text direction, and with Arabic you need [Script=Arabic]. See the fontspec package documentation and other questions on these sites about these languages for more information. I don’t know all these languages, so I have likely gotten some things wrong, and I hope others will correct me. To this you can add using babel or polyglossia for hyphenation patterns specific to each language, but I leave this up to someone else to demonstrate. With only short excerpts of different languages, that may be overkill anyway. Skip code block \documentclass{article} \usepackage{url} % just to format urls \usepackage{fontspec} 902

\setmainfont{Linux Libertine O} % Libertine covers Latin, Hebrew, Greek, and Russian \newfontfamily{\hebrewfont}{Linux Libertine O} \newcommand{\texthebrew}[1]{% \bgroup\luatextextdir TRT\hebrewfont #1\egroup% } \newfontfamily{\chinesefont}{IPAMincho} % in TeXLive \newcommand{\textchinese}[1]{\bgroup\chinesefont #1\egroup} \newfontfamily{\arabicfont}[Script=Arabic]{Droid Arabic Naskh} % free with Debian \newcommand{\textarabic}[1]{% \bgroup\luatextextdir TRT\arabicfont #1\egroup% } \newfontfamily{\thaifont}{Norasi} % free with Debian \newcommand{\textthai}[1]{\bgroup\thaifont #1\egroup} \begin{document} \section*{The Tower of Babel, Genesis 11:7}

\subsection*{English} Come, let us go down and confuse their language so they will not understand each o \subsection*{Hebrew} \texthebrew{% ��� ���� ����� �� ���� ��� �� ����� ��� ��� %������ { \subsection*{Greek} ����� ��� ���������� ��������� ���� ����� ��� �������, ��� �� ��������� ������� ��� ����� ��� �������.

\subsection*{Latin} venite igitur descendamus et confundamus ibi linguam eorum ut non audiat unusquisq

\subsection*{Spanish} Será mejor que bajemos a confundir su idioma, para que ya no se entiendan entre el 903

\subsection*{Russian} ������ �� � ������� ��� ���� ��, ��� ����� ���� �� ������� ���� �������. \subsection*{Chinese (Simplified)} \textchinese{% �����������������������������% } \subsection*{Thai} \textthai{% ������ ��������������������������������������������� ������������������������% } \subsection*{Arabic} \textarabic{% ���� ���� ����� ������ ��������� ���� ��� ���� ����� ����� %.���� {

\bigskip \small Texts from \url{https://www.biblegateway.com}. Greek Septuagint text from \url{https://www.academic-bible.com/en/online-bibles/se

\end{document}

904

905

Tags: babel (Prev Q) (Next Q)

Q: Russian in document with Japanese as main language (LuaLaTeX + ltjsarticle) Tags: babel (Prev Q), polyglossia (Prev Q) (Next Q) I need to use some Russian text fragment in ltjsarticle class, which provides the Japanese settings like Japanese caption for LuaLaTeX. In the current MWE, • There are big intervals between Russian letters. • There is no hyphenation. • The table name becomes to Russian, however the main language in my document is Japanese, so I need to keep the Japanese names (there is no Japanese language in babel or polyglossia packages, so I can’t to assign as \setmainlanguage neither Japanese and Russian).

906

Skip code block \documentclass[a4paper]{ltjsarticle} \usepackage{luatexja-fontspec} \setmainjfont[BoldFont=HGMinchoB]{MS Mincho} \setsansjfont[BoldFont=KozGoPro-Bold]{MS Gothic} \setmainfont[Ligatures=TeX]{TeX Gyre Pagella} \setsansfont[Ligatures=TeX,Scale=MatchLowercase]{TeX Gyre Heros} \usepackage{fontspec} \usepackage{array} \usepackage{booktabs}

907

\usepackage[russian]{babel} \usepackage{multicol} \begin{document} ����������������������

\begin{table}\centering \begin{tabular}{|c|c|c|c|c|} \toprule �&�&�&�&�\\ \hline �&�&�&�&�\\ \hline �&�&�&�&�\\ \midrule \dots&\dots&\dots&\dots&\dots\\ \midrule �&�&�&�&�\\ \bottomrule \end{tabular}\caption{You must to see [�] before table number, \textbf{not} [Table \end{table} ������ �������. The letters is too wide, isn't it?

\begin{multicols}{3} Now the hyphenation test. There are no the [-] symbol, isn't it? ���� ���������. ��� ��� �� \end{multicols}

\begin{table}[ht!]\centering \begin{tabular}{|c|c|c|c|c|} \toprule �&�&�&�&�\\ \hline �&�&�&�&�\\ \hline �&�&�&�&�\\ \midrule \dots&\dots&\dots&\dots&\dots\\ \midrule �&�&�&�&�\\ \bottomrule \end{tabular}\caption{You must to see [�] before table number, \textbf{not} [Table \end{table} \end{document} I know about some commands like \setotherlanguage or \newfontfamily\cyrillicfont, but I didn’t desired result with these commands, too. • Note: Maybe you have not got the fonts. Please replace fonts com908

mands, if so. • Note: If you need ltjsarticle class, you can get it here. Tags: babel (Prev Q), polyglossia (Prev Q) (Next Q) User: gurebu-bokofu

Answer by egreg Reading the documentation reveals that characters are classified in “ALchars” and ”JAchars” and that Cyrillic is assigned to “JAchars”. Just reassign: \ltjsetparameter{jacharrange={-1, -2, +3, -4, -5, +6, +7, +8}} (the standard declaration has +2, see section 4.1 of the documentation). Of course you have to use a font that supports Cyrillic, which TeX Gyre Pagella doesn’t. Skip code block \documentclass[a4paper]{ltjsarticle} \usepackage{luatexja-fontspec} \setmainjfont{Hiragino Mincho Pro} \setsansjfont{Hiragino Sans GB} \setmainfont[Ligatures=TeX]{Linux Libertine O} \setsansfont[Ligatures=TeX]{Linux Biolinum O} \ltjsetparameter{jacharrange={-1, -2, +3, -4, -5, +6, +7, +8}} \usepackage{array} \usepackage{booktabs} \usepackage[russian]{babel} \usepackage{multicol} \begin{document} 909

����������������������

\begin{table}\centering \begin{tabular}{|c|c|c|c|c|} \toprule �&�&�&�&�\\ \hline �&�&�&�&�\\ \hline �&�&�&�&�\\ \midrule \dots&\dots&\dots&\dots&\dots\\ \midrule �&�&�&�&�\\ \bottomrule \end{tabular}\caption{You must to see [�] before table number, \textbf{not} [Table \end{table} ������ �������. The letters is too wide, isn't it?

\begin{multicols}{3} Now the hyphenation test. There are no the [-] symbol, isn't it? ���� ���������. ��� ��� �� \end{multicols}

\begin{table}[ht!]\centering \begin{tabular}{|c|c|c|c|c|} \toprule �&�&�&�&�\\ \hline �&�&�&�&�\\ \hline �&�&�&�&�\\ \midrule \dots&\dots&\dots&\dots&\dots\\ \midrule �&�&�&�&�\\ \bottomrule \end{tabular}\caption{You must to see [�] before table number, \textbf{not} [Table \end{table} \end{document}

910

There is no real integration of luatexja with babel, so doing \usepackage[russian]{babel} overrides all settings. As far as I can see, only Japanese and English are supported. You can correct this by doing \usepackage[russian,english]{babel}. If you need longer passages in Russian, with correct hyphenation, use \begin{otherlanguage*}{russian} ... \end{otherlanguage*} For shorter parts \foreignlanguage{russian}{...} can be used (or nothing at all for a single word, that however won’t be hyphenated). I provide some fixes for babel in luatexja, but be prepared to find other 911

places where something can go wrong. Skip code block \documentclass[a4paper]{ltjsarticle} \usepackage{luatexja-fontspec} \setmainjfont{Hiragino Mincho Pro} \setsansjfont{Hiragino Sans GB} \setmainfont[Ligatures=TeX]{Linux Libertine O} \setsansfont[Ligatures=TeX]{Linux Biolinum O} \ltjsetparameter{jacharrange={-1, -2, +3, -4, -5, +6, +7, +8}} \usepackage{array} \usepackage{booktabs} \usepackage[russian,english]{babel} \usepackage{multicol} \makeatletter \renewcommand\captionsenglish{% \renewcommand{\prepartname}{\[email protected] Part~\else �\fi}% \renewcommand{\postpartname}{\[email protected]\else �\fi}% \renewcommand{\presectionname}{}% � \renewcommand{\postsectionname}{}% � \renewcommand{\contentsname}{\[email protected] Contents\else ��\fi}% \renewcommand{\listfigurename}{\[email protected] List of Figures\else ���\fi}% \renewcommand{\listtablename}{\[email protected] List of Tables\else ���\fi}% \renewcommand{\refname}{\[email protected] References\else ����\fi}% \renewcommand{\bibname}{\[email protected] Bibliography\else ����\fi}% \renewcommand{\indexname}{\[email protected] Index\else ��\fi}% \renewcommand{\figurename}{\[email protected] Fig.~\else �\fi}% \renewcommand{\tablename}{\[email protected] Table~\else �\fi}% \renewcommand{\appendixname}{\[email protected] \else ��\fi}% \renewcommand{\abstractname}{\[email protected] Abstract\else ��\fi}% } \makeatother 912

\begin{document} ����������������������

\begin{table}\centering \begin{tabular}{|c|c|c|c|c|} \toprule �&�&�&�&�\\ \hline �&�&�&�&�\\ \hline �&�&�&�&�\\ \midrule \dots&\dots&\dots&\dots&\dots\\ \midrule �&�&�&�&�\\ \bottomrule \end{tabular}\caption{You must to see [�] before table number, \textbf{not} [Table \end{table} ������ �������. The letters is too wide, isn't it?

\begin{multicols}{3} Now the hyphenation test. There are no the [-] symbol, isn't it? ���� ���������. ��� ��� �� \end{multicols}

\begin{table}[ht!]\centering \begin{tabular}{|c|c|c|c|c|} \toprule �&�&�&�&�\\ \hline �&�&�&�&�\\ \hline �&�&�&�&�\\ \midrule \dots&\dots&\dots&\dots&\dots\\ \midrule �&�&�&�&�\\ \bottomrule \end{tabular}\caption{You must to see [�] before table number, \textbf{not} [Table \end{table} \end{document}

913

Tags: babel (Prev Q), polyglossia (Prev Q) (Next Q)

Tikz Pgf Skip to questions, Wiki by user stefan-kottwitz Questions tagged with tikz-pgf are about the higher-level drawing language TikZ built over the PGF graphics framework or about the whole TikZ/PGF 914

stack. For questions specifically about the PGF layer use pgf-core instead. Both tags are possible on the same question. In addition to all TikZ examples in questions on this site, TeXample.net shows examples of what can be done with TikZ. For learning TikZ see: • Materials for learning TikZ • List of available TikZ libraries with a short introduction

Questions Q: \tikzexternalize doesn’t work with lua code Tags: tikz-pgf (Prev Q) (Next Q) The following code from the pgf manual compiles fine with lualatex --shell-escape \documentclass{article} \usepackage{tikz} \usetikzlibrary{external} \tikzexternalize \begin{document} A simple image is \tikz \fill (0,0) circle(5pt);. \end{document} But, if I write some luacode (for example $\pi = \directlua{tex.sprint(math.pi)}$) I have the following error message : Skip code block ===== 'mode=convert with system call': Invoking 'pdflatex -halt-on-error -inter action=batchmode -jobname "test-figure0" "\def\tikzexternalrealjob{test}\input{ test}"' ======== runsystem(pdflatex -halt-on-error -interaction=batchmode -jobname "test-figure0 " "\def\tikzexternalrealjob{test}\input{test}")...executed. ./test.tex:7: Package tikz Error: Sorry, the system call 'pdflatex -halt-on-err 915

or -interaction=batchmode -jobname "test-figure0" "\def\tikzexternalrealjob{tes t}\input{test}"' did NOT result in a usable output file 'test-figure0' (expecte d one of .pdf:.jpg:.jpeg:.png:). Please verify that you have enabled system cal ls. For pdflatex, this is 'pdflatex -shell-escape'. Sometimes it is also named 'write 18' or something like that. Or maybe the command simply failed? Error me ssages can be found in 'test-figure0.log'. If you continue now, I'll try to typ eset the picture. See the tikz package documentation for explanation. Type H for immediate help. ... l.7 ...ple image is \tikz \fill (0,0) circle(5pt); The question is: what’s wrong? And subsidiarily, why is pdflatex invoked? N.B. The compilation with lua code fails only if I deleted the aux files before. Tags: tikz-pgf (Prev Q) (Next Q) User: matsaya

Answer by diabonas You can change the program PGF/TikZ calls to generate the external graphics with the key /tikz/external/system call (see the manual, page 345). The default value is

\tikzset{external/system call={pdflatex \tikzexternalcheckshellescape -halt-on-err Replacing pdflatex with lualatex should solve the problem:

\documentclass{article} \usepackage{tikz} \usetikzlibrary{external} \tikzset{external/system call={lualatex \tikzexternalcheckshellescape -halt-on-err \tikzexternalize \begin{document} A simple image is \tikz \fill (0,0) circle(5pt);. $\pi = \directlua{tex.sprint(math.pi)}$ \end{document} 916

Tags: tikz-pgf (Prev Q) (Next Q)

Q: \pgfmathdeclarefunction and LuaLaTeX Tags: tikz-pgf (Prev Q) (Next Q), pgfplots (Prev Q) (Next Q) Is it possible to use LuaLaTeX in \pgfmathdeclarefunction? I tried with sinh which seems to work in pgfmathsetmacro but not in \pgfmathparse and pgfplots. How should I declare a pgf function with Lua correctly? Skip code block \documentclass{article} \usepackage{tikz} \usepackage{pgfplots} \makeatletter \pgfmathdeclarefunction{luasinh}{1}{% \begingroup \edef\[email protected]{#1}% \directlua{tex.setdimen("[email protected]", math.sinh(\[email protected]) .. "pt")}% \[email protected]\[email protected]% \endgroup }% \makeatother

\begin{document} \noindent Lua: \pgfmathsetmacro\luasinh{luasinh(1)}\luasinh\\ PGF: \pgfmathsetmacro\pgfsinh{sinh(1)}\pgfsinh\\ \begin{tikzpicture} 917

\begin{axis} \addplot {sinh(x)}; %\addplot {luasinh(x)}; does not work \end{axis} \end{tikzpicture} \end{document} I think being able to use Lua in LuaLaTeX when declaring pgf functions could be useful. For example, this question ”Erf function in LaTeX” could maybe be answered without calling Gnuplot but simply call math.erf (if this exists?) in \directlua. Tags: tikz-pgf (Prev Q) (Next Q), pgfplots (Prev Q) (Next Q) User: martin-heller

Answer by martin-heller Based on @Mark Wibrow’s comment, I have a working function declaration. The conversion from pgfplots internal syntax to something that is digestable by Lua feels wrong, though: Skip code block \documentclass{article} \usepackage{tikz} \usepackage{pgfplots}

\makeatletter \pgfmathdeclarefunction{luasinh}{1}{% \begingroup \pgfkeys{/pgf/fpu,/pgf/fpu/output format=sci}% \pgfmathparse{#1}% \edef\pgfmathresult{\directlua{tex.print("" .. math.sinh(\pgfmathresult))} \pgfmathsmuggle\pgfmathresult% \endgroup }% \makeatother

918

\newcommand*\printtest[1]{% \section*{Test of $\sinh(#1)$} Lua: \directlua{tex.print("" .. math.sinh(#1))}~(directlua)\\ Lua: \pgfmathsetmacro\luasinh{luasinh(#1)}\luasinh~(luasinh())\\ Lua: \pgfmathparse{luasinh(#1)}\pgfmathresult~(pgfmathresult)\\ %PGF: \pgfmathsetmacro\pgfsinh{sinh(#1)}\pgfsinh\\ }% \begin{document} \printtest{0} \printtest{1} \printtest{10} \begin{tikzpicture} \begin{axis}[domain=-10:10] \addplot[mark=o] {sinh(x)}; \addplot[mark=x] {luasinh(x)}; \end{axis} \end{tikzpicture} \end{document}

Tags: tikz-pgf (Prev Q) (Next Q), pgfplots (Prev Q) (Next Q)

Q: Lua code with Tikz Tags: tikz-pgf (Prev Q) (Next Q) Is there a reason why the code below leads to the error: ! Illegal unit of measure (pt inserted).

e l.16 ...t [domain=-.1:.1,samples = 100] (\x,{G(\x)})

919

Skip code block \documentclass[tikz]{standalone} \directlua{ function G (x) return (-(x^2)/3) end } \pgfmathdeclarefunction{G}{1}{% \edef\pgfmathresult{\directlua{tex.print("" .. G(#1))}}% } \begin{document} \begin{tikzpicture} \draw [blue] plot [domain=-.1:.1,samples = 100] (\x,{G(\x)}); \end{tikzpicture} \end{document} Tags: tikz-pgf (Prev Q) (Next Q) User: pluton

Answer by david-carlisle If you modify the function to \pgfmathdeclarefunction{G}{1}{% \edef\pgfmathresult{\directlua{tex.print("" .. G(#1))}}% \show\pgfmathresult \edef\pgfmathresult{1}% } then the plot plots the (wrong:-) function without error but you get to see what you were plotting. The first few values are OK but then: > \pgfmathresult=macro: ->-9.5052e-06. Presumably pgf isn’t expecting the e notation. Presumably lua has some number formatting functions to prevent it using that notation? edit ah yes: 920

\makeatletter \pgfmathdeclarefunction{G}{1}{% \edef\pgfmathresult{\directlua{tex.print(string.format("\@percentchar f",G(#1)))}} } \makeatother

Answer by yiannis-lazarides I would suggest to use Lua for all the calculations and also to create the relevant LaTeX code. Of course as Dave suggested use string.format('% .2f','number') to format the number. Two decimal places would be more than adequate for plotting. Skip code block \documentclass[tikz]{standalone} \usepackage{luacode} \begin{document} \begin{luacode} local function G (x) return string.format('% .2f',-(x^2)/3) end tex.print('\\begin{tikzpicture}[scale=.3]') tex.print('\\draw[color=red] (0,0)') local z=-.1 for i=1,50 do tex.sprint('-- (' .. i .. ',' .. G(z)..') z=z+.2 end tex.sprint(';')

')

tex.print('\\end{tikzpicture}') \end{luacode} \end{document} This normally produces cleaner code, is easier to debug and faster. Add formatting code for axes and co-ordinates to suit your requirements. For 921

example using the above it is trivial to also export the values as a table and also do any transformations you may want.

Tags: tikz-pgf (Prev Q) (Next Q)

Q: Why can I include tikz in a custom latex format with pdftex and not with luatex? Tags: tikz-pgf (Prev Q) (Next Q), format-files (Next Q) Consider the following class.cls: \LoadClass{article} \RequirePackage{tikz} and the following test.tex: \documentclass{class} \begin{document} Test \end{document} With pdftex (TeXLive 2016), I do:

pdftex -ini -jobname="test-fmt-pdftex" "&pdflatex" mylatexformat.ltx """test.tex"" pdftex -fmt=test-fmt-pdftex.fmt test.tex It works with no problem. With luatex (TeXLive 2016), I do:

luatex -ini -jobname="test-fmt-luatex" "&lualatex" mylatexformat.ltx """test.tex"" luatex -fmt=test-fmt-luatex.fmt test.tex The second line ends up with an error:

! error: (pdf backend): referenced object has wrong type others; should be o ! ==> Fatal error occurred, no output PDF file produced!

922

I know that I cannot dump in a luatex format lua code or opentype fonts but I think that tikz does not do that. There must be an other reason. Do you have any ideas?

I investigated a bit. As far as I understand, there has been an updated version of pgfsys-luatex.def to comply with the changes made in luatex related to \pdf... primitives. This is one hint I can think of. There is also this in the luatex manual: One change involves the so called xforms and ximages. In pdfTEX these are implemented as so called whatsits. But contrary to other whatsits they have dimensions that need to be taken into account when for instance calculating optimal line breaks. In LuaTEX these are now promoted to normal nodes, which simplifies code that needs those dimensions. But I must admit I don’t really understand all that. Tags: tikz-pgf (Prev Q) (Next Q), format-files (Next Q) User: cjorssen

Answer by ulrike-fischer pgfsys-luatex.def calls at the end two commands • \[email protected] and • \[email protected]@colorspaces. If you remove these calls your example works. So there is somewhere the source of the problem. The commands call the code in \[email protected]@[email protected] and this set up pdf objects: disabling the obj in \[email protected] avoids the error too. Boiling everthing a bit down one can create the following (senseless!!) minimal document: Skip code block 923

\documentclass{book} \usepackage{ifluatex} \ifluatex \pdfextension obj reserveobjnum \edef\myobjnum{\the\numexpr\pdffeedback lastobj\r \else \pdfobj reserveobjnum \edef\myobjnum{\the\pdflastobj} \fi %\makeatother \begin{document} \ifluatex \immediate \pdfextension obj useobjnum \myobjnum {] (-0.2,0) -- (4.2,0) node[right] {$x$}; \draw[->] (0,-1.2) -- (0,4.2) node[above] {$f(x)$}; \draw[color=red] plot[id=x] function{x} node[right] {$f(x) =x$}; \draw[color=blue] plot[id=sin] function{sin(x)} node[right] {$f(x) = \sin x$}; \draw[color=orange] plot[id=exp] function{0.05*exp(x)} node[right] {$f(x) = \frac{ \end{tikzpicture} \end{document} If I compile this .tex file with pdflatex --shell-escape tikz.tex everything works fine. However, if I use use the exact same command with lualatex instead of pdflatex, my log file says gnuplot tikz.x.gnuplot Package pgf Warning: Plot data file `tikz.x.table' not found. on input line 16. 928

gnuplot tikz.sin.gnuplot Package pgf Warning: Plot data file `tikz.sin.table' not found. on input line 1 7. Does anyone know what’s the problem here? Thanks in advance. Tags: tikz-pgf (Prev Q), shell-escape (Prev Q) (Next Q) User: florian

Answer by david-carlisle \write18 shell escape does not work by default for newer luatex, the shellesc package puts it back, this works for me: Skip code block \RequirePackage{luatex85,shellesc} \documentclass{article} \usepackage{tikz} \begin{document} \pagestyle{empty}

\begin{tikzpicture}[domain=0:4] \draw[very thin,color=gray] (-0.1,-1.1) grid (3.9,3.9); \draw[->] (-0.2,0) -- (4.2,0) node[right] {$x$}; \draw[->] (0,-1.2) -- (0,4.2) node[above] {$f(x)$}; \draw[color=red] plot[id=x] function{x} node[right] {$f(x) =x$}; \draw[color=blue] plot[id=sin] function{sin(x)} node[right] {$f(x) = \sin x$}; \draw[color=orange] plot[id=exp] function{0.05*exp(x)} node[right] {$f(x) = \frac{ \end{tikzpicture} \end{document}

Tags: tikz-pgf (Prev Q), shell-escape (Prev Q) (Next Q)

929

Math Mode Questions Q: Symbols for left and right limits Tags: math-mode (Prev Q) (Next Q), symbols (Prev Q) (Next Q) I am using lualatex, are there symbols for left and right limits, like small ”-” and ”+” to put above the numbers? For now I use Skip code block \documentclass[a4paper,12pt]{book} \usepackage{fontspec} \usepackage{polyglossia} \usepackage{amsmath,empheq} \usepackage{mathtools} \usepackage{amscd} \usepackage{amsxtra} \usepackage{unicode-math} \begin{document} \[ \lim_{x \rightarrow 1^{+}} f(x) \] \[ \lim_{x \rightarrow 1^{-}} f(x) \] \end{document} which I feel is not right because the default ”+” and ”-” are operators and their size and spacing might not be the best for this use. Tags: math-mode (Prev Q) (Next Q), symbols (Prev Q) (Next Q) User: emmet930

Answer by david-carlisle Infix operators like + and - lose their infix status (and the extra space that implies) if used on their own in this way. Also as noted by egreg, in a superscript the operators would get no space even used as an infix operator. What you have is the standard markup.

Tags: math-mode (Prev Q) (Next Q), symbols (Prev Q) (Next Q)

Q: lualatex-luatextra math mode issue Tags: math-mode (Prev Q) I’m new here (i.e., pardon my ignorance). But I’ve been tootling around the LuaLatex and I’ve come across some bizarre behavior. The following code Skip code block \documentclass{article} \usepackage{luatextra} \usepackage{xparse} \begin{luacode*} function record (m,n) file = assert(io.open("test2.dat","a")) file:write(string.format("%s %s",m,n),"\n") end \end{luacode*} \newcounter{prob} \setcounter{prob}{1} \DeclareDocumentCommand{\problem}{m}{% \noindent \textbf{Problem \theprob:} (#1 points) 931

\directlua{record(\theprob ,#1)} \stepcounter{prob} } \begin{document} \problem{2} Who is your Daddy and what does he do? $42$ \end{document} produces the following error: ...MikTex 2.9/tex/luatex/luaotfload/fontloader-2016-06-1 6.lua:10601: attempt to call field 'suffix' (a nil value).

relax 1.24 $4 2$ ? Here comes the bizarre part. When the above code is augmented to include anything in math mode before the ”problem” command is invoked, everything compiles fine. For example \begin{document} $ $ \problem{2} Who is your Daddy and what does he do? $42$ \end{document} compiles with no error. What’s the story here? Thanks in advance for your input. EDIT: The issue appears to have something to do with fontspec since replacing the package luatextra with luacode AND fontspec still exhibits the same behavior. 932

Tags: math-mode (Prev Q) User: tim

Answer by david-carlisle You can cut the example down to Skip code block \documentclass{article} \RequirePackage{fontspec}

\directlua{ function record (m,n) file = assert(io.open("test2.dat","a")) end }

\begin{document}

\directlua{record(1 ,"x")} $42$ \end{document} The error is mostly using the variable name file if you change that to zzz = assert(io.open("test2.dat","a")) then it runs without error.

Tags: math-mode (Prev Q)

933

MiKTeX Skip to questions, Wiki by user doncherry MiKTeX is a widely used TeX distribution available only for Windows. For a typical (La)TeX setup, you will also need an editor, which functions as a graphical front-end to the distribution. You can find a big list of editors at our question LaTeX Editors/IDEs. Installing You can download MiKTeX for free. If you choose the Basic Installer, more packages will be installed when you use them for the first time; if you choose the Net Installer, it will install all packages right away. (Cf. What is the difference between the basic MiKTeX and the complete MiKTeX?) When installing, make sure to install the TeX distribution (MiKTeX) first, and afterwards an editor. This way, the editor will most likely be able to find the TeX binaries automatically and do the configuration for you. During the installation process, you will be asked if you want to install it as a single-user or a net installation [I’m not entirely sure if these are the specific terms used. doncherry]. Unless you know very specifically that the net installation is what you need, the single-user will be the better choice. It has nothing to do with being able to use LaTeX on several Windows user accounts, you can do that with the single-user installation as well. (Cf. Difference between administrative and user mode of MiKTeX) Learning If you’re just beginning to learn LaTeX, The Not So Short Introduction to LaTeX2� is a popular choice, you can find more options at What are good learning resources for a LaTeX beginner?. Also, take a look at Best Way to Start Using LaTeX/TeX?. Besides that, you seem to have found tex.sx, so you’re in the right place already :).

934

Alternatives The other of the two popular TeX distributions if TeX Live. You can learn about some of the differences between the two at What are the advantages of TeX Live over MiKTeX?. You might also come across proTeXt. This is in a category of its own in a way. It simply is a bundle of software, each of which you could get independently as well. The two most important pieces of software are MiKTeX (distribution) and TeXstudio (editor). proTeXt is a good choice for a total beginner, since it sets you up with everything you need and it includes a detailed installation guide. (Cf. What to download, proTeXt or MiKTeX?)

Questions Q: How do I use LuaTex in MikTeX? Tags: miktex (Prev Q) (Next Q) I am using MikTeX 2.9 version and although the manual says I can use LuaTeX, there is nothing in the TeXworks menu. I can see all the other members of the TeX family but none for LuaTeX. Can someone point me as to how to configure it? I am using Windows Vista. Tags: miktex (Prev Q) (Next Q) User: alif

Answer by alain-matthes In preferences, composition, processing tools, you can add your preferred engines here in case luatex or lualatex ... For Linux it’s like that and also for os x I think for windows it’s the same. You can see the command line for others engines, and after you can adapt for luatex and windows. First the command line ( /home/yourname/TeXLive/bin/i386-linux/luatex) then options, $synctexoption (to sync with the pdf) and $fullname.

935

you can add also %!TEX TS-program = lualatex before your code !

Tags: miktex (Prev Q) (Next Q)

Q: Is it possible to pass options to mpost.exe using luamplib? Tags: miktex (Prev Q) (Next Q), metapost (Prev Q) (Next Q) I would like to use the development version of metapost with luamplib. I’ve switched over the executable mpost.exe which is presumable called by luamplib somewhere along the line. Now, I would like to pass the option --math=double to mpost.exe so that I can perform calculations on numbers larger than 4096. Is this possible and, if so, then how can it be done? I run Windows 7 and miktex 2.9 if it’s relevant. Edit, the question above is based on a misunderstanding of how this worked, Khaled cleared that up in the first comment below: What I have done so far (thanks Khaled): 1. Downloaded the latest luatex from here 2. Replaced the binary in my miktex folder with the downloaded version (and updated formats and FNDB just in case). 3. Downloaded the mplib source from here and searched through the file mplibapi.pdf. 4. Found reference to mp_math_double_mode on page 7. 5. Looked through luamplib.lua, and inferred that options could be passed in the function

function load() local mpx = mplib.new { find_file = finder, ini_version = true, math_mode = mp_math_double_mode, initializing instance 'metafun' using format 'metafun' > loading 'metafun': D:/texlive/2012/texmf-dist/metapost/context/b

What is the appropriate way to debug problems with inline METAPOST code in ConTeXt? My example file is:

946

Skip code block \loggingall \starttext \framed{Hello world.} This is a simple_test. \startMPpage loggingall; fill fullcircle scaled 1in withcolor blue; label.top(btex This is a test. etex, origin); \stopMPpage \stoptext I am using TeXLive 2012 on Windows. I apologize for any vagueness in this question. I’m not really sure how the various pieces fit together. Tags: context (Prev Q) (Next Q), metapost (Prev Q) (Next Q) User: colin-fraizer

Answer by marco By default MetaPost does not display the messages injected with message. However, the messages can be enabled using \enabletrackers. To enable verbose debug output use tracingall, which prints plenty of debugging output to the console and the log file. Here’s a complete example: Skip code block \enabletrackers [metapost.showlog] \starttext \startMPpage tracingall; 947

message "This is a debug message."; fill fullcircle scaled 1in withcolor blue; label.top(btex This is a test. etex, origin); \stopMPpage \stoptext

Tags: context (Prev Q) (Next Q), metapost (Prev Q) (Next Q)

Q: How to put signature number in footer (derived from page number)? Tags: context (Prev Q) (Next Q), context-mkiv (Prev Q) (Next Q) To make my book easier to bind I’d like to automatically put the signature number with small type in the footer of the first page of each octavo signature (except the first one which is given since it has the title page). So that means I want to do this: If (page number) == ( [some number that is evenly dividable with 16] + 1 ) then write "Book title --- ( ( [page number]-1 ) / 16)" with small type in the footer of the page • How can this be achieved in Context? • How can this be achieved in Plain Tex? Happy for any pointers or examples. Thanks! Tags: context (Prev Q) (Next Q), context-mkiv (Prev Q) (Next Q) User: petaspeedbeaver

Answer by david-carlisle

948

Plain tex version (using e-tex arithmetic could be written in classic tex if needed)

Skip code block \vsize 4\baselineskip \hsize 5cm \pdfpageheight\dimexpr6\baselineskip+2in\relax \pdfpagewidth\dimexpr\hsize+2in\relax \footline={ \hss\tenrm [original plain footer: \folio] \ifnum\numexpr ((\pageno-1)/16)*16\relax=\numexpr\pageno-1\relax {\fiverm [The title (page \the\pageno) 949

signature \the\numexpr ((\pageno-1)/16)+1\relax] }\fi \hss } \raggedright\raggedbottom \def\a{Red yellow blue green } \def\b{\a\a\par\a\a\a\par} \def\c{One two three four \a\a\a five six seven\par} \def\d{\c\c\c\c\par\a\b\c\a\a\b\b\c\c\a\b\c\c}

\d\d \bye

Answer by aditya Here is one way to do this in ConTeXt: Skip code block % Set footnotes in small size \setupfooter[style=small] % Determine footnote content based on lua code \setupfootertexts[\luasetup{footer}] % Get the page number. If page % 16 == 1, typeset content \startluasetups footer local counters = structures.counters local page = counters.value("userpage") local signature if page > 1 and page % 16 == 1 then signature = (page - 1)/16 context("Book title (%s)", signature) end 950

\stopluasetups % Example \starttext \dorecurse{60}{\input knuth \page} \stoptext

Tags: context (Prev Q) (Next Q), context-mkiv (Prev Q) (Next Q)

Q: Write unit tests for Lua in ConTeXt Tags: context (Prev Q) (Next Q), context-mkiv (Prev Q) (Next Q) I would like to write some unit tests for Lua code being used by ConTeXt, and would like to know if anyone else has done this and what may be require in setting up the framework. The Lua code in particular is being stored in separate files (e.g. numbering.lua), meaning that a test runner (e.g. Busted) can just include them with require. It may be worth noting (but probably does not matter) that I am using Python’s unittest as a test runner with lunatic-python. The inherent problem is that the globals defined by LuaTeX and ConTeXt are not naturally in Lua. Tables such as context and texio are simply not accessible without a require that imports them from their corresponding files. (Which looks to be tex/texmf-context/tex/context/base/trac-log.lua and ...who knows, respectively). Has anyone done unit testing of ConTeXt + Lua? What Lua files might one need to include to get the variables? I would expect there to be an entry-point somewhere that would take care of most of the setup.

It looks like the .lua files of relevance would generally be in ./tex/texmf-context/tex/context/ba but I am just guessing, and since there are around 840 .lua files I would be grateful for any guidance on where to start. 951

Tags: context (Prev Q) (Next Q), context-mkiv (Prev Q) (Next Q) User: brian-m.-hunt

Answer by brian-m.-hunt Just following up on the great comments by @Aditya and @phg, I did the following: I created a test suite using the really cool lunatest framework. It is trivial to set up because one only needs to require('lunatest'), and there is a helpful set of examples in test.lua. Once I have created my own my_tests.lua I run it with: context my_tests.lua --purgeall --batchmode --once My python test runner then checks the return code of the context process (which would be non-zero for failure).

Having experimented with this for some bit, I found it challenging to capture the output of the context and texio and other functions. To solve this, I moved away from having ConTeXt start the lua and am using vanilla lua with stubs like this: Skip code block local function stub(name) local stubbed = {} local calls = {} local metatable = { __call = function(meta, ...) local call = {} call.method = nil call.args = arg table.insert(calls, call) end, __index = function(meta, ...) local method = arg[1] return function(...) 952

local call = {} call.method = method call.args = arg table.insert(calls, call) end end } stubbed._calls = calls setmetatable(stubbed, metatable) _G[name] = stubbed end function M.setup() stub('context') stub('texio') end Where M.setup is called by the lunatest runner before each test. The result is that I can now test Lua for the calls it would make to texio and context like this (with a bit more, but not too much, setup involved): Skip code block lt = require('lunatest') function suite.test_double_indent() test_double_indent() lt.assert_len(5, context._calls) lt.assert_equal('\\startitemize\\sym{}\\startitemize\\sym{}', context._calls[1].args[1]) lt.assert_equal('\n\\stopitemize\n\\stopitemize\n\\stopitemize', context._calls[5].args[1]) end In the end, because there is nothing special about this setup (i.e. no luatex variables required) it is easy to invoke with the python-lunatic or other interpreter bridge, if so inclined.

Tags: context (Prev Q) (Next Q), context-mkiv (Prev Q) (Next Q) 953

Q: Replacing matching text with a macro containing information from a CSV file Tags: context (Prev Q) (Next Q) I have some data stored in a CSV file, in this manner: 000000001 @ name @ information @ more information @ some more information I also have a information.tex file containing the numbers from the first column throughout (this file is \input into my main document): \chapter{Some information about 000012311} This is some text about 000012311 and 000012312\footnote{See also 000012313}. \chapter{Some other information} This text is about 000000001. I currently use a BASH script which replaces all numbers appearing information.tex matched to the first column of the CSV file with a macro, \mymacro{}{}{}{}, where each {} contains data from a column (second, third, fourth, and fifth). For e.g., where the input file above contains This text is about 000000001., using the CSV file line above, it becomes This text is about \mymacro{name}{information}{more information}{some more information}., so when compiled, the text is displayed according to the definition of \mymacro. Essentially, I am using BASH to edit information.tex, after which I compile it. Can I remove the need for BASH and do this directly with LuaTeX or some form of ConTeXt? Tags: context (Prev Q) (Next Q) User: village

Answer by holle

954

My approach is to read all lines from the file, split each line in it’s arguments (divided by @) and store the arguments in a lua-table (tableItem) which is added to an other table (dataTable). We give the tableItem a name that we can access each item by name not by index. If we use the first argument of each line for the name we have direct access to the (sub)tables (tableItem) via the given number in the text using a macro called csvData. In this macro one can access the table and its arguments to format a latex-string or do whatever is needed. Skip code block \documentclass{book} \def\csvData#1{% \directlua{ %here one can access the stored arguments of the input line via the table d=dataTable[#1]; tex.sprint(d.arg1..d.arg2..d.arg3..d.arg4..d.arg5)% } } \def\readDataFile{% \directlua{% local input = io.open('datafile.dat', 'r') dataTable = {} for line in input:lines() do local split = string.explode(line,"@") tableItem={split[1]}%item name is the first input argument of the line tableItem.arg1=split[1] tableItem.arg2=split[2] tableItem.arg3=split[3] tableItem.arg4=split[4] tableItem.arg5=split[5] table.insert(dataTable,tableItem) end input:close() }% } 955

\makeatother

\begin{document} \readDataFile \noindent \csvData{000000001}.\\ \csvData{000000004}.\\ \csvData{000000007}.\\ \end{document}

Answer by topskip A simple approach is to call string.explode() for that. As you don’t give the exact detail what goes where, I can only show the frame for that: Skip code block \documentclass{book} \usepackage{luacode} \begin{document} \begin{luacode*}

for line in io.lines("somedata.dat") do local line_t = string.explode(line,"@") tex.sprint(string.format("\\chapter{%s} Some information about %s",line_t[1],lin end \end{luacode*} \end{document} where somedata.dat looks like this: 000000001 @ name @ information @ more information @ some more information 000000002 @ name2 @ information2 @ more information2 @ some more information2

Tags: context (Prev Q) (Next Q) 956

Q: How to make a font book in context/texlua? Tags: context (Prev Q) The following will list all the fonts, but I would like to take it a step further and render a sample of each font. How can ConTeXt render each font in its respective font? Maybe LuaTeX would be good for this? http://wiki.contextgarden.net/Font_Switching suggests three other articles, but I can’t tell which is relevant. Skip code block % When you want list of all fonts in the database you can do this with % a few macros in your document which are provided for this purpose. % nofruns=1 \setupbodyfont[10pt] \starttext \dolookupfontbyspec{filename=*}

\starttabulate \dorecurse{\dolookupnoffound} {\expanded{\NC \dolookupgetkeyofindex{fontname}{\recurselevel} \EQ \dolookupgetk \stoptabulate \stoptext Tags: context (Prev Q) User: selden

957

Answer by henri-menke Use \definedfont[file:]. Alternatively, \definedfont[name:] would also be possible but thereby you just instruct the fontloader to do the fontname-to-filename resolution again, which is pointless because you already have the filename. More info can be found in »Fonts out of ConTeXt« aka Hans’ new font manual. This will most likely take forever and will probably not typeset as some fonts contain bugs or do not contain printable characters. In my TL 2016 installation for example I got the error ! error:

(file /usr/local/texlive/2016/texmf-dist/fonts/afm/urw/avantgar/uagbi8a.

and no pages output. For the first 100 it works okay and I include the first page of this output below. Skip code block \setupbodyfont[10pt] \starttext \dolookupfontbyspec{filename=*}

\starttabulate[|l|l|l|l|] \dorecurse{\dolookupnoffound}{ \expanded{ \NC \recurselevel \NC \dolookupgetkeyofindex{fontname}{\recurselevel} \EQ \dolookupgetkeyofindex{filename}{\recurselevel} \EQ \definedfont[file:\dolookupgetkeyofindex{filename}{\recurselevel}] My test \NC\NR } } \stoptabulate \stoptext

958

959

Tags: context (Prev Q)

Tex Core Skip to questions, Wiki by user will-robertson tex-core is for questions for syntax, semantics and expected behavior of TeX primitive control sequences, regardless of extensions (eTeX, etc.) formats (Plain or LaTeX) and macro packages (tikz). Such questions usually relate to low-level TeX programming or the behaviour of TeX at an underlying level. Questions tagged tex-core will in general cover topics such as TeX primitives (built-in commands), the basics of macro programming, TeX’s expansion mechanism and so on. Good reference works for these low-level TeX concepts include The TeXbook and TeX by Topic (the later is freely available). Note that even Plain TeX is a format in itself; for questions about it specifically, use plain-tex.

Questions Q: Difference between setting parindent and hangindent Tags: tex-core (Prev Q) (Next Q), paragraphs (Next Q) Is there a difference between setting • \parindent to 1em and to setting • \parindent to 0em, \hangindent to 1em, and \hangafter to -1 960

that shows in practical use? The nodes created by TeX are different, but does that show in typesetting at one point? One difference that I see is that the hang* settings are paragraph-local, but I don’t care about that because I create every paragraph using LuaTeX’s tex.linebreak() This question is specific about LuaTeX, but I guess the answer applies to all engines. Sample code: Skip code block \documentclass{article} \begin{document} \linewidth 300pt

\newcommand\text{A wonderful serenity has taken possession of my entire soul, like these sweet mornings of spring which I enjoy with my whole heart. I am alone, and feel the charm of existence in this spot, which was created for the bliss of souls like mine. I am so happy, my dear friend, so absorbed in the exquisite sense of mere tranquil existence, that I neglect my talents.} \text \hangindent=\parindent \parindent 0pt \hangafter=-1 \text \end{document} Tags: tex-core (Prev Q) (Next Q), paragraphs (Next Q) User: topskip

Answer by david-carlisle LaTeX list environments use \parshape (for which \hangafter is a shorthand essentially) so the behaviour there is likely to be different. 961

But perhaps the first difference to bite is that LaTeX’s mechanism to suppress paragraph indentation after section headings (and after mid-paragraph display environments) removes the parindent node but won’t see hangafter. Compare: \section{aaa} \text in the two cases.

Answer by egreg The most important difference is that TeX remembers \parindent, but it resets \hangindent and \hangafter at the end of the paragraph. Skip code block \documentclass{article} \begin{document} \linewidth 100pt

\newcommand\texta{A wonderful serenity has taken possession of my entire soul, lik these sweet mornings of spring which I enjoy with my whole heart. I am alone, and feel the charm of existence in this spot, which was created for the bliss of souls like mine.} \newcommand\textb{I am so happy, my dear friend, so absorbed in the exquisite sense of mere tranquil existence, that I neglect my talents.} \texta \textb \hangindent=\parindent \parindent 0pt \hangafter=-1 962

\texta \textb \end{document}

The second \textb has no indentation. If you also leave a blank line after \hangafter=-1, you’ll see that the second \texta is not indented, because of the resetting. Indeed a \par in vertical mode does almost nothing: what it does is resetting the paragraph shape parameters (\hangindent, \hangafter, \parshape, \looseness). The behavior is identical in TeX, pdfTeX, XeTeX and LuaTeX.

Tags: tex-core (Prev Q) (Next Q), paragraphs (Next Q)

Q: How to display only certain lines of a paragraph? Tags: tex-core (Prev Q) (Next Q), paragraphs (Prev Q) (Next Q) From reading Knuth’s TeX Book (Chapter 14 How TeX Breaks Paragraphs into Lines), I understand that entire paragraphs are read in and then ”massaged” by the ”line-breaking algorithm” in an optimal way (p 91):

963

One of typesetting system’s chief duties is to take long sequences of words and to break it up into individual lines of the appropriate size. ... TeX chooses breakpoints in an interesting way that considers each paragraph in its entirety; the closing words of a paragraph can actually influence the appearance of the first line. As a consequence, I assume that it flushes out the lines on-by-one after performing the optimization on a per-paragraph basis. Is it possible to interrupt this flushing of lines and say only output specific lines of the paragraph? I guess, almost similar to the way paragraphs are broken across pages. For example, by means of defining an environment (say) showlines that one can use in the following way: \begin{showlines}[lines=2] One of typesetting system's chief duties is to take long sequences of words and to break it up into individual lines of the appropriate size. \TeX\ chooses breakpoints in an interesting way that considers each paragraph in its entirety; the closing words of a paragraph can actually influence the appearance of the first line. \end{showlines} And TeX would only output the first two lines of the traditional output (possibly discarding the rest):

Note: Of interest here is to preserve the typesetting after line-breaking optimization has occurred, even in the case of hyphenation, since the tie should be with the shipout of lines. Of course, if there is another method of doing this (for example, possible sub-optimal line-breaking on a line-by-line basis), that would also work.

As a bonus, not just allowing to show the first n lines as in the example above (via [lines=n]), but allowing to show any combin

Tags: tex-core (Prev Q) (Next Q), paragraphs (Prev Q) (Next Q) User: werner 964

Answer by topskip A Lua(La)TeX solution is missing. Not anymore: Skip code block \documentclass{article} \usepackage{luatexbase} \usepackage{luacode} \begin{luacode} twolines = function ( head ) local orig_head = head local linecounter = 0 while head do if head.id == 0 then linecounter = linecounter + 1 end if linecounter > 1 then head.next = nil return true end head = head.next end return true end

luatexbase.add_to_callback("post_linebreak_filter",twolines,"twolines") \end{luacode}

\begin{document} \hsize 4in A wonderful serenity has taken possession of my entire soul, like these swee whole heart. I am alone, and feel the charm of existence in this spot, which was so happy, my dear friend, so absorbed in the exquisite sense of mere tranquil exi 965

incapable of drawing a single stroke at the present moment; and yet I feel that I \end{document} This adds a callback function (twolines) to the post_linebreak_filter which counts the hlists (node id 0) found in a paragraph and just removes everything after the second hlist from the paragraph (a vlist - that is what orig_head is pointing to - not needed in this example). The drawbacks: • It applies to every paragraph. To circumvent this, activate the callback only when needed. See the chickenize package by Arno Trautmann. • It has a memory leak. The nodes after the second hlist are still in a structure. On needs to call node.free(...) to remove the nodes from memory. See the reference manual (chapter 4, node library). • It doesn’t work with iTeX [tinkle a bell]. Edit: here is a full solution, including the environment: Skip code block \documentclass{article} \usepackage{luatexbase} \usepackage{luacode} \begin{luacode} twolines = function ( head ) local linecounter = 0 while head do if head.id == 0 then linecounter = linecounter + 1 end if linecounter >= showlinescount then local lastline=head head = head.next while head do local head_next = head.next node.free(head) head = head_next 966

end lastline.next = nil return true end head = head.next end return true end \end{luacode}

\newenvironment{showlines}[1] {\directlua{showlinescount = tonumber('#1') luatexbase.add_to_callback("post_linebreak_filter",twolines,"twoline {\par \directlua{luatexbase.remove_from_callback("post_linebreak_filter","twolines")} \begin{document} \hsize 4in

\newcommand\sample{A wonderful serenity has taken possession of my entire soul, li of spring which I enjoy with my whole heart. I am alone, and feel the charm of exi which was created for the bliss of souls like mine. I am so happy, my dear friend, sense of mere tranquil existence, that I neglect my talents. I should be incapable stroke at the present moment; and yet I feel that I never was a greater artist tha \begin{showlines}{3} \sample \end{showlines} \sample \end{document} This still doesn’t work with iTeX [tinkle a bell] yet. But it has no memory leak anymore and it offeres a showlines environment.

Answer by andrey-vihrov 967

When TeX breaks a paragraph into lines, it constructs a hbox for each line. This stack of hboxes can be placed in a vbox (so that there is actually a first hbox) and analyzed one hbox at a time using the \lastbox operation. The following code was heavily influenced by TeX by Topic, subsection 5.9.6. Skip code block \documentclass{article} \usepackage{lipsum} \newbox\linebox \newcount\mycount \def\processline{% Underline every second line \global\advance\mycount by 1 \ifodd\mycount \underline{\box\linebox}% \else \box\linebox \fi} \def\splitlines{% \setbox\linebox\lastbox \ifvoid\linebox \noindent\ignorespaces \else \unskip\unpenalty \begingroup\splitlines\space\endgroup \processline \fi} \long\def\doit#1{\vbox{#1\par\splitlines}} \begin{document} \doit{\lipsum[1]}

968

\end{document} You can redefine \processline to suit your needs. For example, it might discard lines conditionally or \unhbox them for further changes. Selecting lines by number is now a matter of going through the hboxes and comparing numbers. It might be necessary to dissect the vbox twice.

Answer by egreg The following code outputs the number of lines stated in the argument, provided all the lines have the same height (more precisely, the baselines are uniformly spaced): Skip code block \documentclass[a4paper]{article} \makeatletter \newbox\wernerboxa \newbox\wernerboxb \newenvironment{showlines}[1] {\vbadness=\@M\def\[email protected]{#1}\par \setbox\wernerboxa=\vbox\bgroup} {\egroup\setbox\wernerboxb=\vsplit\wernerboxa to\[email protected]\baselineskip \vbox{\unvbox\wernerboxb}} \makeatother \usepackage{lipsum} \begin{document} \begin{showlines}{5} \lipsum \end{showlines} \end{document} Repeating the \vsplit operation recursively can solve the problem of showing a specified list of lines. Let’s look at another approach that can cope with the case when there are 969

higher objects in a line. If the paragraph has no fancy things, but only plain text, a modification of an answer of mine will underline each line of the paragraph; actually the rule is added by the macro \[email protected], so it’s possible to modify it in such a way that it draws the rule only if certain conditions are satisfied; the final number of lines is available in the macro \[email protected] This works bottom up; it shouldn’t be so complicated to add a check whether a line must be underlined. Skip code block \documentclass[a4paper]{article} \usepackage{lipsum} \makeatletter \newif\ifboxended \newbox\wernerbox \def\[email protected]{\kern0.8\[email protected]\hrule\kern-1.2\[email protected]} \newenvironment{werner} {\par\setbox\wernerbox=\vbox\bgroup} {\par\xdef\[email protected]{\the\prevgraf}\egroup \message{The box has \[email protected]\space lines}% \underlinevbox} \def\underlinevbox{\begingroup\global\setbox\@ne=\box\[email protected] \global\boxendedfalse \setbox\[email protected]=\copy\wernerbox\relax\dounderlinevbox} \def\dounderlinevbox{% \setbox\[email protected]=\vbox{\unvbox\[email protected] \ifcase\lastnodetype % char node (can't remove) \or % hlist node \setbox\[email protected]=\lastbox \def\next{\global\setbox\@ne=\vbox{\box\[email protected]\[email protected]\unvbox\@ne}}% \or % vlist node 970

% % % % % % % % %

%

%

% % %

\setbox\[email protected]=\lastbox \def\next{\global\setbox\@ne=\vbox{\box\[email protected]\[email protected]\unvbox\@ne}}% \or rule node (can't remove) \or ins node (can't remove) \or mark node (can't remove) \or adjust node (can't remove) \or ligature node (can't happen) \or disc node (can't happen) \or whatsit node (can't remove) \or math node (can't remove) \or glue node \[email protected]=\lastskip\unskip \def\next{\global\setbox\@ne=\vbox{\vskip\[email protected]\unvbox\@ne}}% \or kern node \[email protected]=\lastkern\unkern \def\next{\global\setbox\@ne=\vbox{\kern\[email protected]\unvbox\@ne}}% \or penalty node \[email protected]=\lastpenalty\unpenalty \def\next{\global\setbox\@ne=\vbox{\penalty\[email protected]\unvbox\@ne}}% \or unset node (can't happen) \or math mode node (can't remove) \else empty list \def\next{\global\boxendedtrue} \fi 971

\next} \ifboxended \def\next{\unvbox\@ne\endgroup} \else \let\next\dounderlinevbox \fi \next} \makeatother \begin{document} \begin{werner} \lipsum[2] \end{werner} \end{document} The code can be modified in order to output only specified lines. It should be noted that the dismantling happens from the bottom line up.

Tags: tex-core (Prev Q) (Next Q), paragraphs (Prev Q) (Next Q)

Q: Namespace in luatex Tags: tex-core (Prev Q) (Next Q) Is it possible from luatex access registers where all names of command sequences are stored. Is it possible to pull out this list of names? I am looking for a way to trace how namespace changes during compilation of latex document. Tags: tex-core (Prev Q) (Next Q) User: baranas

Answer by david-carlisle This is a dump of the hashtable that stores the command names. 972

Skip code block \documentclass{article} \newcommand\wibble{hello} \begin{document} \directlua{ for i, v in pairs (tex.hashtokens()) do texio.write_nl(i) end} \end{document} it outputs a long list, but testing with lualatex testfile.tex | grep wibble produces wibble Showing it includes all commands defined up to the point of the dump. the luatex manual warns that this is the internal hashtable, not all the commands may be defined or reachable from tex due to scoping and other issues.

Tags: tex-core (Prev Q) (Next Q)

Q: How to not have widows and orphans without using raggedbottom Tags: tex-core (Prev Q), page-breaking (Next Q) I know I can set \clubpenalty and \widowpenalty to 10 000 to make them “really bad”, but then TeX sees it equally bad to cut the page short when there is no vertical stretch (i.e. \parskip=0pt), and so I’m left with underfull pages often. 973

The question is: Would it somehow be possible in those cases to instruct TeX to re-do the whole page, for example, trying to get it one line shorter or longer? (Not the page as in \vsize, but the typeset texts space requirements) Maybe this could be possible with LuaTeX? Or some clever output routine? [ Update]Update OK so now, as per comments, I’ve played with the eTeX \club-/\widowpenalties. But either I don’t understand how they work, or they do not help with the problem: Skip code block \font\bodyfont=cmr10 at 11bp \bodyfont \frenchspacing \parskip=0pt \baselineskip=15bp \topskip=15bp \parindent=1em \hsize=27pc \vsize=525bp % 525 / 15 = 35, the number of lines \clubpenalties=2 10000 0 \widowpenalties=2 10000 0 \looseness=1 \input a_novel \bye The pages are cut short when there would be a widow/orphan. References Jonathan Fines “Line breaking and page breaking” hints at a possible global optimisation via multiple passes. David Salomon writes in his book “The Advanced TeXbook” about “A global page-break algorithm”, but I cannot find the reference (Ref. 37). 974

Tags: tex-core (Prev Q), page-breaking (Next Q) User: morbusg

Answer by topskip It is surely impossible to have all of the following conditions: 1. No clubs/widows 2. TeX must not change the paragraph 3. Number of lines must be fixed Since TeX breaks paragraphs before looking at pages, it has no chance to redo 2). With LuaTeX you could probably cook your own automatic solution, but this is pretty much the opposite of ’trivial’. In PDFTeX you have to manually tell TeX to re-arrange the paragraphs. The \looseness parameter tells TeX to make the paragraph larger or smaller, but only if it can do so (\tolerance and such). The following code is a sample document which has no widows/clubs, but the paragraphs are not pretty anymore: Skip code block \font\bodyfont=cmr10 at 11bp \bodyfont \frenchspacing \parskip=0pt \baselineskip=15bp \topskip=15bp \parindent=1em \hsize=27pc \vsize=525bp % 525 / 15 = 35, the number of lines \clubpenalties=2 10000 0 \widowpenalties=2 10000 0

\def\a{A wonderful serenity has taken possession of my entire soul, like these swe mornings of spring which I enjoy with my whole heart. I am alone, and feel the charm of existence in this spot, which was created for the bliss of souls like 975

mine. I am so happy, my dear friend, so absorbed in the exquisite sense of mere tranquil existence, that I neglect my talents. I should be incapable of drawing a single stroke at the present moment; and yet I feel that I never was a greater artist than now. When, while the lovely valley teems with vapour around me, and the meridian sun strikes the upper surface of the impenetrable foliage of my trees, and but a few stray gleams steal into the inner sanctuary, I throw myself down among the tall grass by the trickling stream; and, as I lie close to the earth, a thousand unknown plants are noticed by me: when I hear the buzz of the little world among the stalks, and grow familiar with the countless indescribable forms of the insects and flies, then I feel the presence of the Almighty, who formed us in his own image, and the breath of that universal love which bears and sustains us, as it floats around us in an \par} \a \looseness=-1\a \tolerance300\looseness=2\a \looseness=2\a \bye

Tags: tex-core (Prev Q), page-breaking (Next Q)

Symbols Skip to questions, Wiki by user stefan-kottwitz Choose this tag if your question is about specific symbols, for instance looking-up, constructing, or using symbols. If you look for a symbol, you might browse the Comprehensive LaTeX Symbol list. Alternatively you could use the LaTeX symbol classifier tool: draw a symbol - get the code.

976

If your question is about fonts, choose fonts instead.

Questions Q: How to pick a specific symbol from a specific font? Tags: symbols (Prev Q) (Next Q) Using LuaLatex, I need two very specific symbols from two very specific fonts, namely from the ZapfDingbats and the WingDings font. I understand how I could use the fontspec package to set those fonts as standard fonts for my document. But for obvious reasons, I don’t want that. How do I pick a specific symbol from a specific font (with LuaLatex)? While still using PDFLatex, I used the pifont package to get the Dingbats character: \documentclass{article} \usepackage{pifont} \begin{document} \ding{113} \end{document} Doesn’t work for WingDings, though, which is why I switched to LuaLatex. However, not only did I understand that using such ”font packages” is deprecated with LuaLatex, but I also don’t have a clue how I’d go about picking a specific symbol from the WingDings font... Tags: symbols (Prev Q) (Next Q) User: devsolar

Answer by leo-liu Skip code block

977

\documentclass{article} \usepackage{fontspec} \newfontfamily\wingdingsfont{Wingdings} \newcommand\wingdings[1]{{\wingdingsfont\symbol{#1}}} \usepackage{fonttable} \begin{document} \wingdings{40} 123-4567-8900 \fonttable{Wingdings} \end{document}

Tags: symbols (Prev Q) (Next Q)

Q: Printing backslash from a luacode* environment Tags: symbols (Prev Q) My first attempt with LuaLaTex gave me some headache, trying to generate LaTex code from within LuaLaTex. This required me to print the backslash (to get a LaTeX control sequence).. I think I have found a solution now, but maybe this could also be of interest to others, so I try to post it here as question anyway.. (See also the following questions Printing LaTeX code in LuaTeX and How does one insert a backslash or a tilde into LaTeX?) From the luacode package documentation, page 2 it says: The variant luacode* goes further and makes even backslash a normal character Consider the following code: \documentclass{article} \usepackage{luacode} \begin{document} 978

\begin{luacode*} tex.sprint("\"); \end{luacode*} \end{document} Compiling this with lualatex gives the error ! LuaTeX error :1: unfinished string near '"");'. \[email protected]@exec [email protected]@printdbg {#1} #1 } Then I thought I just have to add another backslash to escape the first: tex.sprint("\\"); But now I get the error: ! Undefined control sequence. l.1 Tags: symbols (Prev Q) User: håkon-hægland

Answer by håkon-hægland The problem is that there are 3 interpretation stages involved. • First macro expansion (this is avoided in my example due to the luacode* environment) • Then Lua interprets the resulting string, where a backslash is an escape character • At last LaTex again interprets what Lua has printed.. I had forgotten the last stage.. So the solution is: tex.sprint("$\\backslash$"); or tex.sprint("\\textbackslash");

Tags: symbols (Prev Q)

979

Polyglossia Skip to questions, Wiki by user alan-munn If you are using XeLaTeX, you should load polyglossia instead of babel. The package does the following automatically: • Loading the appropriate hyphenation patterns. • Setting the script and language tags of the current font (if possible and available), via the package fontspec. • Switching to a font assigned by the user to a particular script or language. - Adjusting some typographical conventions according to the current language (such as afterindent, frenchindent, spaces before or after punctuation marks, etc.). • Redefining all document strings (like “chapter”, “figure”, “bibliography”). - Adapting the formatting of dates (for non-Gregorian calendars via external packages bundled with polyglossia: currently the Hebrew, Islamic and Farsi calendars are supported). • For languages that have their own numbering system, modifying the formatting of numbers appropriately (this also includes redefining the alphabetic sequence for non-Latin alphabets). • Ensuring proper directionality if the document contains languages that are written from right to left (via the package bidi, available separately). (Polyglossia documentation, p.2) Don’t be alarmed if your log file mentions babel hyphenation patterns when you are using polyglossia. This is normal, and is due to how hyphenation patterns are loaded; it does not mean that the babel package has been loaded.

980

The homepage of polyglossia is at github.

Questions Q: Changing language back and forth with polyglossia Tags: polyglossia (Prev Q) (Next Q) I’m using polyglossia and lualatex to compile my source, and I am switching languages back and forth inside my document. It looks like polyglossia (or myself), is not doing what it is supposed to do: Skip code block \documentclass[12pt]{book} \usepackage{polyglossia} \setdefaultlanguage{english} \setotherlanguage{french} \begin{document} \textsc{url:} www. \\ \begin{french} \textsc{url:} www. \\ \end{french} \textsc{url:} www. \\ \end{document} First line prints ”url: www.” in English: OK. Second line prints ”url : www.” in French: OK. Third line prints ”url : www.” in English: not OK (there should not be a space before the colon). Am I doing something wrong ? Thank you. Tags: polyglossia (Prev Q) (Next Q) User: bigdawg

Answer by ulrike-fischer

981

You can reset the ”nonfrench”-spacing with a \directlua-call. But it will affect the whole paragraph: Skip code block \documentclass[12pt]{book} \usepackage{polyglossia} \setdefaultlanguage{english} \setotherlanguage{french} \begin{document} \textsc{url:} www. \begin{french} \textsc{url:} www. \end{french} \directlua{polyglossia.desactivate_frpt()} \textsc{url:} www. \begin{french} \textsc{url:} www. \end{french} %affects the preceding french too: \directlua{polyglossia.desactivate_frpt()} \textsc{url:} www. \end{document}

Answer by herbert Use babel instead: Skip code block \documentclass[12pt]{book} \usepackage[french,english]{babel} \begin{document} \textsc{url:} www.

982

\begin{otherlanguage}{french} \textsc{url:} www. \end{otherlanguage} \textsc{url:} www. \end{document}

Tags: polyglossia (Prev Q) (Next Q)

Q: Macro definition not working when using LuaLaTeX and polyglossia (with ‘\setmainlanguage{german}‘) Tags: polyglossia (Prev Q) I’m compiling the following MWE with LuaLaTeX in an updated TexLive 2017 installation on Ubuntu: Skip code block % !TeX program=lualatex \documentclass[a4paper,12pt,twoside=semi,openright]{scrbook} \usepackage{polyglossia} \setmainlanguage{german} \setotherlanguage{english} \usepackage{fontspec} \usepackage{subfig} \usepackage{amsmath} \usepackage{amssymb} \usepackage{bm} \renewcommand{\vec}[1]{\bm{#1}} \begin{document} 983

\begin{align} \vec{x} = 1 \end{align} \end{document} Here’s what I get:

The desired output would of course be x=1. Note that this fails only when using \setmainlanguage{german}. It also works fine using pdfLaTeX and babel. Skip code block *File List* scrbook.cls 2017/09/07 v3.24 KOMA-Script document class (book) scrkbase.sty 2017/09/07 v3.24 KOMA-Script package (KOMA-Script-dependent basi cs and keyval usage) scrbase.sty 2017/09/07 v3.24 KOMA-Script package (KOMA-Script-independent ba sics and keyval usage) keyval.sty 2014/10/28 v1.15 key=value parser (DPC) scrlfile.sty 2017/09/07 v3.24 KOMA-Script package (loading files) tocbasic.sty 2017/09/07 v3.24 KOMA-Script package (handling toc-files) scrsize12pt.clo 2017/09/07 v3.24 KOMA-Script font size class option (12pt) typearea.sty 2017/09/07 v3.24 KOMA-Script package (type area) polyglossia.sty 2015/03/25 v1.42.4 Alternative to Babel for XeLaTeX and LuaLa TeX etoolbox.sty 2017/01/02 v2.4 e-TeX tools for LaTeX (JAW) makecmds.sty 2009/09/03 v1.0a extra command making commands xkeyval.sty 2014/12/03 v2.7a package option processing (HA) xkeyval.tex 2014/12/03 v2.7a key=value parser (HA) fontspec.sty 2017/11/09 v2.6g Font selection for XeLaTeX and LuaLaTeX 984

xparse.sty 2017/11/14 L3 Experimental document command parser expl3.sty 2017/11/14 L3 programming layer (loader) expl3-code.tex 2017/11/14 L3 programming layer l3pdfmode.def 2017/03/18 v L3 Experimental driver: PDF mode fontspec-luatex.sty 2017/11/09 v2.6g Font selection for XeLaTeX and LuaLaTeX fontenc.sty tuenc.def 2017/04/05 v2.0i Standard LaTeX file fontspec.cfg ifluatex.sty 2016/05/16 v1.4 Provides the ifluatex switch (HO) ifxetex.sty 2010/09/12 v0.6 Provides ifxetex conditional luatexbase.sty 2015/10/04 v1.3 luatexbase interface to LuaTeX ctablestack.sty 2015/10/01 v1.0 Catcode table stable support gloss-german.ldf polyglossia: module for german babelsh.def 2013/04/30 Babel common definitions for shorthands Taken verbatim from babel.def (2013/04/15 v3.9e) gloss-english.ldf polyglossia: module for english subfig.sty 2005/06/28 ver: 1.3 subfig package caption.sty 2016/02/21 v3.3-144 Customizing captions (AR) caption3.sty 2016/05/22 v1.7-166 caption3 kernel (AR) amsmath.sty 2017/09/02 v2.17a AMS math features amstext.sty 2000/06/29 v2.01 AMS text amsgen.sty 1999/11/30 v2.0 generic functions amsbsy.sty 1999/11/29 v1.2d Bold Symbols amsopn.sty 2016/03/08 v2.02 operator names amssymb.sty 2013/01/14 v3.01 AMS font symbols amsfonts.sty 2013/01/14 v3.01 Basic AMSFonts support bm.sty 2017/01/16 v1.2c Bold Symbol Support (DPC/FMi) umsa.fd 2013/01/14 v3.01 AMS symbols A umsb.fd 2013/01/14 v3.01 AMS symbols B *********** Tags: polyglossia (Prev Q) User: christoph90

Answer by mico Under LuaLaTeX, the packages amsmath, amssymb, and bm should always be 985

loaded before both fontspec and polyglossia. (It also used to be standard to advise to load fontspec after any packages that modify math-related macros -- such as, of course, amsmath, amssymb, and bm. However, at some point in the recent past, an update to fontspec has occurred which no longer makes this recommendation a necessity.) If, for some reason, you simply must load polyglossia first, then at least defer the instructions \setmainlanguage{...} and \setotherlanguage{...} to a point later on in the preamble, i.e., after amsmath, amssymb, bm and fontspec have been loaded. Do note that I deliberately started the answer with ”Under LuaLaTeX, ...”: I’m afraid I have no experience with package loading orderings under XeLaTeX. The following, modified version of your MWE compiles fine: Skip code block % !TeX program=lualatex \documentclass[a4paper,12pt,twoside=semi,openright]{scrbook} \usepackage{amsmath,amssymb,bm} \usepackage{fontspec} \usepackage{polyglossia} % load it *after* amsmath, amssymb, bm, and fontspec \setmainlanguage{german} \setotherlanguage{english} \usepackage{subfig} % it doesn't seem to matter when this package is loaded \renewcommand{\vec}[1]{\bm{#1}} \begin{document} \[ \vec{x} = 1 \] \end{document}

Answer by egreg The problem is that \setmainlanguage{german} sets " to a shorthand char986

acter and loading bm after that declaration completely breaks the definitions made by the package when LuaLaTeX is used. The bizarre string you get is essentially random. Without loading subfig you get nothing (but no x either). Loading amsmath and bm before or after polyglossia is irrelevant, as long as the language declarations are made after package loading. Skip code block \documentclass{article} \usepackage{polyglossia} \usepackage{amsmath} \usepackage{amssymb} \usepackage{bm} \usepackage{subfig} \setmainlanguage{german} \renewcommand{\vec}[1]{\bm{#1}} \begin{document} $\vec{x}$ \end{document} Try moving \usepackage{bm} after \setmainlanguage{german} and the issue will appear again.

Tags: polyglossia (Prev Q)

987

Shell Escape Skip to questions, Wiki by user user13907 If enabled, {shell-escape} mode allows the use of a list of commands which can be specified using \write18{commandlist} in a .tex document. The command \write is a TeX primitive used to write to different streams. The use of stream 18 means that TeX is asking the operating system to do something. The use of \write18{} is usually disabled for security reasons. It must be enabled explicitly using latex --shell-escape texfile.

Questions Q: How should I have found out that LuaTeX removed \write18? Tags: shell-escape (Prev Q) (Next Q) I’m trying very hard not to make this sound like a rant, but I’m very angry right now. I was trying to use the TikZ externalization to create a scatter plot for my thesis. There were too many data points for TeX’s memory so I switched to LuaTeX. The externalization didn’t work. (MWE like: \documentclass{article} \usepackage{tikz} \usetikzlibrary{external} \tikzexternalize \begin{document} \tikz\node{Hello}; \end{document} )

988

I had past experience with MiKTeX that suggested that changing -shell-escape to -enable-write18 can make a difference, as well as -enable-write18 vs --enable-write18. I spent literally half a day (remember, LuaTeX compilation times are still orders of magnitude slower on MiKTeX) trying to make it work and figure out why it doesn’t, changing the command line around as well as the value of tikz/external/shell escape. Nothing worked. Today I do a Google search and I find the answer at https://github.com/ gpoore/minted/issues/112: There is no more \write18 in LuaTeX. You have to \usepackage{shellesc} which adds it back again. My question is, I’m trying to be a good user here and always RTFM. Where is TFM I should have read to find out that this functionality was removed and how to add it back? To avoid spending half a day thinking I’m doing something wrong? Surely it’s not the Github issue of a completely unrelated package? Tags: shell-escape (Prev Q) (Next Q) User: marczellm

Answer by egreg It’s a bit unfortunate that Christian Schenk deploys in MiKTeX new versions of the binaries (luatex in this case) as soon as they are available. TeX Live only changes (core) binaries with the yearly release and doesn’t modify them during the year (except for very serious bugs, but these are usually caught during the pretest phase). When LuaTeX 0.87 was released, many changes were made, in particular the one about \write18. If you look at LaTeX News 24, released February 2016, you’ll see

989

and also

Answer by ulrike-fischer The manual of luatex mentions the change: Also, we no longer support write18 because os.execute can do the 990

same. But I doubt very much that even if you had read this that you would have understand the implications and that it could affect tikzexternalize. The change happened last year and if you search this site for shellesc you will find a number of questions (also involving texlive, it is not a miktex specific problem, Cannot run tikz externalize with lualatex but it used to work). But again: even if you saw one of this questions during the year I wouldn’t expect from you to remember them and realize that they applicate to your current problem. So what could you do? Some tipps: • Changes happen, even more with new software like luatex. Accept this. • Not every change is obvious and can be learned by reading the manual. • Don’t try to solve your problems for hours alone. Search a bit and if you have the impression that you don’t make any progress then better spent your time to make a sensible minimal example and then ask.

Answer by david-carlisle If using a beta release of software it’s best to follow its development channels as breaking changes are expected in beta releases. This was discussed on the luatex list before the change was made. (Not true of all breaking changes in luatex:-). For example this thread from November 2015 http://tug.org/ pipermail/luatex/2015-November/005499.html Without following the mailing list, this change was flagged in ltnews and also in the luatex manual. That said, in an ideal world an end user would not need to know this at all, we did search ctan for every use of \write18 that we could find and try to reach out to package developers to update packages before the changed luatex was distributed in major distributions. The minted github issue that you referenced being one example of that. That there are still packages that require the end user to use shellesc (or luatex85) packages is a bit unfortunate but a possibly unavoidable result of the distributed nature of LaTeX package development. Packages are updated as and when the developers have time or inclination to publish an update. 991

Tags: shell-escape (Prev Q) (Next Q)

Q: gnuplottex and lualatex Tags: shell-escape (Prev Q) (Next Q) EDIT: This question covers a bug in gnuplottex which will be fixed in TeXLive 2013.If you still want to have the bug fixed, download the latest upstream version from CTAN and compile it yourself.

Let gnu.tex Skip code block \documentclass[border=3mm]{standalone} \usepackage{gnuplottex} % use gnuplot \usepackage{epstopdf} % convert resulting eps to pdf \begin{document} \begin{gnuplot}[terminal=epslatex,terminaloptions=color] set xlabel '$x$' set ylabel '$y$' plot sin(x) title '$\sin x$' \end{gnuplot} \end{document} I am now trying to compile with lualatex; unfortuantely this doesn’t work. I called lualatex in the manner $ lualatex --shell-escape gnu.tex The log file reads ... \write18 enabled. 992

... Package gnuplottex Warning: Shell escape not enabled. (gnuplottex) You'll need to convert the graphs yourself.. ... If I compile with pdflatex and the command line $ pdflatex --shell-escape gnu.tex it works just fine. Summary: Is gnuplottex incompatible with lualatex? Tags: shell-escape (Prev Q) (Next Q) User: henri-menke

Answer by egreg I’d consider this a bug in gnuplottex.sty: the package tests shell escape by writing a file in /tmp and assigning it a name without extension. TeX implementations may differ in the treatment of missing extensions in file names, but should do the same thing when an extension is found. So if the test is Skip code block %% test if shell escape really works \ifShellEscape \def\tmpfile{/tmp/w18-test-\the\year\the\month\the\day\the\time.tex} \ifmiktex \def\tmpfile{w18-test-\the\year\the\month\the\day\the\time.tex} \immediate\write18{echo t > "\tmpfile"} \else \immediate\write18{touch \tmpfile} \fi \IfFileExists{\tmpfile}{\ShellEscapetrue}{\ShellEscapefalse} \ifmiktex \immediate\write18{del "\tmpfile"} \else \immediate\write18{rm -f \tmpfile} 993

\fi \fi all will work (I’ve added an explicit .tex extension). You can work around this bug by adding your own test: Skip code block \documentclass[border=3mm]{standalone} \usepackage{gnuplottex} % use gnuplot \usepackage{pdftexcmds,ifluatex} \makeatletter \ifluatex \ifnum\[email protected]=\@ne \ShellEscapetrue \fi \fi \makeatother \usepackage{epstopdf} % convert resulting eps to pdf \begin{document} \begin{gnuplot}[terminal=epslatex,terminaloptions=color] set xlabel '$x$' set ylabel '$y$' plot sin(x) title '$\sin x$' \end{gnuplot} \end{document} You’ll still get the message, but the document will compile correctly when -shell-escape is given in the command line. You need LuaTeX version >0.67 for this workaround, though.

Tags: shell-escape (Prev Q) (Next Q)

994

Q: Using macros in \DeclareGraphicsRule statement using shell command Tags: shell-escape (Prev Q) I am currently working on a document which i am compiling under both linux and windows. As one of the images I use is a tif image, I’d like to have lualatex converting it on-runtime to a format it understands. Therefore, I managed to do this under linux using \DeclareGraphicsRule{.tif}{png}{.png}% {% `convert #1 `dirname #1`/`basename #1 .tif`-tif-converted-to.png % } \AppendGraphicsExtensions{.tif} This however is not portable to windows because of the dirname and basename commands (as installing ImageMagick makes convert available). Therefore, I would like to use the file parsing from latex to do this, but I could not find my way around it. The code I am currently trying to use is : \makeatletter \newrobustcmd*\dirname[1]{\[email protected]{#1}\[email protected]}% \newrobustcmd*\basename[1]{\[email protected]{#1}\[email protected]}% \DeclareGraphicsRule{.tif}{png}{.png}% {% `convert #1 \dirname{#1}/\basename{#1}-tif-converted-to.png % }% \makeatother \AppendGraphicsExtensions{.tif} However, \DeclareGraphicsRule seems to just ignore I have used macros in my command. So my question is the following : • What am I doing wrong ? • Is there a way around it ? EDIT : Slightly changing the working command

995

Tags: shell-escape (Prev Q) User: samuel-albert

Answer by heiko-oberdiek The conversion via shell escape is added by package epstopdf. In TeX Live it is automatically loaded, if pdfTeX/LuaTeX is detected in PDF mode and 1. LaTeX is running (plain TeX users are on their own), 2. and shell escape (\write18) is enabled (possibly restricted), 3. and \DoNotLoadEpstopdf either does not exist or is not \relax. For convenience the package epstopdf provides a macro to define a graphics rule with conversion program (1.5.3 Conversion program): \epstopdfDeclareGraphicsRule{.tif}{png}{.png}{% convert #1 \OutputFile } Also the backtick notation with \DeclareGraphicsRule can be used: \DeclareGraphicsRule{.tif}{png}{.png}{% \noexpand\epstopdfcall{convert #1 \noexpand\OutputFile}% } • \noexpand is needd, because \DeclareGraphicsRule expands the argument. • \epstopdfcall deals with packages like pst2pdf. The name of the output file \OutputFile is controlled by options. Since version 2009/07/12 v2.0 the default for option suffix is suffix=-\SourceExt-converted-to The suffix is inserted after the base name and the new file extension. foo.tif becomes foo-tif-converted-to.png.

Answer by egreg Macros defined with \newrobustcmd (from etoolbox) are not expanded in \write operations. However \[email protected] relies on assignments which 996

aren’t performed in those operations. I suggest to define

\def\eattif#1.tif{#1} \DeclareGraphicsRule{.tif}{png}{.png}{`convert #1 \eattif#1-tif-converted-to.png } \AppendGraphicsExtensions{.tif} so that the extension will be swallowed (in an expandable fashion).

Tags: shell-escape (Prev Q)

Pgfplots Questions Q: LuaLaTeX:PGFplots can’t read data passed by Lua Tags: pgfplots (Prev Q) (Next Q) I wanted to give a LuaLaTeX answer to this question Here it is the listing I wrote: Skip code block % !TEX encoding = UTF-8 % !TEX program = LuaLaTeX % !TEX spellcheck = en_GB \documentclass{standalone} \usepackage{pgfplots} \usepackage{luacode} \begin{luacode*} -- Code taken by 997

-- http://rosettacode.org/wiki/Gamma_function#Lua function recigamma(z) local gamma = 0.577215664901 local coeff = -0.65587807152056 local quad = -0.042002635033944 local qui = 0.16653861138228 local set = -0.042197734555571 return z+gamma*z^2+coeff*z^3+quad*z^4+qui*z^5+set*z^6 end function gamma(z) if z == 1 then return 1 elseif math.abs(z) 0 then tex.print([[Result of mplib execute is unsuccessfull.]]) else if result.fig then tex.sprint('Converted something: \\vrule\\vbox{\\hrule') local converted=luamplib.convert(result) tex.sprint('\\hrule}\\vrule') else tex.print([[No figure output.]]) tex.print([[Log:]]) tex.print(l) end end mpx:finish() end I will try to improve (=shorten) it more. E.g., I believe that there is a way to use finder function from luamplib. Any comments are welcome. Tags: metapost (Prev Q), graphics (Prev Q) (Next Q) User: misha

Answer by taco-hoekwater The file mplibapi.pdf from the metapost source distrobution documents the low-level interface. Still, it is probably wise to read the luamplib code as 1019

well, because the conversion from mplib’s return table (containing images) to PDF literal code is not quite trivial. http://www.tug.org/metapost/src/ manual/mplibapi.pdf

Tags: metapost (Prev Q), graphics (Prev Q) (Next Q)

Paragraphs Questions Q: Replacement(s) for TeX’s paragraph builder using LuaTeX Tags: paragraphs (Prev Q) (Next Q) The LuaTeX engine provides a callback that allows you to replace the built-in paragraph builder by your own algorithm. My question is twofold: • does there exist a lua implementation that fully (or partially) reimplements the normal algorithm that can be used as a basis for paragraph breaking experiences? • if not (or even if yes) are there any other known uses of this callback? Update Given that my first part of the question was answered in the comments below, i.e., that Taco (I guess) has reimplemented the paragraph builder from TeX (with additions from pdfTeX and Omega/Aleph) in Lua). Can somebody perhaps show how to use this lua script in a simple plain TeX scenario? In other words how is this applied so that

i.prevgraf and iM1.prevgraf < i.prevgraf then -- Both +1 and -1 looseness would work LastLineColor = color_pm1 elseif iP1s.prevgraf > i.prevgraf and iM1.prevgraf < i.prevgraf then -- Both +1 and -1 looseness would work, but +1 only with emergency stretch LastLineColor = color_pm1s elseif iP1.prevgraf > i.prevgraf then -- Only +1 looseness would work LastLineColor = color_p1 1037

elseif iP1s.prevgraf > i.prevgraf then -- Only +1 looseness would work and only thanks to the emergency stretch LastLineColor = color_p1s elseif iM1.prevgraf < i.prevgraf then -- Only -1 looseness would work LastLineColor = color_m1 else LastLineColor = nil end return true end -- Callback to colorize the last line of the paragraph when ColorLastLine is true local post_linebreak_color_last_line = function (head, groupcode) if LastLineColor then color_last_line(head) end return true end

-- Register callbacks luatexbase.add_to_callback("pre_linebreak_filter", pre_linebreak_test_looseness, " luatexbase.add_to_callback("post_linebreak_filter", post_linebreak_color_last_line Usage is then as follows: \documentclass{article} \usepackage{lipsum} \usepackage{luatexbase} \directlua{dofile("widow-assist.lua")} \begin{document} \lipsum[1-5] \end{document}

Tags: paragraphs (Prev Q) (Next Q), page-breaking (Prev Q) (Next Q)

1038

Q: In LuaTeX, what is the “identity” linebreak_filter? (Or: how can we use ‘tex.linebreak‘ to match the default line-breaking algorithm?) Tags: paragraphs (Prev Q) Consider the following LaTeX document (to be compiled with lualatex): Skip code block

\documentclass{article} \usepackage{lipsum} \begin{document} \directlua{ function shouldbenoop(head, isDisplay) return tex.linebreak(head) end } % \directlua{luatexbase.add_to_callback('linebreak_filter', shouldbenoop, 'This sh \lipsum \end{document} Whether or not the add_to_callback line is commented out, the output appears to be the same, that is our overridden linebreak filter, which calls tex.linebreak, appears to do the same thing that TeX does by default. However, when we try the same with plain TeX (to be compiled with luatex): Skip code block

\input ltluatex % For luatexbase.add_to_callback \input plipsum \directlua{ function shouldbenoop(head, isDisplay) return tex.linebreak(head) end } % \directlua{luatexbase.add_to_callback('linebreak_filter', shouldbenoop, 'This sh \lipsum{1-20} 1039

\bye and use the linebreak filter (uncomment the commented line above), the result looks bad, between paragraphs:

The paragraphs appear to overlap almost, and we need to set a higher \parskip to get “proper” results (of course they’re not proper in the sense that they differ from the result without using the linebreak filter). The issue is not with loading ltluatex in plain, as the result is the same with this: Skip code block \input plipsum \directlua{ function shouldbenoop(head, isDisplay) return tex.linebreak(head) end } \directlua{callback.register('linebreak_filter', shouldbenoop)} \lipsum{1-20} \bye 1040

It also doesn’t have anything to do with plipsum, as it is reproducible by simply typing out paragraphs without loading the package. What is going on? And more importantly, what can we write as a linebreak_filter in plain TeX, that will perfectly reproduce the effect of the default line-breaking (that is, be identical to not having a linebreak_filter)? Tags: paragraphs (Prev Q) User: shreevatsar

Answer by david-carlisle You need to reset (at least) \prevdepth something like this, otherwise \prevdepth gets the ”start of list” value of -1000pt and the following paragraph is set with no space before it. Skip code block \directlua{ function shouldbenoop(head, isDisplay) h,t =tex.linebreak(head) tex.prevdepth= t.prevdepth return h end } \directlua{callback.register('linebreak_filter', shouldbenoop)} \hsize3cm \parindent0pt g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g \showthe\prevdepth g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g g

a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a

1041

a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a \bye

Tags: paragraphs (Prev Q)

Texlive 2016 Skip to questions, Wiki by user martin-schröder The 2016 release of texlive introduced a number of incompatible changes, especially in luatex. Use this tag to track questions with these problems; if your problem is not specific to changes in this release, use texlive instead.

Questions Q: LuaLaTeX, TeXLive 2016, standalone: undefined control sequence Tags: texlive-2016 (Prev Q) (Next Q) Since I installed TeXLive 2016 I cannot build documents with the standalone document class any more using LuaLaTeX (PDFLaTeX works fine). For example: \documentclass{standalone} \begin{document} hi \end{document}

1042

Gives me: ! Undefined control sequence. \[email protected] ->\newpage \global \pdfpagewidth =\wd \[email protected] \global \pdfpageh... l.4 \end{document} How to fix that? Tags: texlive-2016 (Prev Q) (Next Q) User: keelan

Answer by egreg The fix is easy: add \RequirePackage{luatex85} as the very first line, a temporary workaround until standalone is updated. It should do no harm even after the update. \RequirePackage{luatex85} \documentclass{standalone} \begin{document} hi \end{document}

Answer by yan-zhou The easiest way is to load luatex85 package. You probably will need to load it before documentclass, using RequirePackage The longer story is that luatex now no longer defines many primitives with pdf prefix. The luatex85 package defines aliases of primitives which have the same names as in pdftex and earlier versions of luatex.

Tags: texlive-2016 (Prev Q) (Next Q)

1043

Q: datetime package does not work with lualatex in TL 2016 Tags: texlive-2016 (Prev Q) (Next Q) I am getting error compiling using lualatex under TL 2016 installed today when I use package datetime. This MWE works ok under TL 2015. How to resolve this error? It looks like the API to the datetime package has changed. \documentclass[11pt]{scrbook}%ext \usepackage{luatex85} %needed else gets an error with lualatex in 2016 \usepackage[us,12hr]{datetime} \begin{document} \currenttime \end{document} error is Skip code block lualatex foo.tex This is LuaTeX, Version 0.95.0 (TeX Live 2016) restricted system commands enabled. (./foo.tex LaTeX2e Babel and hyphenation patterns for 1 language(s) loaded. (/usr/local/texlive/2016/texmf-dist/tex/latex/koma-script/scrbook.cls Document Class: scrbook 2016/05/10 v3.20 KOMA-Script document class (book) (/usr/local/texlive/2016/texmf-dist/tex/latex/koma-script/scrkbase.sty (/usr/local/texlive/2016/texmf-dist/tex/latex/koma-script/scrbase.sty (/usr/local/texlive/2016/texmf-dist/tex/latex/graphics/keyval.sty) (/usr/local/texlive/2016/texmf-dist/tex/latex/koma-script/scrlfile.sty Package scrlfile, 2016/05/10 v3.20 KOMA-Script package (loading files) Copyright (C) Markus Kohm ))) (/usr/local/texlive/2016/texmf-dist/tex/latex/koma-script/tocbasic.sty) (/usr/local/texlive/2016/texmf-dist/tex/latex/koma-script/scrsize11pt.clo) (/usr/local/texlive/2016/texmf-dist/tex/latex/koma-script/typearea.sty Package typearea, 2016/05/10 v3.20 KOMA-Script package (type area) Copyright (C) Frank Neukam, 1992-1994 1044

Copyright (C) Markus Kohm, 1994)) (/usr/local/texlive/2016/texmf-dist/tex/generic/luatex85/luatex85.sty) (/usr/local/texlive/2016/texmf-dist/tex/latex/datetime/datetime.sty (/usr/local/texlive/2016/texmf-dist/tex/latex/etoolbox/etoolbox.sty) (/usr/local/texlive/2016/texmf-dist/tex/latex/fmtcount/fmtcount.sty (/usr/local/texlive/2016/texmf-dist/tex/latex/base/ifthen.sty) (/usr/local/texlive/2016/texmf-dist/tex/latex/xkeyval/xkeyval.sty (/usr/local/texlive/2016/texmf-dist/tex/generic/xkeyval/xkeyval.tex (/usr/local/texlive/2016/texmf-dist/tex/generic/xkeyval/xkvutils.tex))) (/usr/local/texlive/2016/texmf-dist/tex/latex/fmtcount/fcprefix.sty (/usr/local/texlive/2016/texmf-dist/tex/latex/fmtcount/fcnumparser.sty)) (/usr/local/texlive/2016/texmf-dist/tex/generic/ifxetex/ifxetex.sty) (/usr/local/texlive/2016/texmf-dist/tex/latex/amsmath/amsgen.sty) (/usr/local/texlive/2016/texmf-dist/tex/latex/fmtcount/fc-english.def)) (/usr/local/texlive/2016/texmf-dist/tex/latex/datetime/datetime-defaults.sty) ! Use of \@[email protected] doesn't match its definition. \pdfcreationdate ->\pdffeedback creationdate l.233 } ? Compiles ok with pdflatex in TL 2016 and compiles OK with lualatex in 2015: \documentclass[11pt]{scrbook}%ext \usepackage[us,12hr]{datetime} \begin{document} \currenttime \end{document} No error: Skip code block lualatex foo.tex This is LuaTeX, Version beta-0.80.0.1 (TeX Live 2015) (rev 5863) restricted \write18 enabled. (./foo.tex 1045

LaTeX2e patch level 2 Babel and hyphenation patterns for 79 languages loaded. (/usr/local/texlive/2015/texmf-dist/tex/latex/koma-script/scrbook.cls Document Class: scrbook 2015/10/03 v3.19a KOMA-Script document class (book) (/usr/local/texlive/2015/texmf-dist/tex/latex/koma-script/scrkbase.sty (/usr/local/texlive/2015/texmf-dist/tex/latex/koma-script/scrbase.sty (/usr/local/texlive/2015/texmf-dist/tex/latex/graphics/keyval.sty) (/usr/local/texlive/2015/texmf-dist/tex/latex/koma-script/scrlfile.sty Package scrlfile, 2015/10/03 v3.19a KOMA-Script package (loading files) Copyright (C) Markus Kohm ))) (/usr/local/texlive/2015/texmf-dist/tex/latex/koma-script/tocbasic.sty) (/usr/local/texlive/2015/texmf-dist/tex/latex/koma-script/scrsize11pt.clo) (/usr/local/texlive/2015/texmf-dist/tex/latex/koma-script/typearea.sty Package typearea, 2015/10/03 v3.19a KOMA-Script package (type area) Copyright (C) Frank Neukam, 1992-1994 Copyright (C) Markus Kohm, 1994)) (/usr/local/texlive/2015/texmf-dist/tex/latex/datetime/datetime.sty (/usr/local/texlive/2015/texmf-dist/tex/latex/etoolbox/etoolbox.sty) (/usr/local/texlive/2015/texmf-dist/tex/latex/fmtcount/fmtcount.sty (/usr/local/texlive/2015/texmf-dist/tex/latex/base/ifthen.sty) (/usr/local/texlive/2015/texmf-dist/tex/latex/xkeyval/xkeyval.sty (/usr/local/texlive/2015/texmf-dist/tex/generic/xkeyval/xkeyval.tex (/usr/local/texlive/2015/texmf-dist/tex/generic/xkeyval/xkvutils.tex))) (/usr/local/texlive/2015/texmf-dist/tex/latex/fmtcount/fcprefix.sty (/usr/local/texlive/2015/texmf-dist/tex/latex/fmtcount/fcnumparser.sty)) (/usr/local/texlive/2015/texmf-dist/tex/generic/ifxetex/ifxetex.sty) (/usr/local/texlive/2015/texmf-dist/tex/latex/amsmath/amsgen.sty) (/usr/local/texlive/2015/texmf-dist/tex/latex/fmtcount/fc-english.def)) (/usr/local/texlive/2015/texmf-dist/tex/latex/datetime/datetime-defaults.sty)) No file foo.aux. [1{/usr/local/texlive/2015/texmf-var/fonts/map/pdftex/updmap/pdftex.map}] (./foo.aux)) 275 words of node memory still in use: 2 hlist, 1 vlist, 1 rule, 2 glue, 43 glue_spec, 1 write nodes avail lists: 1:3,2:26,3:2,4:25,5:3,6:32,7:2,9:12,10:3 which latex /usr/local/texlive/2016/bin/x86_64-linux/latex >which make4ht /usr/local/texlive/2016/texmf-dist/scripts/make4ht/make4ht The first file I tried to compile gives error. I’d like to ask what does a user need to change or add to make tex4ht work under TL 2016. I use lua as option in all my builds using make4ht. Here is a MWE \documentclass[11pt]{article}% \usepackage[utf8]{inputenc} \begin{document} test \end{document} Error is Skip code block make4ht --lua foo.tex Output dir: Compiler: dvilualatex Latex options: -jobname=foo tex4ht.sty : xhtml, tex4ht build_file foo.mk4 Cannot open config file foo.mk4 setting param correct_exit setting param correct_exit setting param correct_exit 1048

setting param ext Adding: ext dvi LaTeX call: dvilualatex -jobname=foo '\makeatletter\def\HCode{\futurelet\HCode\H This is LuaTeX, Version 0.95.0 (TeX Live 2016) restricted system commands enabled. LaTeX2e Babel and hyphenation patterns for 1 language(s) loaded. (./foo.tex (/usr/local/texlive/2016/texmf-dist/tex/latex/base/article.cls Document Class: article 2014/09/29 v1.4h Standard LaTeX document class (/usr/local/texlive/2016/texmf-dist/tex/latex/base/size11.clo)) (/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/tex4ht.sty) (/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/usepackage.4ht) (/usr/local/texlive/2016/texmf-dist/tex/latex/base/inputenc.sty Package inputenc Warning: inputenc package ignored with utf8 based engines. ) (/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/tex4ht.4ht :::::::::::::::::::::::::::::::::::::::::: TeX4ht info is available in the log file :::::::::::::::::::::::::::::::::::::::::: ) (/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/tex4ht.sty --- needs --- tex4ht foo --(./foo.tmp) (./foo.xref) (/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/html4.4ht) (/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/html4-math.4ht) (/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/html4.4ht) (/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/html4-math.4ht) (/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/latex.4ht (/usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/html4.4ht ! String contains an invalid utf-8 sequence. l.1267 \Configure{tableofcontents} ? It works if remove --lua option. But I need to use this option and it works in TL 2015. The above error also shows up if I remove \usepackage[utf8]{inputenc} File compiles OK with lualatex 2016 1049

Skip code block lualatex foo.tex This is LuaTeX, Version 0.95.0 (TeX Live 2016) restricted system commands enabled. (./foo.tex LaTeX2e Babel and hyphenation patterns for 1 language(s) loaded. (/usr/local/texlive/2016/texmf-dist/tex/latex/base/article.cls Document Class: article 2014/09/29 v1.4h Standard LaTeX document class (/usr/local/texlive/2016/texmf-dist/tex/latex/base/size11.clo)) (./foo.aux) [1{/usr/local/texlive/2016/texmf-var/fonts/map/pdftex/updmap/pdftex.map}] (./foo.aux)) 346 words of node memory still in use: 2 hlist, 1 vlist, 1 rule, 7 glue, 39 glue_spec, 1 write nodes avail lists: 1:1,2:12,3:2,4:1,5:10,6:6,7:22,8:1,9:6

Output written on foo.pdf (1 page, 10400 bytes). Transcript written on foo.log. File also compiled OK with make4ht --lua under TL 2015: Skip code block

make4ht --lua foo.tex Output dir: Compiler: dvilualatex Latex options: -jobname=foo tex4ht.sty : xhtml, tex4ht build_file foo.mk4 Cannot open config file foo.mk4 setting param correct_exit setting param correct_exit setting param correct_exit setting param ext Adding: ext dvi LaTeX call: dvilualatex -jobname=foo '\makeatletter\def\HCode{\futurelet\HCode\H This is LuaTeX, Version beta-0.80.0.1 (TeX Live 2015) (rev 5863) restricted \write18 enabled. 1050

LaTeX2e patch level 2 ...... parse_lg process file: foo.css outdir: parse_lg process file: foo.tmp tmp file Tags: texlive-2016 (Prev Q) (Next Q), tex4ht (Next Q) User: nasser

Answer by egreg The file /usr/local/texlive/2016/texmf-dist/tex/generic/tex4ht/html4.4ht contains a spurious character in line 1267 1265 \let\sv:etoc\e:tableofcontents 1266 % 1267 \Configure{tableofcontents} 1268 {\IgnorePar\EndP\HCode{}\IgnorePar} The output was obtained with LESSCHARSET=ascii less -N $(kpsewhich html4.4ht) Make a local copy, edit the file placing the cursor at the backslash in \Configure and remove the preceding character. If the edited copy is in the working directory, compilation succeeds.

Tags: texlive-2016 (Prev Q) (Next Q), tex4ht (Next Q)

Q: lualatex texlive 2016 tcolorbox Tags: texlive-2016 (Prev Q) (Next Q), tcolorbox (Prev Q) (Next Q) If you compile with tl2016 lualatex this MWE

1051

Skip code block \documentclass[10pt, xcolor=svgnames, x11names,

t]{beamer}

\usepackage{etoolbox} \usepackage{ifluatex} \ifluatex \usepackage[no-math]{fontspec} \usepackage[EU2]{fontenc} \usepackage{lualatex-math} \else \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc} \fi \usepackage{mathtools} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{bm} \ifluatex \setsansfont[Ligatures=TeX, ItalicFont={MyriadPro-SemiCnIt.otf}, BoldFont={MyriadPro-BoldSemiCn.otf}, BoldItalicFont={MyriadPro-BoldSemiCnIt.otf}, SmallCapsFont={Delicious-SmallCaps.otf} ]{MyriadPro-SemiCn.otf} \else \usefonttheme{professionalfonts} \usepackage[condensed, scale]{tgheros} \fi \normalfont \usepackage[listings,theorems,skins, raster, breakable]{tcolorbox} \ifluatex \newtcblisting{mydocument}{% 1052

left skip=-4.2pt,width=1.01\linewidth, sharp corners,% beforeafter skip=0.5\baselineskip,% leftlower=0pt,rightlower=0pt,% lower separated=false,middle=0pt,% colframe=blue, enhanced, % interior style={top color=yellow!5!white,bottom color=yellow!5!white},% righthand width=4cm,halign=left,% pdf comment,% listing side comment,% compilable listing,% run lualatex} \else \newtcblisting{mydocument}{% left skip=-4.2pt,width=1.01\linewidth, sharp corners,% beforeafter skip=0.5\baselineskip,% leftlower=0pt,rightlower=0pt,% lower separated=false,middle=0pt,% colframe=blue, enhanced, % interior style={top color=yellow!5!white,bottom color=yellow!5!white},% righthand width=4cm,halign=left,% pdf comment,% listing side comment,% compilable listing,% run pdflatex} \fi

\begin{document} \begin{frame}[fragile]{TCB} \begin{mydocument} \documentclass[border=10pt]{standalone} \begin{document} Hello% world. Hello world. \end{document} 1053

\end{mydocument} \end{frame} \end{document} you have this error: Package tcolorbox Error: PDF file `mwebeamersans-listin g-1.pdf' not found. The file name is mewbeamersans.tex. With pdflatex the compilation is ok. With TL2015 and lualatex also the compilation is ok. Any help? Tags: texlive-2016 (Prev Q) (Next Q), tcolorbox (Prev Q) (Next Q) User: jpayansomet

Answer by egreg It’s better to minimize the example. The error appears also with Skip code block \documentclass[10pt, xcolor=svgnames, x11names,

t]{beamer}

\usepackage{fontspec} \usepackage[listings,theorems,skins, raster, breakable]{tcolorbox} \newtcblisting{mydocument}{% left skip=-4.2pt,width=1.01\linewidth, sharp corners,% beforeafter skip=0.5\baselineskip,% leftlower=0pt,rightlower=0pt,% lower separated=false,middle=0pt,% colframe=blue, enhanced, % interior style={top color=yellow!5!white,bottom color=yellow!5!white},% righthand width=4cm,halign=left,% pdf comment,% listing side comment,% compilable listing,% 1054

run lualatex} \begin{document} \begin{frame}[fragile]{TCB} \begin{mydocument} \documentclass[border=10pt]{standalone} \begin{document} Hello% world. Hello world. \end{document} \end{mydocument} \end{frame} \end{document} if compiled with lualatex -shell-escape. You need to add \usepackage{shellesc}, but you also need some adjustment for standalone, because it has not been updated to take into consideration that \pdfpagewidth and \pdfpageheight have been renamed to \pagewidth and \pageheight. This can be solved by using a file named standalone.cfg in the same directory as your main file containing \ifdefined\pdfpagewidth \else \let\pdfpagewidth\pagewidth \let\pdfpageheight\pageheight \fi You can produce it automatically if you use filecontents: Skip code block \begin{filecontents}{standalone.cfg} \ifdefined\pdfpagewidth \else \let\pdfpagewidth\pagewidth \let\pdfpageheight\pageheight \fi 1055

\end{filecontents} \documentclass[10pt, xcolor=svgnames, x11names,

t]{beamer}

\usepackage{shellesc} \usepackage{fontspec} \usepackage[listings,theorems,skins, raster, breakable]{tcolorbox} \newtcblisting{mydocument}{% left skip=-4.2pt,width=1.01\linewidth, sharp corners,% beforeafter skip=0.5\baselineskip,% leftlower=0pt,rightlower=0pt,% lower separated=false,middle=0pt,% colframe=blue, enhanced, % interior style={top color=yellow!5!white,bottom color=yellow!5!white},% righthand width=4cm,halign=left,% pdf comment,% listing side comment,% compilable listing,% run lualatex} \begin{document} \begin{frame}[fragile]{TCB} \begin{mydocument} \documentclass[border=10pt]{standalone} \begin{document} Hello% world. Hello world. \end{document} \end{mydocument} \end{frame} \end{document}

1056

An alternative to writing standalone.cfg is to add \RequirePackage{luatex85} to the document you want to compile Skip code block \begin{mydocument} \RequirePackage{luatex85} \documentclass[border=10pt]{standalone} \begin{document} Hello% world. Hello world. \end{document} \end{mydocument} 1057

Tags: texlive-2016 (Prev Q) (Next Q), tcolorbox (Prev Q) (Next Q)

Q: Error using pdfpages and lualatex Tags: texlive-2016 (Prev Q) After upgrading to Tex Live 2016/Debian i get errors when using the package pdfpages and compiling with Lualatex. If i try to compile \documentclass[a4paper,portrait]{article} \usepackage{pdfpages} \usepackage{pgffor} \includepdf{document.pdf} i get the errors Skip code block ! Undefined control sequence. \[email protected] ->\pdfhorigin ! Missing number, treated as zero.

\relax ! Illegal unit of measure (pt inserted).

\relax ! Undefined control sequence. \[email protected] ->\pdfvorigin (these are not the complete error messages, just the parts i think are important) I get no errors compiling with pdflatex. The versions i’m using are

1058

Package: pdfpages 2016/04/19 v0.5f pdfTeX, Version 3.14159265-2.6-1.40.17 LuaTeX, Version 0.95.0 Is this some sort of bug, or has something changed in the way pdfpages should be used? Tags: texlive-2016 (Prev Q) User: joão-gândara

Answer by daleif LuaTeX has changed quite a lot this year. Among other things the LuaTeX developers removed a lot of known (pdf)primitives from pdfTeX. Thus several packages that make use of these primitives need to be updated. Alternatively you can add the luatex85 package, which will reintroduce thise ”missing” primitives.

Tags: texlive-2016 (Prev Q)

Beamer Skip to questions, Wiki by user stefan-kottwitz This tag deals with the beamer class, which is used for creating presentations and slides. For questions about presentations or slides in general, independent of the document class, use presentations. For more information about beamer, see the project page on github.

1059

Questions Q: pdfx, beamer and lua(la)tex: is it possible? Tags: beamer (Prev Q) MWE: Skip code block \documentclass{beamer} %\usepackage[x-1a]{pdfx} \begin{document} \section{Présentation} \begin{frame}{First Frame} Hello, world! \end{frame} \section{Techniques} \begin{frame}{First Frame} Hello, world! \end{frame} \section{Mise en œuvre} \begin{frame}{First Frame} Hello, world! \end{frame} \section{Démonstration} \begin{frame}{First Frame} Hello, world! \end{frame} \section{Conclusions} \begin{frame}{First Frame} Hello, world! \end{frame} \end{document} This example compiles successfully (albeit with the annoyances associated with using non-ASCII characters). However, when I enable pdfx, I am

1060

plagued by these errors: ! LaTeX Error: Option clash for package xcolor. See the LaTeX manual or LaTeX Companion for explanation. Type H for immediate help. ... l.730 \else or (in this case using a-1b): ! Package kvsetkeys Error: Undefined key ‘pdftex,pdfa,pdfversion=1.4’. See the kvsetkeys package documentation for explanation. Type H for immediate help. ... l.806 } % Is it possible to use pdfx with the beamer class? Tags: beamer (Prev Q) User: amyspark

Answer by egreg The error for xcolor can be cured by \documentclass[xcolor={cmyk,hyperref}]{beamer} The main error about the minor version is cured by \usepackage[pdf15,x-1a]{pdfx} More difficult is to fix the kvsetkeys error, which is due to bad programming in pdfx.sty. I copied the file and changed all occurrences of \hypersetup{\[email protected]} (where ... is variable text) with \expandafter\hypersetup\expandafter{\[email protected]} because \hypersetup doesn’t expand its argument. There are nine replacements to do. Since this is not wrapped in a macro, but is code executed during loading of the package, there’s no other way than fixing the package. 1061

File a bug report, the code is wrong to begin with. Disclaimer. Whether this makes a valid PDF/X file I don’t know.

Tags: beamer (Prev Q)

Programming Questions Q: LaTeX3 versus pure Lua Tags: programming (Prev Q) (Next Q), latex3 (Prev Q) (Next Q) Reading this site for the last nearly two years I’ve learned a lot about LaTeX3 (which I had previously understood to be a defunct pipe dream) and LuaTeX (of which I was previously totally unaware). As I have said before, TeX itself is a bad programming language, though a good typesetting engine, but even as a typesetting engine, it is hobbled by its limitations as a language. What I mean by both of these, in short, is that it does not provide an easy way to manipulate its own representations of data. Others have also had this problem, and sometimes it can be solved with LuaTeX, which opens up a lot of the internals to the programming environment. Now, as I understand it, LaTeX3 also provides a lot of programming tools within TeX, with the aim of making package creation and maintenance more robust. Joseph Wright has explained this in at least one place (and therefore probably many more). These are ”algorithmic” tools, while the direction of LuaTeX development appears to be ”data structure” tools. Of course, Lua is also a general-purpose programming language and as such provides perfectly good algorithmic tools as well. My question: Why use LaTeX3 programming over Lua, when LuaTex is available? 1062

I understand that LuaTeX is very much experimental now, but then, so is LaTeX3. I also understand that as a result, LuaTeX is not necessarily used by anyone ”ordinary”, but then, it is intended as the ultimate successor to pdfTeX, which is now the default engine in the major TeX distributions. For all the reasons that TeX is a terrible programming language, LaTeX3 will still suffer from irritating expansion issues, lack of arithmetic capabilities, poor (or at least poor man’s) variables, and so on. However, Knuth himself has written that he would have used a better language if one had been available. Now that ”we” are inserting Lua into the TeX executable it appears that this alternative has been identified (ironically, that link is about PyTeX, based on Python). Now that \directlua is feasible, I don’t see why it is not better in every way simply to make all ”function” macros (those that do not directly store text) hook into that one primitive and then do all their programming in Lua. Loops, variables, recursion, and so on can all be done in a comprehensible way. A lot of effort in the development of LaTeX3 appears to be in managing the programming language and its use. So, I ask again: Why use LaTeX3 to program at all? Why not turn its development into the development of a LaTeX-style document design library for LuaTeX, written in Lua? This suggests a related question to me: Is the separation of LuaTeX and LaTeX3 a result (or at least an artifact) of the non-communication among developers that Ahmed Musa described in his comment to this answer? What kind of cooperation is there between these two projects to reduce duplication of effort? (An even more fantastical notion is to implement every primitive, except \directlua itself, in terms of Lua and various internal typesetting parameters, thus completely divorcing the programming side of TeX from the typesetting side. Then TeX itself would be a ”macro package” on top of LuaTeX and one would not be bound to its strange design choices. An answer to why that should or should not be done might be too long for me to request, however.) I don’t personally think that this is too bloggy for this site, and I hope others agree. At least, given the confluence of expertise here, it seems to be the best 1063

place to ask the question.

I have accepted Frank Mittelbach’s answer, though all the answers are extremely informative, because I think it hits all the main points most directly. One thing that neither it nor Joseph Wright’s answer quite manages to come out and say directly is that ConTeXt does do the Lua-programming thing at least to some extent, and it does not solve all algorithmic problems because LuaTeX does not actually rewrite the underpinnings of TeX so much as stitch in a Lua layer that can interact with them. I guess the one-line answer to my question is that my expectations of LuaTeX are much more grand than its reality, much like my ”fantastical” idea. Tags: programming (Prev Q) (Next Q), latex3 (Prev Q) (Next Q) User: ryan-reich

Answer by frank-mittelbach (I guess I could be called a member of one of the teams ;-) this is my view) I thought of staying out of this debate, but perhaps some words of clarification or, let’s say, some thoughts are in order after all. LaTeX3 versus pure Lua First of all this is the wrong question imho: LaTeX3 has different goals to LuaTeX and those goals may well be still a defunct pipe dream, but if so they are unlikely to be resolved by pure Lua either. So if one wants to develop an argument along those lines then it should be more like ”Why does LaTeX3 use an underlying programming language based on eTeX and not on LuaTeX where a lot of functionality would be available in a ”simpler” way?” But LaTeX3 is really about three to four different levels • • • •

underlying engine programming level typesetting element layer designer interface foundation layer 1064

• document representation layer See for example my talk at TUG 2011: http://www.latex-project.org/ papers/ Here is a sketch of the architecture structure:

The chosen underlying engine (at the moment is any TeX engine with eTeX extension). The programming level is what we call ”expl3” and that is what I guess you are referring to if you say ”LaTeX3” (and I sometimes do that too). However, it is only the bottom box in the above diagram. The more interesting parts are those that are above the programming level (and largely a pipe dream but moving nicely along now that the foundation on the programming level is stable). And for this part there is no comparison against Lua. Why use LaTeX3 programming over Lua, when LuaTeX is avail1065

able? To build the upper layers it is extremely important to have a stable underlying base. As @egreg mentioned in chat: compare the package situation in 2.09 to the package situation in 2e. The moment there were standard protocols to build and interface packages the productivity increased a lot. However, the underlying programming level in 2e was and is still a mess which made a lot of things very complicated and often impossible to do in a reliable manner. Thus the need for a better underlying programming layer. However, that programming layer is build on eTeX not because eTeX is the superior engine (it is compared to TeX but not with respect to other extensions, be it Lua or some other engine) but because it is a stable base available everywhere. So eTeX + expl3 is a programming layer that the LaTeX3 team can rely on of not being further developed and changed (other than by us). It is also a base that is immediately available to everybody in the TeX world with the same level of functionality as all engines in use are implementing eTeX extensions. Any larger level of modifications/improvements in the underlying engine is a hindrance to build the upper layers. True, some things may not work and some things may be more complicated to solve but the tasks we are looking at (well I am) the majority are very much independent of that layer anyway. To make a few examples: • good algorithms for automatically doing complex page layout aren’t there (as algorithms) so Lua will not help you here unless somebody comes up with such algorithms first. • something like ”coffins”, is thinking about approaching ”design” and the importance here is how to think about it now how to implement it (that comes second) -- see Is there no easier way to float objects and set margins? or LaTeX3 and pauper’s coffins for examples Having said that, the moment LuaTeX would be stable similar to eTeX (or a subset of LuaTeX at least) there might well good reasons for replacing the underlying engine and the program layer implementation. But it is not the focus (for now).

1066

Why use LaTeX3 to program at all? Why not turn its development into the development of a LaTeX-style document design library for LuaTeX, written in Lua? Could happen. But only if that ”LuaTeX” would no longer be a moving target (because LaTeX3 on top would be moving target enough). Side remark: @PatrickGundlach in his answer speculated that this answer that the LaTeX3 goal is backwards compatibility. Wrong. The same people that are coming down on you very strong about compatibility for LaTeX2e have a different mindset here. We do not believe that the interesting open questions that couldn’t get resolved for 2e could be resolved in any form or shape with LaTeX3 in a document-compatible manner. Input compatible: probably. But output compatibility for old documents, no chance if you want to get anything right. But in any case, this is not an argument for or against implementing the ideas we are working on one day with a LuaTeX engine. Is the separation of LuaTeX and LaTeX3 a result (or at least an artifact) of the non-communication among developers that Ahmed Musa described in his comment to this answer? What kind of cooperation is there between these two projects to reduce duplication of effort? As I tried to explain, there is not much overlap in the first place. There is much more overlap in conceptual ideas on the level ConTeXt viz. LaTeX. An even more fantastical notion is to implement every primitive, except \directlua itself, in terms of Lua and various internal typesetting parameters, thus completely divorcing the programming side of TeX from the typesetting side. That brings us to a completely different level of discussion, namely is based on LuaTeX, or anything else for that matter, a completely different approach to a typesetting engine possible? That is a very interesting thought, but as @Patrick explained it isn’t done with leaving TeX to do the typesetting and do everything else in a different language. So far such concepts have failed whether it was NTS or anything else because fundamentally (in my believe) we haven’t yet grasped how to come up with a successful and different model for the TeX macro approach (as ugly as it might look in places). 1067

Answer by joseph-wright Both Patrick and Frank have provided good answers: I’d like to add a few complementary points which seem too long for comments. One aspect of expl3 that is important is that it can be used now to program LaTeX2e packages (the ’l3in2e’ approach). That is seen for example in my own siunitx package, which I would not want to make LuaTeX-only. A particularly important aspect to this is xparse, which is proving to be popular with a reasonable number of users who probably don’t care about the programming internals. This use of LaTeX3 code is dependent on being usable with a good range of the currently-available engines. A second aspect is that LuaTeX does not mean you need no TeX programming at all. TeX is still there doing the typesetting, but also things like argument grabbing. (On the later, I asked the ConTeXt people about this once as I wondered about the old verbatim-in-arguments issue.) So improved TeX programming is still a good idea, even if you decided to go LuaTeX-only. Now, the nature of the structures you need would doubtless be different in that case, but again you can’t simply ignore it. Finally, there are practical considerations. A lot of the work on expl3 was done well before LuaTeX began, or certainly before it started reaching a more stable state. So to move from expl3 to Lua now would not really cut down on the work we need to do today, which as Frank says is mainly about higherlevel issues. A lot of what needs to be done seems to me to be relatively insensitive to the choice of language: it seems unlikely that a switch to Lua would suddenly accelerate development.

Answer by topskip (I am not a member of either team, this is my view.) LaTeX3 is not only about providing a better output routine, but also about providing programming tools such as the famous quicksort algorithm (see l3prg.sty). This is obviously nicer to write in Lua (for most of us). Or consider string manipulation / regular expressions. This could be handled in Lua as well. But strictly speaking, one doesn’t need Lua for that. 1068

Why use LaTeX3 to program at all? Why not turn its development into the development of a LaTeX-style document design library for LuaTeX, written in Lua? As I understand LaTeX3, one of its major goals is keeping backwards compatibility. While other documentation approaches are surely much appreciated in todays world (XML typesetting with CSS formatting for example), they would break existing documents. This is not what the LaTeX3 team wants. What kind of cooperation is there between these two projects to reduce duplication of effort? I can’t see much communication between the two projects. LaTeX3 is aimed at ”working with all engines that have the eTeX extensions”. This implies that no engine specific code must be used (that is: functionality that behaves differently under different engines). Therefore there is no obvious need for LuaTeX specific code. An even more fantastical notion is to implement every primitive, except \directlua itself, in terms of Lua and various internal typesetting parameters, thus completely divorcing the programming side of TeX from the typesetting side. Lua does not do any macro expansion / replacement, you need TeX for that. It is not possible to delegate all work to Lua, you will need the TeX part of LuaTeX. On the other hand, both LaTeX and Lua offer control structures such as loops or if/then/else clauses (LaTeX3 even more). Therefore you don’t need Lua at all. If you mix control structures from Lua and TeX, the programming can get ugly, because you need to switch back and forth between TeX and Lua. Currently this is only possible with coroutines but may be easier in the future. LuaTeX’s great power in LaTeX lies in the manipulation of the (pre) typeset material.

Tags: programming (Prev Q) (Next Q), latex3 (Prev Q) (Next Q)

1069

Q: How to access the last line of a paragraph with LuaTeX Tags: programming (Prev Q) (Next Q) Consider the following code, using traditional TeX programming that through a series of boxing and unboxing, grabs the last line of a paragraph and centers it. Skip code block \documentclass{article} \usepackage{lipsum} \begin{document} \def\centerlastline#1{% \bgroup \setbox0=\vbox{\bfseries\noindent #1}% \setbox1=\vbox{% \unvbox0 \setbox2=\lastbox \hbox to \linewidth{\hfill\unhbox2 \hfill}% }% \unvbox1 \egroup }% \centerlastline{\lipsum[3]} \end{document} How can achieve the same using LuaTeX’s access to the paragraph builder and its nodes? Tags: programming (Prev Q) (Next Q) User: yiannis-lazarides

Answer by michal.h21 After too many hours of failed attempts I got a working solution. The problem was in setting correct values to glue nodes. Documentation on this is unfortunately lacking, so I spent too much time hacking node dumps, but this lead to nowhere. 1070

Skip code block \documentclass{article} \usepackage{lipsum} \usepackage{luatexbase} % we will use node attributes to start/stop processing of paragraphs. % This is the most flexible way to support multiple paragraphs at once \newluatexattribute\centerattr \directlua{% luatexbase.add_to_callback("post_linebreak_filter", function(head) local first_glyph = function(h) for i in node.traverse_id(37,h) do return i end end local get_last = function(head, id) local x = node.count(id, head) for n in node.traverse_id(id,head) do x = x - 1 if x == 0 then return n end end return false end % get last line local n = get_last(head,0) local attr_num = luatexbase.attributes.centerattr local attr_val = node.has_attribute(n, attr_num) or 0 if attr_val < 1 then return head end % make hfill glue local make_hfill = function() local hfill = node.new("glue") hfill.spec = node.new("glue_spec") hfill.spec.stretch = 2^15 % set stretch_order to glue_order value of parent hlist hfill.spec.stretch_order = n.glue_order %3 return hfill end

1071

local hfill = make_hfill() local hfill2 = make_hfill() % add first hfill at the beginning hfill.next = n.head local last_glyph = get_last(hfill, 10) hfill2.next = last_glyph.next % and second hfill at the end last_glyph.next= hfill2 n.head = hfill return head end, "center last line") } \begin{document} \def\luacenterlastline#1{% \bgroup \centerattr=1 \bfseries\noindent #1% \egroup } \luacenterlastline{\lipsum[3]} \lipsum[3] \noindent hello world \centerattr=1 \noindent hello world \end{document} I decided to use different approach than was used in Yannis’s example with box processing. Node processing callbacks are used, as it enables much more flexibility. We can have process multiple paragraphs at once, or even whole document. To direct processing, node attributes are used. This is new concept in LuaTeX, we can declare the attribute and assign a value to it and all following nodes will have attribute set to this value. Using luatexbase package, we can declare new attribute and assign a value with

1072

\newluatexattribute\centerattr \centerattr=1 on the Lua side, we can get attribute number and value with: local attr_num = luatexbase.attributes.centerattr local attr_val = node.has_attribute(n, attr_num) or 0 attributes are numbers, so we first have to get attribute number from name used on LaTeX side, and then get value of the attribute with this number of node n. if

attr_val < 1 then return head end

with this condition we return node list unchanged if attribute is unset or when we set it to 0 manually. Now we must decide which node callback we shall use. for processing paragraphs after linebreak, post_linebreak_filter is used. Structure of node list we can access in this callback is following: hlist glue hlist ... hlist is a horizontal box, with child nodes accessible in head field. glue here is from \baselineskip. It is quite easy to get the last line using this function: local get_last = function(head, id) local x = node.count(id, head) for n in node.traverse_id(id,head) do x = x - 1 if x == 0 then return n end end return false end head is node list to be processed and id is node type to be processed. So we can get last hlist with local n = get_last(head,0) 1073

Now the hard thing, which I don’t still ready understand and which I found after lot of experimenting. hfill type of glue: local make_hfill = function() local hfill = node.new("glue") hfill.spec = node.new("glue_spec") hfill.spec.stretch = 2^15 % set stretch_order to glue_order value of parent hlist hfill.spec.stretch_order = n.glue_order %3 return hfill end With this function, two glue nodes are created, one is added at the beginning of the node list, second at the end, so the contents will be centered. Now I will explain problems that I had before I found this solution: when I inspected nodes inserted with \hfill command, they had these values of spec: stretch = 2^16 stretch_order = 3 when I added glue nodes with these values to the node list, nothing happened. later I found that value of stretch_order must be the same as value of glue_order of parent hlist. hlist which contained explicit \hfill had value of glue_order equal to 3, but normal hlists had glue_order set to 2, so no shrinking was applied. I don’t really know why, some experts on TeX internals will hopefully explain that. So I changed value of stretch_order to be the same as glue_order. But now the lines were flush right, ignoring second hfill node. Then I played with stretch value and found that value of 2^15 works. I don’t know why doesn’t work 2^16, when nodes inserted by \hfill have this value. After realizing correct values for hfill glue, rest of the work is quite easy, just setting next pointers between nodes.

1074

Old answer I will post partial solution, because I am stuck with some problem and maybe someone will know a solution. Skip code block \documentclass{article} \usepackage{lipsum} \begin{document} \def\luacenterlastline#1{% \bgroup \setbox0=\vbox{\bfseries\noindent #1}% \directlua{% local char =unicode.utf8.char 1075

% get contents of box 0 local head = tex.box[0].head % get last hlist -- this means line local x = node.count(0,head) for n in node.traverse_id(0, head) do x = x - 1 % if x is 0 then we are in the last line if x == 0 then % make hfill node local hfill = node.new("glue") hfill.spec = node.new("glue_spec") hfill.spec.stretch = 2^16 hfill.spec.stretch_order = 3 % make testing node, because node inserting doesn't work local pok = node.new(37) pok.char = 64 pok.next = n.head % print all glyphs on a line % note the @ at the beginning. our test node is printed for c in node.traverse_id(37,pok) do print(char(c.char)) end n.head = pok % this doesn't work neither %n.head = node.insert_before(n.head,n.head,pok) end end tex.box[0].head = head } \unvbox0 \egroup } \luacenterlastline{\lipsum[3]} \end{document} Contents of boxes is accessible with tex.box function. Node list is in head field. In this case, there are several nodes with id 0, which are hlist, nodes broken into lines. We cound these nodes and loop over them, processing is 1076

activated only in the last hlist. New node of type glue is created, with stretch and stretch_order fields set to maximal stretchability. Then I tried to insert this node at the beginning of the current hlist and this is where I am stuck, because it doesn’t show in the document. I am sure that this is some stupid problem on my side, but I was unable to solve it. For test, I added another node of glyph type, which should add @ char into the hlist and it doesn’t work either. Strangely, if I print contents of the hlist, @ character is printed on the terminal, so this glyph is part of new hlist, but it doesn’t find its way to the node lists used in the final document. I am sure that this is just some stupid mistake, but I should go sleep now, so maybe I will figure that tommorow.

Tags: programming (Prev Q) (Next Q)

Q: Can luaLaTeX convert xlsx tables into LaTeX code? Tags: programming (Prev Q) (Next Q) Inspired by this question: Using external tables in TikZ, I would like to know whether it is technically possible to use a xlsx (Office Open XML) file directly with luaLaTeX, i.e. can luaLaTeX call some external unzip program and then parse the extracted XML file? Or is that pushing the envelope too hard? Tags: programming (Prev Q) (Next Q) User: count-zero

Answer by topskip This is of course possible, as ”LuaTeX is the new Mac Gyver”. You can use the built-in luazip to unzip the contents of the xlsx file and then use an Lua-XML parser (see https://github.com/pgundlach/LuaTeX/tree/xmlreader for an XML enabled LuaTeX).

1077

Tags: programming (Prev Q) (Next Q)

Q: How can one get a list of the available functions in Lua(La)TeX Tags: programming (Prev Q) Is there a list or method to determine a list of the lua functions available/installed? Sofar I could only find the lua source files. Maybe I should write something that search through all the installed lua files for lines starting with ”function”. Then I will have a list, but it would still not give me the rest of detail of the functions. Any better ideas or suggestions? Tags: programming (Prev Q) User: louis

Answer by topskip You know the LuaTeX functions short reference? That together with the Lua reference should cover all available functions if I am correct.

Answer by taco-hoekwater This is hard to answer, as you are asking the lua equivalent of ’what are the names of all defined macros?’. The answer is: it depends. The core luatex functions are documented in the reference manual, as Patrick wrote in his answer. Everything else is loaded from lua source files on your hard-disk, but only if you (possibly indirectly) asked for it, just as would be the case for macros/packages.

1078

If you are only interested in a list of defined lua functions in your current luatex source file, you can try this inside a lua code block: Skip code block function dump (prefix, a) for i,v in pairs (a) do if type(v) == "table" then dump(prefix .. '.' .. i,v) elseif type(v) == "function" then print (prefix .. '.' .. i .. '()') end end end dump('_G',_G) but there are two caveats: • you only get to know function names, not their calling conventions. This is about as useful as only knowing macro names (meaning: not very useful at all) • circular references to tables will confuse this bit of lua code, it needs to be made smarter to allow for that

Tags: programming (Prev Q)

LaTeX3 Skip to questions, Wiki by user joseph-wright latex3 is about the new material being developed by the LaTeX3 Project. LaTeX3 is currently a series of packages used with LaTeX2e, and so questions in this category will almost all be about using LaTeX3 concepts with

1079

LaTeX2e. This includes the expl3 programming language along with higherlevel concepts such as xparse and xtemplate. Please do not use this tag for general LaTeX questions.

Questions Q: Why do I need Lua or LaTeX3 in a plain old technical document? Tags: latex3 (Prev Q) (Next Q) I wrote and maintain a couple hundred page computer related technical spec in XeLaTeX. I use tables, figures, bitfields, algorithms and other typical trappings. I’m intrigued by LuaTeX and LaTeX3, but honestly, I don’t know what benefit these will bring to a document like mine. Am I going to do more with less? Replace inelegant documentation strategies? Does anyone have examples of LaTeX3 benefits to a plain-Jane technical document? I already know and respect Lua from past programming work. It’s the dayto-day applicability to documentation that I’m missing. Tags: latex3 (Prev Q) (Next Q) User: srking

Answer by joseph-wright Developments in Lua and LaTeX3 are separate, but there is some convergence in the sense that both address issues for LaTeX programmers. It’s also the case that the benefits you will see from these developments depend on the nature of your documents. LuaTeX adds to TeX functionality which is not available any other way, but also makes general programming a lot easier. The general programming stuff helps package authors. For example, Lua is used by fontspec when loaded in LuaLaTeX to find fonts system. Some of the new abilities show up in particular areas, where TeX ’runs out of steam’. One that stands out is in

1080

Arabic typesetting, which is very context-dependent and which TeX does not do so well at. LuaTeX-based approaches can address this type of issue. LaTeX3 developments are also focussed at the programming end the moment making it easier to maintain packages. For example, XeLaTeX users tend to use fontspec, and fontspec is written in the LaTeX3 programming system. In the longer term, the aim is to address a number of underlying issues with LaTeX in an eventual LaTeX3 format. This should wrap up a lot of package functionality kernel, and also allow us to address some long-standing awkward issues (for example, that adding vertical space can have odd effects due to the way TeX handles the main vertical list). A richer set of kernel tools should also cut down on multiple-package compatibilities. Now, it’s possible that this will have very little impact on your documents, other than perhaps giving you shorter preambles.

Tags: latex3 (Prev Q) (Next Q)

Q: Will LaTeX3 have proper support for hooks? Does LuaTeX? Tags: latex3 (Prev Q) Tex has powerful support for extensions triggered by events happen in generating output, by running one of six token lists appropriately: \everycr \everydisplay \everyhbox \everymath \everypar \everyvbox They’re used with effect in such places as Latex classes, but they are much less useful than they could be, because the \everyfoo={\t\o ks} assignment simply wipes the current value, making it rather tricky to use them by authors of packages and documents. Emacs’ Elisp has a widely understood technology for registering and deregistering code to run at events, namely hooks. The LaTeX3 Project’s expl3 library offers supports for managing token lists, and LuaTeX augments TeX’s event handling mechanism with a set of Lua callbacks. Are these the beginning of proper support for event-driven TeX code, as usable as hooks? Is this a priority for developers on these projects? 1081

Tags: latex3 (Prev Q) User: charles-stewart

Answer by topskip LuaTeX does not offer these hooks out of the box, but you can make them yourself. The LuaLaTeX people do this (thanks!). See http://github.com/ mpg/luatexbase (and there: luatexbase-mcb.dtx).

Answer by will-robertson Sure, it would be great if LaTeX3 provided hooks for this sort of thing— not using the primitives directly, but rather providing an interface to a reliable way to use these token registers. Unfortunately, ripping out the current LaTeX2e machinery for, say, giving a good way to access \everypar simply isn’t possible without breaking backwards compatibility with lots and lots of current packages. Experimental LaTeX3 packages such as galley are written to start thinking about these ideas, but we’re quite a way away from anything that can be used for general purposes.

Answer by joseph-wright Expanding on the LaTeX3 side of things, I guess this is a place where I’d expect to provide a different input syntax to LaTeX2e. As the question points out, the current implementation uses the token register syntax \everyfoo{tokens} which overwrites whatever was in \everyfoo unless you do \everyfoo\expandafter{\the\everyfoo tokens} which is not exactly obvious. So a better approach would be something like the current \AtBeginDocument, something like: \AtEveryFoo{tokens}

1082

where this is additive. The implementation of such an approach would be easy enough. Proof of concept A short piece of concept code that might be an approach for LaTeX3. The idea here is that the TeX primitive is only used by the kernel, with two separate hooks provided. First, settings that the kernel needs are applied, then ones from programmers and finally those from the user. In the demo I’ve only considered the \everymath concept. I’ve provided an interface for the user to both add to and clear the list, plus an alias to the LaTeX2e \everymath interface. (In a pure LaTeX3 approach I’d drop this TeX-like interface, or at least mark it depreciated.) Skip code block \documentclass{article} \usepackage{xparse} \ExplSyntaxOn \makeatletter \tl_new:N \l_every_math_programmers_tl \tl_new:N \l_every_math_users_tl \toks_set:Nn \tex_everymath:D { \[email protected] % LaTeX2e's requirement \tl_use:N \l_every_math_programmers_tl \tl_use:N \l_every_math_users_tl } \NewDocumentCommand \InsertForEvery { m +m } { \tl_put_right:cn { l_every_ #1 _users_tl } {#2} } \NewDocumentCommand \ClearForEvery { m } { \tl_clear:c { l_every_ #1 _users_tl } } \RenewDocumentCommand \everymath { +m } { \InsertForEvery { math } {#1} } \ExplSyntaxOff \begin{document} \InsertForEvery{math}{\mathrm{Look!\,}} \( y = mx + c \) \ClearForEvery{math} 1083

\( y = mx +

c \)

\end{document} I should add that a real implementation would need error-checking and so on.

Tags: latex3 (Prev Q)

Hyperref Skip to questions, Wiki by user stefan-kottwitz hyperref is a package capable of producing hypertext links in documents. If your question is about cross-referencing in general, choose cross-referencing. If it’s specifically about PDF features, consider to choose pdf. In addition to the capability of producing hypertext links hyperref can be used to add meta data to PDF files.

Questions Q: hyperref, lualatex and unicode bookmarks issue (garbled page numbers in AR for Linux) Tags: hyperref (Prev Q) (Next Q) I have text with some non-ascii characters in chapters, sections... which I’d like to see in bookmarks displayed correctly. I noticed that, • If I run xelatex, everything is fine, no need to set \hypersetup{unicode=true} to get this working 1084

• If I run lualatex, I have these issues: 1. If unicode=false, then bookmarks containing non-ascii characters have strange unreadable symbols instead of those chars, but everything else is fine 2. If unicode=true, then bookmarks are just fine, but page numbers in resulting PDF file are garbled in Adobe Reader 9 on Linux (and Okular shows some strange symbols in bookmark pane too) Is it a driver issue? Any suggestion how to overcome this problem? Here’s a MWE: Skip code block \documentclass{article} \usepackage{hyperref} %\hypersetup{unicode=true} \begin{document} \section{Test 1 čćžđš} Some text.\clearpage \section{Test 2 šđžćč} Some text. \end{document} A notice: I tried to post this question on comp.text.tex earlier, but something went wrong and it didn’t show up. Anyway, if the post shows up later, I’ll post the link here. Tags: hyperref (Prev Q) (Next Q) User: meho-r.

Answer by meho-r. I received an email from Heiko suggesting that I try auto pdfencoding which worked indeed. So, the solution is: 1085

\hypersetup{pdfencoding=auto} And corrected MWE from above: Skip code block \documentclass{article} \usepackage{hyperref} \hypersetup{% pdfencoding=auto, pdfauthor={Author Test ČĆŽĐŠ}, pdftitle={Title test, čćžđš} } \begin{document} \section{Test 1 čćžđš} Some text.\clearpage \section{Test 2 šđžćč} Some text. \end{document} Complete Heiko’s answer can be found on comp.text.tex.

Tags: hyperref (Prev Q) (Next Q)

Q: Possible LuaLaTeX Problem (compilation seems to hang) Tags: hyperref (Prev Q) I asked a question earlier, where I had problems with my font specification, since I am using LuaLaTeX with Caslon. I am on Win 7 with TeXLive 2013 (up to date). The file compiles just fine with XeLaTeX.

1086

Here is my preamble and the compiler seems to hang at this point of the output: Skip code block \documentclass[ a4paper, % DIVcalc, % BCOR12mm, 12pt]{scrartcl} \linespread{1.6} \usepackage{setspace} % \singlespacing % \onehalfspacing % \doublespacing %\setstretch{1.2} % for custom spacing %\usepackage[T1]{fontenc} %\usepackage[ansinew]{inputenc} %\usepackage[latin9]{inputenc} %\usepackage[english]{babel} %\synctex=-1 \usepackage{xcolor} \usepackage{pdfcolmk} \usepackage{textcomp} \usepackage{verbatim} \PassOptionsToPackage{normalem}{ulem} \usepackage[normalem]{ulem} \usepackage{units} %for nicefrac \usepackage{ftnxtra}

%%%XeTeX-font-modifications \usepackage[no-math]{fontspec} \usepackage{lipsum} \usepackage[rm]{titlesec} %\usepackage{titletoc} \usepackage[titles]{tocloft} \usepackage{polyglossia} 1087

\usepackage{csquotes} \setdefaultlanguage{english} %\defaultfontfeatures{Ligatures=TeX} %\setmainfont[Numbers=Proportional,Ligatures=TeX]{Adobe Caslon Pro} \setmainfont[ Extension = .otf, Ligatures = TeX, BoldFont = ACaslonPro-Bold, ItalicFont = ACaslonPro-Italic, BoldItalicFont = ACaslonPro-BoldItalic ]{ACaslonPro-Regular} %\usepackage{luaotfload}

%%%for luatex %\usepackage{uniinput-lualatex} %\usepackage{luatextra}

%%%special typesetting adjustment %\usepackage{microtype} %\usepackage[english]{selnolig}

%%% Equations \usepackage{amsmath} \usepackage{mathcomp} \usepackage{amssymb} \usepackage{breqn} \usepackage{upgreek} \usepackage{stmaryrd} % % % %

%%%XeTeX Mathfont XITS Math \usepackage[MnSymbol]{mathspec} \setmathsfont(Digits,Latin,Greek) [Numbers={Lining,Proportional}]{Latin Modern Math}

1088

%%% THE BIB \usepackage[backend=biber, citestyle=authoryear,bibstyle=philosophy-modern, natbib=true,isbn=false,url=false,maxcitenames=2,language=english,hyperref=true,sor \addbibresource{draft.bib} %%%geometry \usepackage[lmargin=2.5cm,rmargin=2cm,bottom=2.5cm,top=2.5cm,includeheadfoot] {geometry}

%%%Symbols \usepackage{eurosym}

%%% TABLES \usepackage{threeparttable} \usepackage{tabularx} \usepackage{fancyvrb} \usepackage{array} \usepackage{booktabs} \usepackage{multirow} \usepackage{multicol} \usepackage{longtable} \usepackage{supertabular} \usepackage{rotating} %zum drehen von Tabellen ins Querformat \usepackage{dcolumn} % ??? \usepackage{enumerate} %%% Grafiken \usepackage{graphicx} \usepackage{subfig} \usepackage{rotating} \usepackage{tikz} 1089

\usetikzlibrary{arrows,positioning} %%% version control \usepackage{mVersion} \increaseBuild %%%shaping %\usepackage{shapepar} %%% To-do-Notes % \usepackage[german,textsize=footnotesize]{todonotes} % \setlength{\marginparwidth}{4cm} % \reversemarginpar %vorübergehend, damit marginnotes Platz haben % \setlength{\hoffset}{3cm} % \setlength{\textwidth}{14cm} %def:stodo % \newcommand{\stodo}[2][] % {\todo[caption={#2}, size=\small, #1]{\renewcommand{\baselinestretch} %%% Schusterjungenkontrolle \widowpenalty=10000 \clubpenalty=10000 %%% Verzeichnisse

%%% Makros \newcommand{\HRule}{\rule{\linewidth}{0.5mm}}

%%% HYPERREF \usepackage[english,linktocpage=true]{hyperref} \hypersetup{ colorlinks = true, linkcolor = blue, anchorcolor = blue, citecolor = blue, 1090

{0.5}\s

filecolor = red, urlcolor = blue } Here is where the compiler hangs: Skip code block

(c:/texlive/2013/texmf-dist/tex/latex/biblatex-philosophy/english-philosophy.lbx ( ) (c:/texlive/2013/texmf-dist/tex/latex/base/ts1cmr.fd) (c:/texlive/2013/texmf-dist/tex/latex/tipa/t3cmr.fd) (c:/texlive/2013/texmf-dist/tex/context/base/supp-pdf.mkii [Loading MPS to PDF converter (version 2006.09.02).] ) (c:/texlive/2013/texmf-dist/tex/latex/oberdiek/epstopdf-base.sty (c:/texlive/2013/texmf-dist/tex/latex/oberdiek/grfext.sty) (c:/texlive/2013/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg)) (./draft.bbl) *geometry* driver: auto-detecting *geometry* detected driver: pdftex ABD: EveryShipout initializing macros (c:/texlive/2013/texmf-dist/tex/latex/hyperref/nameref.sty (c:/texlive/2013/texmf-dist/tex/generic/oberdiek/gettitlestring.sty)) (./draft.out) (./draft.out) If you have any idea, why the compiler hangs please tell me. Thanks in advance! Tags: hyperref (Prev Q) User: option_select

Answer by option_select This got solved due to @egreg and @cgnieder and this suggestion tug.org/pipermail/tex-live/2013-July/033914.html. If you experience similar problems, run luaotfload-tool --update from the command line/shell.

1091

Tags: hyperref (Prev Q)

Protrusion Questions Q: How does one retrieve \rpcode values in LuaTeX? Tags: protrusion (Prev Q) The \rpcode values from pdfTeX are properties of font characters, e.g., \rpcode\font 50 = 200 sets the right protrusion value for character 50 in the current font to 200. Reading chapter 7 of the luatex reference manual my understanding is that this value then shows up in the character table for this particular character as right_protrusion. However, this is either not the case or I do something wrong, here is a minimal example: Skip code block \pdfprotrudechars=2 \rpcode\font 50 = 200 \efcode\font 50 = 333 \directlua{ local function FMItable (name,t) print ("---- looking at table ", name, tostring(t)) for k, v in pairs(t) do print(" ", k,"=", tostring(v)) end print("----------------") end

1092

FMItable("char 50",font.fonts[font.current()].characters[50]) } \bye If run through luatex this generates Skip code block luatex rp-test.tex This is LuaTeX, Version beta-0.79.1 (TeX Live 2014/W32TeX) (rev 4971) restricted \write18 enabled. (./rp-test.tex---- looking at table char 50 table: 02FB5E10 height = 422343 used = false width = 327681 bot_accent = 0 italic = 0 expansion_factor = 333 depth = 0 top_accent = 0 ---------------) No pages of output. Transcript written on rp-test.log. You can see the changed \efcode so I’m getting at the right character table but no index for protrusion. Any idea what I’m doing wrong? Tags: protrusion (Prev Q) User: frank-mittelbach

Answer by david-carlisle This seems to be fixed in the current 0.80 release Skip code block This is LuaTeX, Version beta-0.80.0 (TeX Live 2015) (rev 5238) restricted \write18 enabled. 1093

(./gg384.tex---- looking at table depth = 0 used = false width = 327681 expansion_factor = right_protruding = height = 422343 ---------------) No pages of output.

char 50 table: 0x60106f270

333 200

showing right_protruding

=

200

is reported.

Tags: protrusion (Prev Q)

Page Breaking Questions Q: Can LuaTeX change the PAGE-breaking algorithm Tags: page-breaking (Prev Q) (Next Q) One of the often highlighted features in LuaTeX is the ability to replace the default TeX line-breaking algorithm by something else. I wonder if it is similarly possible to replace the page-breaking algorithm? This would be a great feature, since the page-breaking algorithm in TeX is often described as more ”greedy” than the line-breaking algorithm, and as not very good at optimizing globally. EDIT: If this turns out to be possible, can this be used to solve the following problem, highlighted by Frank Mittelbach? I assume no, since Frank does 1094

not state so explicitly.

[ Issue: TEX generates pages based on precompiled paragraph data]Issue: TEX generates pages based on precompiled paragraph data This issue describes the fundamental problem in TeX’s approach: the program builds optimized paragraph shapes without any knowledge about their final placement on a page. The result is a “galley” from which columns are cut to a specified vertical size. A consequence of this is that one can’t have the shape of a paragraph depend on its final position on the page when using TEX’s page builder algorithm. To some extent, it is possible to program around this limitation, e.g., by measuring the remaining space on a page and explicitly changing paragraph shapes after determining where the current textual material will finally appear. However, besides being complicated to implement, it requires accounting for all kinds of special situations that normally would be automatically managed by TEX, and providing “programmed” solutions for them. As a result, all attempts so far to provide such functionality had to impose strong limitations on the allowed input material, i.e., they worked only in restricted setups and even then, the results were often not satisfactory. Tags: page-breaking (Prev Q) (Next Q) User: gaussler

Answer by david-carlisle Yes, see the documentation of the buildpage_filter callback, and possibly also the pre_output_filter callback. Note however that unlike the linebreaking algorithm, there are very few parts of the page breaker that you are forced to use directly, which is why differ1095

ent strategies can be programmed even in classic tex without needing lua extensions, such as two column mode in standard latex, or multicol package.

Tags: page-breaking (Prev Q) (Next Q)

Q: pagebreak in ledpar (eledpar) Tags: page-breaking (Prev Q) I am sort of restating this question -- however only sort of. I will (1) describe a problem, (2) assume something about the functions of ledpar, and (3) ask a question. 1. Problem I am typesetting a bilingual edition of a text: edition on the left, translation on the right page. Since the translation is much longer than the original, the pagesynchronization is rarely correct (I assume that the unequal lengths of text on both pages is at least in part responsible; this assumption could be wrong, of course). Anyway, I would like to be able to insert a pagebreak manually an thereby to synchronize the contents manually. AFAIK such a manual pagebreak is not implemented in ledpar. There is this fine solution, but I want to state the problem from a slightly different angle. 2. Assumption I guess ledpar works like this: • looking at the text on both sides, • trying measure the contents on both sides, • deciding for a portion of text on the left page,

1096

• using some sort of command in order to let the left page break after that portion, • trying to measure the corresponding text on the right page, • trying to determine an equal portion on the right page and the correct spot for the break, • using some sort of command in order to let the right page break, • go to the next portion of text... etc. 3. Question What is this command that lets the page break? This command -- or something like it -- must exist, because ledpar uses it itself automatically all the time, right? So, can I just manually use this very same command that lets the page break myself wherever I want? If this command is some bigger function, then I think it should be possible to define a command I could execute in my text. Tags: page-breaking (Prev Q) User: clinteastwood

Answer by maïeul The version 1.5.0 of eledpar add tools to manage pagebreak on eledpar. There is two commands : \ledpb to make page break, and \lednopb to prevent page break, by adding new line. It needs to make two runs.

Tags: page-breaking (Prev Q)

Context Mkiv Skip to questions, 1097

Wiki by user topskip The tag context-mkiv is for the modern variant of context that uses luatex. You should use this tag if a Mark IV based answer would be helpful.

Questions Q: Escape a string printed from Lua using ConTeXt Tags: context-mkiv (Prev Q) (Next Q) This seems to have come up a couple times, but I cannot glean an answer to the generic question of how one might protect an arbitrary string in Lua to ensure its characters are printed. In other words, given some code in a .lua file: local i_can_be_anything = '&\\%*_' context(i_can_be_anything) This balks for any number of reasons, because the characters have special meaning in TeX when ConTeXt pushes them out to the TeX compiler. The most apparent option to me would be to convert the string in Lua so that it contains the proper escaping or substitutions that can be passed to TeX to achieve the desired outcome, which would be in this case along the lines of: \&\textbackslash{}\%\&\_ I believe the full list of replacements one would be looking for would be along the lines of (and this is from some Python I wrote): Skip code block tex_replacements = [ (u'{', ur'\{'), (u'}', ur'\}'), (u'[', ur'{[}'), (u']', ur'{]}'), 1098

(u'\\', ur'\textbackslash{}'), (u'$', ur'\$'), (u'%', ur'\%'), (u'&', ur'\&'), (u'#', ur'\#'), (u'_', ur'\_'), (u'~', ur'\textasciitilde{}'), (u'^', ur'\textasciicircum{}'), ] tex_mapping = {ord(char):rep for char, rep in tex_replacements} def escape(s): return unicode(s).translate(tex_mapping) Is there no function in Lua or LuaTeX to achieve this set of substitutions (or otherwise) so that an arbitrary string could be printed? A straightforward iteration over the characters with a substitution along the lines of the tex_replacements above could do the trick, but I would expect that someone had already written a solution to this problem.

EDIT It is worth noting that @phg posed a plausible solution of changing the catcodes to vrbcatcode (i.e. \verbatim, or context.sprint(catcodes.numbers.vrbcatcodes, i_can_be_anything)). This does perform the escaping desired, however it seems to have serious issues with line breaking that make it essentially unusable. Tags: context-mkiv (Prev Q) (Next Q) User: brian-m.-hunt

Answer by aditya This answer is based on an email from Hans Hagen. One way to achieve the desired output is using formatters. For example:

1099

\starttext \startluacode local text='&\%*_' context("%!tex!", text) \stopluacode \stoptext The %!tex! is plug to the formatters and tex is one of the pre-defined formatters. Other pre-defined formatters are lua and xml (which escape strings for Lua and XML, respectively). The above code is equivalent to context(string.formatters["%!tex!"](text)) which is equivalent to the rather low-level context(lpeg.match(lpeg.patterns.texescape,text)) The corresponding lpeg patterns for lua and xml formatters are lpeg.patterns.luaescape and lpeg.patterns.xmlescape. These are defined in util-str.lua as: patterns.xmlescape patterns.texescape patterns.luaescape patterns.luaquoted

= = = =

Cs((P("")/">" + P("&")/"&" + P('"')/" Cs((C(S("#$%\\{}"))/"\\%1" + P(1))^0) Cs(((1-S('"\n'))^1 + P('"')/'\\"' + P('\n')/'\\n"')^0) -- may Cs(Cc('"') * ((1-S('"\n'))^1 + P('"')/'\\"' + P('\n')/'\\n"')

The luaquoted pattern is not used in the core.

Tags: context-mkiv (Prev Q) (Next Q)

Q: How can I list fonts available to LuaTeX in ConTeXt (TeX Live 2013)? Tags: context-mkiv (Prev Q) I’ve looked at How do I get a list of all available fonts for luaotfload?, but the answers don’t work for me in TeX Live 2013, at least not without La1100

TeX. This is because there they rely on the file otfl-names.lua under \luatex-cache\generic\names; but in my installations of TeX Live 2013 (ConTeXt scheme), the only directory under \luatex-cache is context, and there is no otfl-names.lua that I can find. P.S. Following this comment, I also looked for luaotfload-names.lua, but can’t find that file either. Do I need to run a program to build it? I looked for mkluatexfontdb but no such command seems to exist. I tried the following ConTeXt mkiv (LuaTeX) document: Skip code block \starttext \startluacode myfonts=dofile(fonts.names.path.path) for i,v in ipairs(myfonts.mappings) do tex.print(-2, v.familyname) tex.print(', ') tex.print(-2, v.fontname) tex.print('\\par') end \stopluacode \stoptext But I get the error: ! LuaTeX error [string ”\directlua ”]:2: attempt to index field ’path’ (a nil value) Any suggestions would be appreciated. Tags: context-mkiv (Prev Q) User: larsh

Answer by philipp-gesang If all you need is a list of the registered fonts, you can run

1101

mtxrun --script fonts --list --all for Context, and luaotfload-tool --list=* for Lualatex/Luaotfload (see man 1 luaotfload-tool for details). If you did not yet build the font indices you will have to do so before running above commands, e.g. mtxrun --script fonts --reload and luaotfload-tool --update

Tags: context-mkiv (Prev Q)

Compiling Skip to questions, Wiki by user edd LaTeX is a compiled markup language, and as such there is a compilation process that needs to be followed to correctly produce output. This can be a long and complicated sequence of steps, with multiple passes being required to successfully build references and tables of contents amongst other things, as well as ensuring that externally generated files are up to date.

Questions Q: Hiring someone to help me with LaTeX for my PhD thesis Tags: compiling (Prev Q) (Next Q), arabic (Next Q) 1102

I do not know whether this is an appropriate question, but I was carrying it around for quite some weeks and now it just has to come out. I am working on my PhD thesis. My thesis will include a long English textual analysis in the mainmatter ((almost) no problem with that) and a long appendix providing the source texts on which the analysis is based. These source text will be given in the original language (Arabic) on the left page as a critical edition with two or three apparatus and my english translation on the right page. I have chosen ledmac/ledpar to do the job (because there is no alternative, is there?) and now I’ve been wrestling for weeks/months to get everything in order -- and by wrestling, I really mean it. Other than that, I already started to edit my texts using the commands that the packages provide and all the while I’ve been hoping that in the end all problems can be overcome one after another, so that in the end I have a nice typeset thesis and I can confidently claim that I’ve made the right choice in chosing (Lua-) LaTeX for writing my thesis. This my situation. Now, since I’ve encountering problems after problems (in between solving one or two while others appear), I’ve become skeptical whether LaTeX is the right choice for my project. Even more since I also have the feeling that I myself won’t be able to solve all the issues, because I am lacking the IT-expertise. I’ve done a lot of delving into the depths of LaTeX, but I am coming close to my limits there. I still belive in LaTeX, but what I intend to do seems to be some major job for LaTeX and I doubt that I am the one who can get LaTeX to do the job. So, the question I’ve been having in my mind is this (and I want to repeat that I am not sure whether it is an appropriate question): 1. Is there anybody out there who I could hire (yes: hire) to look through my tex-files and fix the problems I encounter while I can focus on writing my thesis (and of course fix what I can fix myself)? 2. How much would it be to hire someone like that? I am at the point where I have to decide whether to abandon LaTeX for my PhD and to take another application (e.g. CTE), or to stay with it. Once again: I like LaTeX, and I’d also like to stay with it, but I am not sure whether I should. And also, I don’t want to realize that using LaTeX was the wrong decision only two months before I hand in my thesis because then 1103

it is too late. Sorry for this question, but it had to come out...

Appendix: Random examples of problems • the line numbers in the apparatus are one to much (e.g., 7 instead of 6) • the arabic text has sometimes varying interlinespacing • the space between the paragraphs (created by ledpar) shouldn’t be there (see here) • the content is not correctly snychronized and the pagebreaks are thus wrong • the Arabic apparatus has problems with linebreaks • the page numbers in the table of contents need to be modified (see here) • ... Tags: compiling (Prev Q) (Next Q), arabic (Next Q) User: clinteastwood

Answer by topskip You can always contact your local TeX users group. They most likely know people that offer LaTeX help (free/commercial). For the other question, on how much it would be. That depends, of course, but since you’re asking for special knowledge, it won’t be cheap. I see you are located in Germany: we maintain a list of professional TeX consultants here: http://texfragen.de/latex_hilfe#kommerzielle_dienstleister

Answer by simurgh12 As far as I understand your question, you need someone who has expertise on both bidi typesetting in TeX and critical edition typesetting in TeX. You

1104

may contact these people/groups/mailing lists and see if they can help (or be hired): 1. Peter Wilson (the original author of ledmac, ledpar, and ledarab packages) 2. Dominik Wujastyk and John Lavagnino (the authors of edmac package) 3. Maïeul Rouquette (the current maintainer of ledmac package) 4. Klaus Lagally (the author of arabtex package) 5. Ahmad Yazdipour (the author of TeX-e-Parsi: a Persian TeX typesetting system) 6. FarsiTeX project group and in particular, Behdad Esfahbod 7. IvriTeX mailing list 8. François Charette (the original author of bidi and arabxetex packages) 9. Vafa Khalighi (current author/maintainer of bidi, xepersian, and arabxetex packages, previous maintainer of ledmac, ledpar, and ledarab packages). 10. Youssef Jabri (the author of arabi package)

Answer by anabel In http://www.djdekker.net/ledmac/ you can find lot of clues. It is more or less what you want, except for the Arabic. It saved my life day with my Ph.D. thesis.

Tags: compiling (Prev Q) (Next Q), arabic (Next Q)

Q: how to get lualatexmk to run in \nonstopmode Tags: compiling (Prev Q) (Next Q) I use the engine lualatexmk to create my documents. This runs the entire pdf-generating-process several times until a stage is reached where an additional run of this process wouldn’t change the result anymore. This, at least, is more or less how I believe lualatexmk works.

1105

The content of lualatex.engine is:

#!/bin/bash export TSBIN="$HOME/Library/TeXShop/bin/tslatexmk" export LTMKBIN="$HOME/Library/TeXShop/bin/tslatexmk" export LTMKEDIT="$HOME/Library/TeXShop/bin" # make sure latexmkrcedit exists in bin if [ ! -e "${LTMKEDIT}/latexmkrcedit" ] ; then cp "${LTMKBIN}/latexmkrcDONTedit" "${LTMKEDIT}/latexmkrcedit" fi "${LTMKBIN}"/latexmk -f -pdf -r "${LTMKEDIT}/latexmkrcedit" -r "${TSBIN}/lualatexm When I get an error and don’t want to care about the error for the moment, I press ”r” in the console and it then runs through one process and forgets about all the errors. This mode is called \nonstopmode, because it does not stop at each and every error. Since, however, lualatexmk runs the documentgenerating-process several times, I need to press ”r” also several times. My simple question is: How do I have to edit lualatexmk.engine to let it run completely in \nonstopmode, so that each and every error is ignored for the moment? Tags: compiling (Prev Q) (Next Q) User: clinteastwood

Answer by yo’ The \...mode commands can be added directly in the document, and this should work in LuaTeX as well. Therefore adding the following line as the first line of your document should suffice: \nonstopmode

Tags: compiling (Prev Q) (Next Q)

1106

Q: How to set the interactive editor in TeXLive? lualatex bug? Tags: compiling (Prev Q), bugs (Prev Q) (Next Q), editors (Next Q) After some research we determined this is a problem inherent to lualatex. If you have a solution for this problem in LuaLaTeX please post it below and I will accept you answer. When compiling a file with LaTeX (and others), if there is an error one has the option to edit the file at the line of the error (or near) by pressing e + Enter. For example, if one has this file \documentclass{article} \begin{document} \badcommand \end{document} I get this ... Document Class: article 2007/10/19 v1.4h Standard LaTeX document class (/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo)) (./main.aux) ! Undefined control sequence. l.3 \badcommand ? However, in my current configuration TeXLive 2015 (Fedora), nothing happens. I only get this message: You want to edit file ./main.tex at line 81 297 words of node memory still in use: 3 hlist, 1 rule, 48 glue_spec, 1 write, 1 dir, 1 pdf_colorstack nodes avail lists: 2:12,3:1,6:2,9:1 No pages of output. Transcript written on document.log. prompt $_ How can I configure the editor? in particular Gedit. (I am suspecting it tries to open emacs which is not installed, but still I would

1107

like to use Gedit instead). Tags: compiling (Prev Q), bugs (Prev Q) (Next Q), editors (Next Q) User: alfc

Answer by cfr If you are happy setting this system wide, you can edit the customisation into texmf.cnf but it is important to pick the correct texmf.cnf. Probably kpsewhich texmf.cnf should return the correct file. On my system, for TeX Live 2015, this is /usr/local/texlive/2015/texmf.cnf. Wherever it is, the file should be almost empty with just some explanatory comments at the top. Here’s mine after adding the configuration line for the editor: Skip code block % (Public domain.) % This texmf.cnf file should contain only your personal changes from the % original texmf.cnf (for example, as chosen in the installer). % % That is, if you need to make changes to texmf.cnf, put your custom % settings in this file, which is .../texlive/YYYY/texmf.cnf, rather than % the distributed file (which is .../texlive/YYYY/texmf-dist/web2c/texmf.cnf). % And include *only* your changed values, not a copy of the whole thing! % TEXEDIT = /usr/bin/vim +%d '%s' You will need to add an appropriately modified TEXEDIT = /usr/bin/vim +%d '%s' to your file, as I just added this line to mine. After doing so, I can edit the file using e. I am not sure why the default is not to use the system or user value of EDITOR. TeX simply ignores this on my system and tries to use an editor which doesn’t exist, with inevitably unsatisfactory results. What it should do is use EDITOR if that’s configured, but I can’t even get the file to use the value of a shell variable, so probably this is a hopeless enterprise. Hence, I

1108

hard-coded it as shown above, which does work even though the solution is not really a satisfying one.

Tags: compiling (Prev Q), bugs (Prev Q) (Next Q), editors (Next Q)

Format Files Questions Q: How can I dump Lua code to a format file? Tags: format-files (Prev Q) (Next Q) From this format: Skip code block %% testformat.ini \input plain \directlua {tex.enableprimitives('', tex.extraprimitives())} \directlua { testFunction = function () tex.print("This was print by Lua's testFunction.\par") end } %% \directlua {testFunction()} %% \bye \dump I create a testformat.fmt with $ luatex -ini testformat.ini, but when trying to use it with the following test file: %% test-testformat.tex \directlua{testFunction()} \bye

1109

the globaly defined function testFunction is lost: Skip code block $ luatex -fmt testFormat.fmt test-testformat.tex This is LuaTeX, Version beta-0.70.1-2011120612 (./test-testformat.tex ! LuaTeX error :1: attempt to call global 'testFunction' (a nil va lue) stack traceback: :1: in main chunk. l.2 \directlua{testFunction()} ? Should I do another trick in Lua or it simply can’t be dumped and I must use something like \everyjob{\directlua{dofile("testformat.lua")}}? Tags: format-files (Prev Q) (Next Q) User: caio-lopes

Answer by joseph-wright For the LaTeX3 l3bootstrap module, we wanted to enable the equivalent of \pdfstrcmp using Lua code for LuaTeX. To build that into a format, we wanted to avoid having to read a .lua file each run. Taco Hoekwater suggested the use of lua.bytecode. We use this as: Skip code block \directlua { lua.bytecode[1] = function () function strcmp (A, B) if A == B then tex.write("0") elseif A < B then tex.write("-1") else tex.write("1") 1110

end end end lua.bytecode[1]() } \everyjob\expandafter {\the\everyjob\directlua{lua.bytecode[1]()}} i.e. you have to save the bytecode and use the \everyjob TeX primitive to active it for each run. (I’ve modified slightly from the version in the .dtx as there are other details there which are not relevant to this question.)

For reference, you would access the above using something like \long\def\pdfstrcmp#1#2{% \directlua{strcmp("\luaescapestring{#1}","\luaescapestring{#2}" )}% } (The pdfstrcmds package calls this \[email protected], as it requires an additional expansion compared to the primitive and so is ’safest’ given a different name. In the LaTeX3 load code, that’s not a worry as we don’t directly expose this, so we take a slightly different approach.)

Tags: format-files (Prev Q) (Next Q)

Q: LuaTeX 0.85 \pdf* primitive changes and format file generation Tags: format-files (Prev Q) (Next Q) TeX Live 2015 ships with LuaTeX 0.80. As LuaTeX 0.85 became available last month and I am supposed to do be doing other things I found this to be a wonderful opportunity to procrastinate by giving the 0.85 version a try. Building the executable was unproblematic. However to avoid a (Fatal format file error; I'm stymied) 1111

error, the format files had to be regenerated. fmtutils-sys --all however failed to regenrate the LuaTeX related format files. Doing it manually via: luatex -ini

-jobname=luatex -progname=luaex luatex.ini

revealed that the very first line fails: ! Undefined control sequence. l.4 \pdfoutput =1 ? ! Emergency stop. Which is quite bad, because \pdfoutput is primitive control sequence of pdfTeX, it is always there, out of the box. But not any more in LuaTeX 0.85 it seems. In fact section 8.1.7 of the LuaTeX manual explains that all but three of the \pdf* primitives are gone. In the same section the manual provides a list of commands to get the traditional pdfTeX \pdf*-primitives back. However the use of \protected is only possible if the eTeX primitives in LuaTeX have been enabled. That happens in /usr/local/texlive/2015/texmf-dist/tex/generic/config/luatexiniconfig.tex which is the first thing that /usr/local/texlive/2015/texmf-dist/tex/plain/config/luatex.ini loads. Extending luatexiniconfig.tex with list of commands almost succeeds. The last commands on the list use \newdimen which is not a primitive. It is defined in the plain-TeX-Format. As luatex.ini loads pdfetex.ini which in turn loads etex.src which loads plain.src the \newdimen command sequence will not be available until after all the files have been processed. However pdfetex.ini of course ends with \dump end \endinput Adding something after pdfetex.ini has been processed would be pointless. Thus, my modified luatex.ini therefore looks like this: 1112

Skip code block % $Id: luatex.ini 26647 2012-05-24 23:54:05Z karl $ % Karl Berry, originally written 2008. Public domain. % PDF output by default. % must be done first (activation of primitives) \input luatexiniconfig.tex \input luatex-unicode-letters.tex \input pdftexconfig.tex \input etex.src \input pdftexmagfix.tex \newdimen\pdfeachlineheight \newdimen\pdfeachlinedepth \newdimen\pdflastlinedepth \newdimen\pdffirstlineheight \newdimen\pdfignoreddimen \dump \endinput Now fmtutils-sys successfully generats the luatex.fmt format file. The lualatex.fmt still fails. The lualatex.ini can be extended with the list of \pdf* commands just as well. However do something like \protected\def\pdfliteral{\pdfextension literal} one needs at least \catcode`\{=1 \catcode`\}=2 as we are in iniTeX-mode. But there very first thing that latex.ltx checks is \ifnum\catcode`\{=1 \errmessage {LaTeX must be made using an initex with no format preloaded} \fi and this is triggered now. Thus the lualatex.ini needs and additional 1113

\catcode`\{=2 It now looks like this: Skip code block % $Id: lualatex.ini 38624 2015-10-12 23:38:27Z karl $ % Originally written 2008 by Karl Berry. Public domain.

\begingroup \catcode`\{=1 % \catcode`\}=2 % % JAW: Enable 'extra' pdfTeX primitives only in .ini file % latex.ltx enables the extra primitives bu a subset of those from % pdfTeX are needed to do the configuration below (pdftexconfig.tex). % Rather than list them all, just enable those classed as 'pdftex'. \directlua{tex.enableprimitives('',tex.extraprimitives('pdftex', 'luatex', 'et % JAW: Set up job name quoting before latex.ltx % Web2c pdfTeX/XeTeX quote job names containing spaces, but LuaTeX does % not do this at the engine level. The behaviour can be changed using % a callback. Originally this code was loaded via lualatexquotejobname.tex % but that required a hack around latex.ltx: the behaviour has been altered % to allow the callback route to be used directly. \global\everyjob{\directlua{require("lualatexquotejobname.lua")}} \endgroup \catcode`\{=1 \catcode`\}=2 % recreate the traditional pdfTeX primitives here REMOVED FOR BREVITY \catcode`\{=2 % settings inherited from pdftex \input pdftexconfig.tex % pdf output by default \input latex.ltx Again latex.ltx ends with \dump and \endinput so the necessary 1114

\newdimen commands: \newdimen\pdfeachlineheight \newdimen\pdfeachlinedepth \newdimen\pdflastlinedepth \newdimen\pdffirstlineheight \newdimen\pdfignoreddimen cannot be inserted after the \input latex.ltx line, that would be to late. Removing the last to lines from latex.ltx \dump \endinput and placing them in lualatex.ini as follows Skip code block % settings inherited from pdftex \input pdftexconfig.tex % pdf output by default \input latex.ltx \newdimen\pdfeachlineheight \newdimen\pdfeachlinedepth \newdimen\pdflastlinedepth \newdimen\pdffirstlineheight \newdimen\pdfignoreddimen \dump \endinput allows fmtutil-sys --all to regenerate the lualatex.fmt format file. But now that the LaTeX source has been changed all other formats of course are broken. There must be a better way to do this! Any ideas? Tags: format-files (Prev Q) (Next Q) User: uli

1115

Answer by joseph-wright LuaTeX from v0.85 onward removes essentially all of the pdfTeX ’back end’ primitives in favour of three new interfaces: • \pdfextension • \pdffeedback • \pdfvariable At the same time, there are several other renames and changes to the Lua side (the original token library is removed, and the newtoken library replaces it meaning there is no newtoken any more). These changes require significant work in the format-building process (many of the primitives impacted are not used by end users), in parts of the LaTeX kernel (where the change to the token library impacts) and in packages (most obviously graphics drivers and ifpdf). ’Fixing’ all of this in a transparent way is non-trivial. (There’s not just LaTeX to think about: plain LuaTeX is also affected.) The LaTeX team have been working on this with the TeX Live maintainer for some time, deciding on how best to handle the required adaptation. At the time of writing, we have several parts of the ’jigsaw’ decided but are still implementing them. There are particular issues with the package support: it’s very likely that a ’compatibility’ package will be needed at least in the short term. (The core team do not control all packages using the PDF back end primitives!) There is also a need to co-ordinate with MiKTeX, TeX Live management utilities and so on. All of this means that official (CTAN release) support for LuaTeX v0.85+ will not happen ’just yet’. Currently the plan is to get this in place by early in 2016 with a definite requirement for it all to work for TL’16. Anyone testing in the meantime should get in contact with the team/me to get onto the CC list for discussions. To be clear: unless you are entirely comfortable hand-rebuilding formats and messing with your TeX tree, do not try LuaTeX v0.85 but wait for official support from TeX Live.

1116

Tags: format-files (Prev Q) (Next Q)

Q: How to create luatex.fmt Tags: format-files (Prev Q) I wanted to try the latest version of LuaTeX, so I downloaded the official precompiled binaries but these raw binaries are useless without a luatex.fmt. How can this file be created? Tags: format-files (Prev Q) User: h0b0

Answer by joseph-wright I’m assuming you have TeX Live installed, so will have the file ’luatex.ini’. You need that (i.e. copy to where you are going to generate your format file), as it specifies how to build the format. You should then be able to do luatex -ini luatex.ini to build the format file.

Tags: format-files (Prev Q)

Packages Questions Q: Good lua code in .tex doesn’t work in .sty? Tags: packages (Prev Q) 1117

I have some luacode in a .tex file that works fines, but does’t in a .sty file -- with this error message : Runaway argument? ! File ended while scanning use of \[email protected]@lines. \par mwe.tex .tex file Skip code block \documentclass{article} \usepackage{luacode,mwe} \begin{document} % works fine for i = 0,10 do tex.print (i) end % doesn't work \For \end{document} mwe.sty file \newcommand{\For}{% \begin{luacode} for i = 0,10 do tex.print (i) end \end{luacode} } Tags: packages (Prev Q) User: tarass

1118

Answer by joseph-wright The luacode environment works by changing catcode codes to make in the input easier to pass to Lua. That can’t work inside a macro: the input is already tokenized. In that sense luacode is similar to a verbatim environment. For any long block of Lua code you are best having it in a separate file, whilst for short blocks I’d stick to \directlua and be aware of the requirements, which here are minimal \newcommand*\For{% \directlua{ for i = 0,10 do tex.print(i) end }% } (You actually get the error as the \end{luacode} is being found using a verbatim-like approach, and that will always fail inside a macro.)

Tags: packages (Prev Q)

Windows Skip to questions, Wiki by user caramdir windows is for questions which are specific for the Microsoft Windows operating systems. Questions regarding MikTeX, a popular TeX distribution for Windows, should be tagged with miktex instead.

1119

Questions Q: Is it possible to run LuaTeX from a USB flash drive Tags: windows (Prev Q) (Next Q) I am looking for ways to install and run LuaTeX on a USB flash drive (Windows operating system). Tags: windows (Prev Q) (Next Q) User: yiannis-lazarides

Answer by aditya ConTeXt minimals does not require any installation and can be run from a USB stick. It contains the latest luatex binary along with plain and context macro packages ... but no latex. So, depending on what macro package you want to use, it may or may not be useful.

Answer by will-robertson LuaTeX will be included MiKTeX 2.9, due out soon. When that happens, I presume you’ll be able to run it (and hence LuaTeX) on MiKTeX Portable. (I couldn’t see anything about the portable version on the MiKTeX 2.9 beta page.)

Answer by mpg TeX Live also offers a portable mode, thought it’s not well documented (if at all) currently. With TeX Live 2010, use install-tl -portable, then select your USB stick as the destination folder. You can customize the installation as usual (eg, selecting only the packages you need in order to save space). One installed, all you need to do is to run the tl-portable.bat script at the root of the installation.

1120

Tags: windows (Prev Q) (Next Q)

Q: Precompiled header in Lualatex on Windows? Tags: windows (Prev Q) I am trying to typeset a longer document with lots of packages. Now it seems that pre-compiling the header can speed up the edit-compile-revise cycle quite a bit. I tried to follow the guideline from How to speed up pdflatex for a very large document on MacOS X? but it does not work on my system and I am not sure what I am doing wrong. My preamble.tex looks as follows: \documentclass[a4paper]{scrbook} \usepackage{scrpage2} \def\preambleloaded{Precompiled preamble loaded.} and the main.tex file:

\def\ifundefined#1{\expandafter\ifx\csname#1\endcsname\relax} \ifundefined{preambl \typeout{PRECOMILED PREAMBLE NOT LOADED}\input{preamble} \else \typeout{\preambleloaded} \fi \begin{document} test test test \end{document} Now after compiling the preamble with lualatex -ini -job-name="main" "&lualatex preamble.tex\dump" a main.fmt file is created and lualatex runs without errors. Compiling the main file with lualatex -shell-escape main.tex gives the message right at the beginning that the preamble was not included: LaTeX2e 1121

LuaTeX adaptation of babel and hyphenation patterns for engl ish, loaded. PRECOMILED PREAMBLE NOT LOADED (C:/Users/User/Documents/LaTeX/precompile/preamble.tex (C:/Users/User/AppData/Roaming/MiKTeX/2.9/tex/latex/koma-script/scrbook.cls ... The only difference that I can think of at the moment is that I am using LuaLaTeX on Windows 7 instead of pdftex on Mac OS X as in the linked question. Any hint how to fix this is very appreciated. Tags: windows (Prev Q) User: alexander

Answer by taco-hoekwater You need: lualatex -shell-escape "&main main.tex" otherwise the newly generated main.fmt file is not used at all.

Tags: windows (Prev Q)

Conditionals Skip to questions, Wiki by user lockstep conditionals is about macros like \if and \ifx that may execute other macros depending on whether certain conditions are true or not. Popular packages are etoolbox and ifthen.

1122

Questions Q: Check if LuaTeX is running Tags: conditionals (Prev Q) (Next Q) I want to check if my tex document is compiled with LuaTeX (or any other Lua TeX compiler). The simple approach from the TeXbook is to check the \directlua macro against \@empty, like \ifx\directlua\@empty{\errmessage{...}}\fi If I’m running luatex, everything is fine. If I run tex, the compilation fails with my \errmessage -- fine. But if I run latex, my error does not occur, but the compilation fails because of the undefined \directlua environment. Which \ifx statement works for all TeX dialects? And why not the one which works fine with plain TeX, the one from above? Thanks in advance :) UPDATE An solution for this is very easy, but I don’t know if it’s causing any problems in the future. \ifx\directlua\[email protected]@[email protected]{% \errmessage{an error}\fi works well with TeX and LaTeX. Is there a way which is more elegant and doesn’t need any additional packages? Otherwise I will post this as answer. Tags: conditionals (Prev Q) (Next Q) User: matten

Answer by ulrike-fischer \@empty is defined in LaTeX, so your test fails. ifluatex.sty? It will work with plainTeX too,

Answer by hasan-zakeri 1123

Why don’t you use

How about iftex? it works fine in plain, and gives you some other useful macros. It is also included in TeXLive.

Tags: conditionals (Prev Q) (Next Q)

Q: Testing for TeX boolean in Lua code Tags: conditionals (Prev Q) How can I test for a TeX boolean in Lua? This kind of code doesn’t work: Skip code block \newif\[email protected]@someif \begin{luacode} -- some lua code \[email protected]@someif -- some more lua code \else -- another lua code \fi -- again some lua code \end{luacode} Is there a way to achieve this? Tags: conditionals (Prev Q) User: �aphink

1124

Answer by aditya Tex expansion happens before control is passed to lua. The following minimal example works. Skip code block \documentclass{minimal} \usepackage{luacode} \newif\ifluaflag % \luaflagtrue \begin{luacode} print("before flag") \ifluaflag print("lua flag true") \else print("lua flag false") \fi \end{luacode}

\begin{document} test \end{document}

Tags: conditionals (Prev Q)

Graphics Skip to questions, Wiki by user seamus

1125

graphics is about inclusion of external graphic files in your document. For questions about vector graphics created programmatically inside a (La)TeX document, use diagrams instead, or preferably the tag for specific packages like tikz-pgf, pstricks, or metapost. Frequently Asked Questions 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11.

How can I include SVG images in LaTeX documents? How can I convert a TeX document into a small PNG? What’s the best way to include Matlab graphics in LaTeX? Which graphics formats can be processed by LaTeX and pdfLaTeX? How can I include graphics whose file path has spaces? Why does using transparency in illustrations cause text to appear in bold? Why can’t pdfLaTeX print EPS figures? What GUI applications exist to help generate graphics for LaTeX? Can I use TikZ to draw on an image? How can I include graphics whose file path has multiple dots? How can I add a border to an image?

Questions Q: Ploting a function using mplib in lualatex Tags: graphics (Prev Q) This question asked about ways to generate a nice function graph in LaTeX. There are several great answers, however, most of the either rely on an external program to generate the plot, or, if they use TeX to calculate the coordinates of the graph, are restricted to only fairly simple functions. I wanted to come up with an answer using luatex, using lua to do the calculations, and mplib to actually draw the graph. However, I could not figure out how to use lua and mplib together. Generating the graph in lua is not hard, and I can pass the generated path to tikz for rendering: Skip code block 1126

\documentclass{article} \usepackage{luacode} \usepackage{tikz} \begin{luacode} require("math") sin=math.sin;cos=math.cos;pi=math.pi point = function (f,x) return "("..x..","..f(x)..")" end; path = function (f,a,b,n) local step = (b-a)/n; local s = ""; for x = a, b - step/2, step do s = s .. point(f,x) .. "--" end; s = s .. point(f,b); return s end; \end{luacode} \def\plot#1#2#3#4{% \directlua{ do local f = function (x) return #1 end; tex.print(path(f,#2,#3,#4)) end; }% }

\begin{document} \begin{tikzpicture} \draw[thin,->] (-.2,0)--(6.5,0)node[right]{$x$}; \draw[thin,->] (0,-2.2)--(0,2.2)node[above]{$y$}; \draw[thick] \plot{sin(2*x)+cos(x)}{0}{2*pi}{40}node[above]{$y=\sin(2x)+\cos(x) \end{tikzpicture} \end{document} I would like to know what would be a best way to generate a drawing using lua and render it using mplib. Tags: graphics (Prev Q) User: jan-hlavacek

1127

Answer by aditya This is how I would do it in ConTeXt. I don’t know if similar functionality is available in a LaTeX package. Basically, I do the calculations in lua and write the result inside a \startMPcode .. \stopMPcode environment. \startluacode require("math") local sin = math.sin local cos = math.cos local pi = math.pi local function scale(x) return x .. " * 1cm" end local function pair(x,y) return "(" .. scale(x) .. "," .. scale(y) .. ")" end local function point(f,x) return pair(x, f(x)) end userdata = userdata or {} function userdata.draw_function(f, a, b, n) local step = (b-a)/n local path = {} local i = 0 for x = a, b, step do path[i] = point(f,x) i = i + 1 end path = table.concat(path, "--") context("draw " .. path .. " withpen pencircle scaled 2bp;") end function userdata.draw_x_axis(from, to) 1128

context(" drawarrow " .. pair(from,0) .. " -- " .. pair(to,0) .. "; ") context(" label.rt ( btex $x$ etex , " .. pair(to,0) .. ") ;") end function userdata.draw_y_axis(from, to) context(" drawarrow " .. pair(0, from) .. " -- " .. pair(0,to) .. "; ") context(" label.top ( btex $y$ etex , " .. pair (0,to) .. ") ;") end function userdata.plot() userdata.draw_x_axis(-2, 6.5) userdata.draw_y_axis(-2.2, 2.2)

local f = function (x) return sin(2*x) + cos(x) end userdata.draw_function(f, 0, 2*pi, 40) end \stopluacode \starttext \ctxlua {context.startMPcode() ; userdata.plot() ; context.stopMPcode() ; } \stoptext However, this assumes that everything that is written inside teh userdata.plot() function is MP code. If you also want that function to print stuff to the TeX stream, then you can store all the MP code inside a \startMPdrawing and \stopMPdrawing environment and retrieve them using \getMPdrawing. \startluacode require("math") 1129

local sin = math.sin local cos = math.cos local pi = math.pi local function scale(x) return x .. " * 1cm" end local function pair(x,y) return "(" .. scale(x) .. "," .. scale(y) .. ")" end local function point(f,x) return pair(x, f(x)) end userdata = userdata or {} function userdata.draw_function(f, a, b, n) local step = (b-a)/n local path = {} local i = 0 for x = a, b, step do path[i] = point(f,x) i = i + 1 end path = table.concat(path, "--") context.startMPdrawing() context("draw " .. path .. " withpen pencircle scaled 2bp;") context.stopMPdrawing() end function userdata.draw_x_axis(from, to) context.startMPdrawing() context(" drawarrow " .. pair(from,0) .. " -- " .. pair(to,0) .. "; ") context(" label.rt ( btex $x$ etex , " .. pair(to,0) .. ") ;") context.stopMPdrawing() end 1130

function userdata.draw_y_axis(from, to) context.startMPdrawing() context(" drawarrow " .. pair(0, from) .. " -- " .. pair(0,to) .. "; ") context(" label.top ( btex $y$ etex , " .. pair (0,to) .. ") ;") context.stopMPdrawing() end function userdata.plot() userdata.draw_x_axis(-2, 6.5) userdata.draw_y_axis(-2.2, 2.2)

local f = function (x) return sin(2*x) + cos(x) end userdata.draw_function(f, 0, 2*pi, 40) end \stopluacode \starttext \ctxlua { context.resetMPdrawing() ; userdata.plot() ; context.MPdrawingdonetrue() ; context.getMPdrawing() ; } \stoptext

Answer by jan-hlavacek I combined Aditya’s ConTeXt solution with my original code and modified it for LaTeX. It mostly works, except I seem to have trouble with using btex ... etex in labels. If I replace the two lines with mpost labels with their commented version in the code below, I get Skip code block 1131

! LuaTeX error ...share/texmf-texlive/tex/luatex/luamplib/luamplib.lua:74: invalid stack traceback: [C]: in function 'format' ...share/texmf-texlive/tex/luatex/luamplib/luamplib.lua:74: in function 'log' ...share/texmf-texlive/tex/luatex/luamplib/luamplib.lua:143: in function 'repor ...share/texmf-texlive/tex/luatex/luamplib/luamplib.lua:173: in function 'proce ...share/texmf-texlive/tex/luatex/luamplib/luamplib.lua:101: in function 'proce :1: in main chunk. \endmplibcode ...adirect {luamplib.processlines()} l.49 \plot{sin(2*x)+cos(x)}{0}{2*pi}{40}{-2}{2} The following works: Skip code block \documentclass{article} \usepackage{luatextra} \usepackage{luamplib} \begin{luacode} scale = function (x) return x .. " * 1cm" end; pair = function (x,y) return "("..scale(x)..","..scale(y)..")" end; point = function (f,x) return pair (x,f(x)) end; path = function (f,a,b,n) local step = (b-a)/n; local s = ""; for x = a, b - step/2, step do s = s .. point(f,x) .. "--" end; s = s .. point(f,b); return s end; draw_x_axis = function (from, to) tex.print(" drawarrow " .. pair(from,0) .. " -- " .. pair(to,0) .. "; ") tex.print([[ label.rt ( "x" , ]] .. pair(to,0) .. ") ;") % The following does not work, though: %tex.print(" label.rt ( btex $x$ etex, " .. pair(to,0) .. ") ;") end draw_y_axis = function (from, to) tex.print(" drawarrow " .. pair(0, from) .. " -- " .. pair(0,to) .. "; ") 1132

tex.print([[ label.top ( "y" , ]] .. pair (0,to) .. ") ;") % The following does not work, though: %tex.print(" label.top ( btex $y$ etex , " .. pair (0,to) .. ") ;") end beginMPcode = function () tex.print("\string\\begin{mplibcode}") tex.print("beginfig(0)") end; endMPcode = function () tex.print("endfig;") tex.print("\string\\end{mplibcode}") end; \end{luacode} \def\plot#1#2#3#4#5#6{% \directlua{ require("math") local sin=math.sin;local cos=math.cos;local pi=math.pi % ... and so on local f = function (x) return #1 end; beginMPcode() draw_x_axis(#2-.2,#3+.2) draw_y_axis(#5-.2,#6+.2) tex.print("draw " .. path(f,#2,#3,#4) .. " withpen pencircle scaled 2pt;" ) endMPcode() }% } \begin{document} \plot{sin(2*x)+cos(x)}{0}{2*pi}{40}{-2}{2} \end{document} Any ideas on how to make this better, and how to fix the problem with labels?

Tags: graphics (Prev Q)

1133

Verbatim Skip to questions, Wiki by user martin-scharrer verbatim is about macros and environments like \verb and verbatim which implement some form of verbatim mode, i.e. change the catcodes. A popular package is fancyvrb. For questions about the listings or the minted package, use the respective tag instead.

Questions Q: How to handle verbatim material in LuaLaTeX? Tags: verbatim (Prev Q) (Next Q) While trying to implement an own working alternative to shdoc (one of its issues see here) I encountered an interesting behaviour of LuaLaTeX I cannot explain. Consider the following code: Skip code block \documentclass{scrreprt} \usepackage{xparse} \usepackage{luacode} \DeclareDocumentCommand{\terminaloutput}{+v}{ \directlua{tex.print("\luatexluaescapestring{#1}")} } \begin{document} \terminaloutput{ total 10244 1134

drwxr-xr-x 47 User dr-xr-xr-x 8 User drwxr-xr-x 9 User -rw-r--r-- 1 User } \end{document}

Users Users Users Users

16384 4096 4096 2950

Mar Jun Dec Mar

31 18:26 . 27 2015 .. 23 12:49 .editor 31 09:01 .bash_history

I just defined a function using a verbatim argument (\terminaloutput) which has to be verbatim since there is a _ in .bash_history. My question is why LaTeX is able to print the whole content of #1 (as expected in a continuous way) and Lua doesn’t print anything. Tags: verbatim (Prev Q) (Next Q) User: texnician

Answer by mico Rather than re-invent the wheel, I prefer to refer to and build on Paul Isambert’s wonderful article LuaTEX: What it takes to make a paragraph, published in 2011 in Volume 32 of TUGBoat. In this article, the author discusses inter alia how one can make use of the LuaTeX’s process_input_buffer callback to handle verbatim material in a very robust and flexible manner. To quote from the article: One of the most arcane areas of TeX is catcode management. This becomes most important when one wants to print verbatim text, i.e. code that TeX should read as characters to be typeset only, with no special characters, and things turn definitely dirty when one wants to typeset a piece of code and execute it too (one generally has to use an external file). With the process_input_buffer callback, those limitations vanish: the lines we would normally pass to TeX can be stored and used in various ways afterward. The MWE shown adapts Paul’s code to LaTeX coding practices. (Paul’s code is distinctly PlainTEX-ish.) If you’re at all interested in this issue, you should absolutely read Paul’s original article; the material on handling verbatim material is on pp. 2 and 3 in the pdf file (pp. 69 and 70 in original 1135

published article). Paul explains the issues far better than I possibly could. • The Lua-side code consists of defining a Lua table (which will hold the verbatim material) and 3 Lua functions that do most of the work. • The TeX-side code sets up several TeX macros that activate, invoke, and suspend the operation of the Lua functions. The main LaTeX macros are \printverbatim (you should be able to guess what it does...) and \useverbatim; the latter executes whatever is in the most recently read verbatim chunk. • A verbatim chunk is anything sandwiched between lines that say \Verbatim and \EndVerbatim, respectively. Note that I have not defined a LaTeX environment called Verbatim, although it wouldn’t be too hard to do so.

Skip code block \documentclass{scrreprt} %% Set up a Lua table and 3 Lua functions \directlua{% verb_table = {} function store_lines (str) if string.find (str , "\noexpand\\EndVerbatim" ) then luatexbase.remove_from_callback ( "process_input_buffer" , "store_lines") else table.insert(verb_table, str)

1136

end return "" end function register_verbatim () verb_table = {} luatexbase.add_to_callback( "process_input_buffer" , store_lines , "store_lines") end function print_lines ( catcode ) if catcode then tex.print ( catcode , verb_table) else tex.print ( verb_table ) end end } %% TeX-side code: define several macros \def\Verbatim{\directlua{register_verbatim()}} \def\useverbatim{\directlua{print_lines()}} \def\printverbatim{% \par \bgroup \setlength{\parindent}{0pt} \ttfamily \directlua{print_lines(1)} \egroup } \def\createcatcodes{% \bgroup \catcode`\\=12 \catcode`\{=12 \catcode`\}=12 \catcode`\$=12 \catcode`\&=12 \catcode`\^^M=13 \catcode`\#=12 \catcode`\^=12 \catcode`\_=12 \catcode`\ =13 \catcode`\~=12 \catcode`\%=12 \savecatcodetable 1 % '\savecatcodetable' is a LuaTeX primitive \egroup} \createcatcodes \def\Space{ } \bgroup 1137

\catcode`\^^M=13\gdef^^M{\quitvmode\par}% \catcode`\ = 13\gdef {\quitvmode\Space}% \egroup \begin{document} \Verbatim total 10244 drwxr-xr-x 47 User dr-xr-xr-x 8 User drwxr-xr-x 9 User -rw-r--r-- 1 User \EndVerbatim \printverbatim

Users Users Users Users

16384 4096 4096 2950

Mar Jun Dec Mar

31 18:26 . 27 2015 .. 23 12:49 .editor 31 09:01 .bash_history

\bigskip \Verbatim \def\lululu{% Lua\kern-.01em \TeX }% \EndVerbatim \printverbatim \bigskip \useverbatim % this "registers" the macro "\lululu" \noindent\lululu \end{document}

Answer by henri-menke Mico’s answer is very good and shows how a low-level implementation of verbatim buffers in LuaTeX could look like. ConTeXt comes with this feature included and it is super easy to use. Skip code block \starttext 1138

\startbuffer[terminal] total 10244 drwxr-xr-x 47 User Users dr-xr-xr-x 8 User Users drwxr-xr-x 9 User Users -rw-r--r-- 1 User Users \stopbuffer

16384 4096 4096 2950

Mar Jun Dec Mar

31 18:26 . 27 2015 .. 23 12:49 .editor 31 09:01 .bash_history

\typebuffer[terminal] \startbuffer[logo] \def\lululu{% Lua\kern-.01em \TeX }% \stopbuffer \typebuffer[logo] \getbuffer[logo] \lululu \stoptext The output is similar to Mico’s answer.

Tags: verbatim (Prev Q) (Next Q)

Q: show content of token register as a string in the document Tags: verbatim (Prev Q) I’m trying to implement a command that can execute its argument, but also print it. 1139

To that end I’m dumping the argument into a toks register and use LuaTex to put it back with inactive catcodes; as it says in the manual: tex.print( n, s, ...) If n is −1, the currently active catcode regime is used. If n is −2, the resulting catcodes are the result of \the\toks: all category codes are 12 (other) except for the space character, that has category code 10 (space) \newcommand{\showandtell}[1]{\toks0{#1}% {using the argument #1 executes}\\ {printing with current \directlua{tex.print(-1, tex.toks[0])} executes}\\ {printing with inert \texttt{ \directlua{tex.print(-2, tex.toks[0])}} shows the code}\\ {reading the register \the\toks0 executes} } \noindent\showandtell{\bfseries\color{red}} From ”the resulting catcodes are the result of \the\toks” in the manual I was expecting \the\toks0 to have the opposite effect. How can I get the effect of print(-2 in pure TeX? The token register appears to be stored as a string, discarding the original catcodes, but then how can packages like verbatim just use just \the\[email protected] and produce plain output?

Tags: verbatim (Prev Q) User: pascal

Answer by egreg

1140

You can obtain the same effect in e-TeX (not in Knuth TeX) with \detokenize, which is available when LaTeX is used (on TeX distributions not more than ten years old). Skip code block \documentclass{article} \usepackage{color} \newcommand{\showandtell}[1]{% {using the argument #1 executes}\\% printing with detokenize \texttt{\detokenize{#1}} shows the code% } \begin{document} \noindent \showandtell{\bfseries\color{red}} \end{document}

If you want to use a token register, then \detokenize\expandafter{\the\toks0} will do. Verbatim modes attain their purpose by changing category codes before starting to read the material, which is why they can’t be used in the argument to a command. Note, however, that \detokenize, like the LuaTeX code you used, adds a space after control words (which verbatim modes don’t).

Answer by jfbu It is also possible to achieve this in Knuth TeX via \meaning. Although there is no reason not to use \detokenize if it is available. Skip code block

1141

\documentclass{article} \usepackage{color} \makeatletter \let\StripPrefix\[email protected] % Latex kernel command \makeatother

\newcommand{\showandtell}[1]{% {using the argument #1 executes}\\% \def\TEMP {#1}% playing tricks with meaning \texttt{\expandafter\StripPrefix\meaning\TEMP} shows } \begin{document} \noindent \showandtell{\bfseries\color{red}} \end{document}

and if you want to show things from \toks0 register you can do \expandafter\def\expandafter\TEMP\expandafter{\the\toks0} or simpler \edef\TEMP{\the\toks0} and then the \meaning thing.

Tags: verbatim (Prev Q)

1142

Latexmk Skip to questions, Wiki by user martin-scharrer The latexmk program allows to automatically run latex and related commands as many times as needed to build the final document. It is an alternative or complement to Makefiles or similar functionality of integrated LaTeX editors. It is available on CTAN and on its project site by the maintainer, John Collins. See the manpage for more information. There is a similar tool named LaTeX-Mk, which yet is distinct from latexmk.

Questions Q: Is there latexmk functionality for LuaTeX? Tags: latexmk (Prev Q) (Next Q) I am a big fan of latexmk and lately I have been looking a bit towards LuaTeX. However I am am yet to find a way to get the functionality of latexmk (mainly recompilation on changes and automatic rerun an appropriate number of times to resolve cross references and such) for LuaTex. Is there something similar and if not how do you LuaTeX people survive without it? :) Tags: latexmk (Prev Q) (Next Q) User: jonalv

Answer by diabonas You can use Lua(La)TeX with latexmk by setting the -pdflatex parameter: 1143

-pdflatex= - set program used for pdflatex. (replace ’’ by the program name) So latexmk should call lualatex instead of pdflatex if you invoke it like this: latexmk -pdflatex=lualatex -pdf or with newer versions of latexmk there is direct Lua(La)TeX/XeLaTeX support: -lualatex Use lualatex. That is, use lualatex to process the source file(s) to pdf (in place of pdflatex). This option is exactly equivalent to specifying the following sequence of options: -pdflatex=”lualatex %O %S” -pdf -dvi- -ps-

Answer by yossi-gil Instead of adding the -lualatex flag to each application of latexmk, you could place the following $pdflatex = 'lualatex -file-line-error %O %S'; $pdf_mode = 1; in an ’.latexmkrc’ file. This file should reside in your home folder, if you use lualatex in all your jobs, or in the folder(s) where your lualatex jobs are. More generally, you will find a host of examples and boilerlate code for .latexmkrc in the respective CTAN repository

Tags: latexmk (Prev Q) (Next Q)

Q: Specify timezone for \today and \currenttime Tags: latexmk (Prev Q) 1144

Is there a way I can specify the timezone LaTeX should use when printing the \today and \currenttime (or the datetime package in general)? I need this because travisCI does build my PDF automatically on every commit and their timezone seems to be set to GMT. I’d need GMT+1. Contrary to some other questions I don’t want the timezone to be displayed, I just want the date & time to be in the specified timezone. For building I use latexmk with pdflatex set to LuaLaTeX. Tags: latexmk (Prev Q) User: michael-weibel

Answer by michael-weibel Immediately after asking this question an idea came to my mind which worked out. In order to specify the timezone you can just set the usual linux environment variable TZ before building the PDF. As an example if you have a Makefile which builds it on running make you can set it like this: TZ='Europe/Zurich' make Or, of course, export it before running the build using export TZ='Europe/Zurich'.

Tags: latexmk (Prev Q)

1145

Boxes Questions Q: Value of LuaTeX’s \mathstyle in \frac (de)nominator Tags: boxes (Next Q) This was fixed in version from 2017/06/15 (available on CTAN). This is a followup question of How to transfer math style in \hbox_set?. While the code I posted there as an answer using LuaTeX’s \mathstyle primitive it doesn’t work inside of the (de)nominator of a \frac. If a \frac happens to appear in \textstyle the (de)nominator actually is set in \scriptstyle (as far as I can tell), but \mathstyle stell equals 2.

Skip code block % !TeX program = luatex \documentclass{article} \usepackage{parskip,xparse,xcolor} \usepackage{amsmath,lualatex-math} 1146

\ExplSyntaxOn\makeatletter

\cs_new:Npn \tobi_save_math_style: { \int_case:nn { \mathstyle } { { \displaystyle } { \tl_set:Nn \l_tobi_saved_math_style_tl { \displaystyle } { \textstyle } { \tl_set:Nn \l_tobi_saved_math_style_tl { \textstyle } } { \scriptstyle } { \tl_set:Nn \l_tobi_saved_math_style_tl { \scriptstyle } } { \scriptscriptstyle } { \tl_set:Nn \l_tobi_saved_math_style_tl { \scriptscr } }

\NewDocumentCommand { \boxtest }{ m }{ \mode_if_math:TF { % aktuellen Mathemodus ermitteln und für später sichen \tobi_save_math_style: % Box mit entsprechender Formel speichern \hbox_gset:Nn \l_tmpa_box { \begingroup \( \[email protected] \tl_use:N \l_tobi_saved_math_style_tl #1 \) \endgroup } } { \hbox_set:Nn \l_tmpa_box { #1 } } \fbox { \box_use:N \l_tmpa_box } [\tl_to_str:n { \mathstyle } = \mathstyle; saved style = \tl_to_str:N \l_tobi_s } \cs_new:Npn \tobi_genfrac:nnnn #1#2#3#4 { % \colorlet { l_tobi_current_color_before_frac } { . } % \begingroup % \color { #2 } \genfrac { } { } { } { #1 } { 1147

%

\color { l_tobi_current_color_before_frac } #3 } {

%

% }

\color { l_tobi_current_color_before_frac } #4 } \endgroup

\RenewDocumentCommand { \frac } { O{.} m m } { \tobi_genfrac:nnnn { } { #1 } { #2 } { #3 } } \makeatother\ExplSyntaxOff \begin{document} OK: $a^2 = a^{\boxtest{2}}$ OK: $\displaystyle \frac{1}{2} = \frac{\boxtest{1}}{2}$ OK: $\frac{1}{2} = \boxtest{\frac{1}{2}}$ OK: $\displaystyle \frac{1}{2} = \boxtest{\frac{1}{2}}$ wrong: $\frac{1}{2} \neq \frac{\boxtest{1}}{2}$ wrong: $\genfrac{}{}{}{}{1}{2} \neq \genfrac{}{}{}{}{\boxtest{1}}{2}$ \end{document} So … is it possible to capture the correct style in this case too? Update: I added an example using \genfrac, which is used in my real document do get a coloured fraction line. Tags: boxes (Next Q) User: tobi

1148

Answer by david-carlisle \frac{a}{b} is essentially {a \over b} and the big problem with the infix \over is that it makes tracking the current style hard luatex does not change that. to get a version in which \mathstyle is set you need \Ustack{a \over b} so in latex you would have to redefine \frac and related commands to use \Ustack. One possibility would be to load lualatex-math which redefines \frac in this way.

Tags: boxes (Next Q)

Q: write the content of an hbox in an auxilary file Tags: boxes (Prev Q) (Next Q) I know that TeX can’t write the content of hbox in an auxiliary file (Re-parse the content of a box register). That mean tha