0

I am including the LuaTeX into an Overleaf LaTeX document by

\usepackage{arxiv}
\usepackage[T1]{fontenc}    % use 8-bit T1 fonts
\usepackage{hyperref}       % hyperlinks
\hypersetup{
    colorlinks=true,
    linkcolor=blue,
    filecolor=magenta,      
    urlcolor=cyan,
    pdftitle={Sharelatex Example},
    pdfpagemode=FullScreen,
}
\usepackage{url}            % simple URL typesetting
\usepackage{booktabs}       % professional-quality tables
\usepackage{amsfonts}       % blackboard math symbols
\usepackage{nicefrac}       % compact symbols for 1/2, etc.
\usepackage{microtype}      % microtypography

\usepackage[english]{babel} \usepackage[utf8]{inputenc} \usepackage{amsmath} \usepackage{amsthm} \usepackage{multirow,tabularx} \usepackage{luacode} \usepackage{graphicx} \usepackage[colorinlistoftodos]{todonotes}

but encountered the following error message:

Package luacode Error: /usr/local/texlive/2017/texmf-dist/tex/lualatex/luacode/luacode.sty, line 51 LuaTeX is required for this package. Aborting..

See the luacode package documentation for explanation. Type H for immediate help. ...

l.51 to prevent additional errors.} This package can only be used with the LuaTeX engine (command `lualatex'). Package loading has been stopped to prevent additional errors.

What is the remedy?

Hans
  • 115
  • 1
    It looks like you are trying to compile the file with pdfTeX instead of luaTeX. – campa Aug 07 '20 at 13:19
  • 3
    You need to change your compiler to LuaLaTeX, see https://www.overleaf.com/learn/how-to/Changing_compiler for how to do that. Note that since Lua(La)TeX handles fonts very differently from pdf(La)TeX there are a few packages you should not load with LuaLaTeX (cf. https://tex.stackexchange.com/q/28642/35864, some of the advice there is outdated, babel for example works fine with modern LuaLaTeX): Do not load inputenc and fontenc with LuaLaTeX. – moewe Aug 07 '20 at 13:23
  • 2
    With LuaLaTeX you'll want to drop \usepackage[T1]{fontenc} and \usepackage[utf8]{inputenc}. No matter what compiler you use you should make sure that hyperref is the last package you load (save for a few exceptions). There is little point in loading \usepackage{url} if you also load \usepackage{hyperref} (since the latter loads the former), especially if you do it after loading hyperref. (These hints won't help with the error message you posted, but they are still relevant for your document.) – moewe Aug 07 '20 at 13:33
  • @moewe: Thank you. Changing to LuaLaTeX helped. But dropping '\usepackage[T1]{fontenc}' generated hundreds of warnings like Package microtype Warning: Unknown slot number of character \r A' in font encodingTU' in inheritance list `microtype.cfg/358(protrusion)'. and it lost the styles for the large and bold font for section titles. – Hans Aug 07 '20 at 13:40
  • As I said, the way fonts are handled in pdf(La)TeX and Lua(La)TeX is quite different. So it may not be enough to just drop \usepackage[T1]{fontenc}. See for example https://tex.stackexchange.com/q/243482/35864. In any case \usepackage[T1]{fontenc} is detrimental with LuaLaTeX as explained in https://tex.stackexchange.com/q/470976/35864 (compile `\documentclass[ngerman]{article} \usepackage[T1]{fontenc}

    \begin{document} Grüße \end{document}` with LuaLaTeX to see a very obvious problem)

    – moewe Aug 07 '20 at 13:47
  • @moewe: OK. I have replaced 'fontenc' with 'fontspec' and it works. Thank you. – Hans Aug 07 '20 at 13:54

1 Answers1

2

If you want to use luacode you need to compile your document with LuaLaTeX (and not with pdfLaTeX, which is probably the standard in most editors, or XeLaTeX).

See https://www.overleaf.com/learn/how-to/Changing_compiler for how to do that on Overleaf.


Note that pdf(La)TeX and Lua(La)TeX handle fonts very differently, that means that you may have to change a few things in your preamble when you switch to LuaLaTeX. (Cf. also Frequently loaded packages: Differences between pdfLaTeX and LuaLaTeX)

In particular

\usepackage[T1]{fontenc}

and

\usepackage[utf8]{inputenc}

should not be loaded with LuaLaTeX. Instead most people will load

\usepackage{fontspec}

See Switching to lualatex: How to translate font setups? and Are there cases where fontenc + luatex (or xetex) cause problems? for details and background.

moewe
  • 175,683