0

Everything was working fine in my main document before trying to embed this answer in my code. However, I don't quite understand the steps needed to resolve this according to this solution.

The error message is

Font \TU/LatinModernRoman(0)/bx/n/10=LatinModernRoman/B:mode=node;script=latn;language=DFLT;+tlig;-liga; at 10pt not loadable: metric data not found or bad. \section*{Editor Comment}

P.S. I am compiling on Win 10 using MikTeX 2.9.

\documentclass{elsarticle}

\usepackage{mathtools}
\usepackage[tuenc,no-math]{fontspec}
\usepackage[bold-style=TeX]{unicode-math}
\setmathfont[math-style=ISO]{Cambria Math}
\setmainfont[
Ligatures={NoRequired,
    NoCommon,
    NoContextual}
]{Latin Modern Roman}


\usepackage[hidelinks,colorlinks=false,bookmarks=true]{hyperref}
\usepackage[numbered]{bookmark}
\biboptions{square,numbers,sort&compress}
\setlength\marginparwidth{0.8\dimexpr(\paperwidth - \textwidth)/2\relax}
\usepackage[textwidth=\marginparwidth]{todonotes}


\usepackage{etoolbox}

\makeatletter
\newcommand\@todonotes@owner{default}
\define@key{todonotes}%
{owner}{\def\@todonotes@owner{#1}}


\newtoggle{ownerdefault}
\newtoggle{ownerB}
\newtoggle{ownerEditor}


\newcommand\stR[2]{% 1st reviewer comment
    \todo[%
    owner=default,
    author=Reviewer \#1,noline,caption={#1 Comment},color=blue!20%
    ]%
    {#1 Comment}{\color{blue}{\bfseries#2}}}

\newcommand\ndR[2]{% 2nd reviewer comment
    \todo[%
    owner=B,
    author=Reviewer \#2,noline,caption={#1 Comment},color=red!50!white%
    ]%
    {#1 Comment}{\color{red}{\bfseries#2}}}

\newcommand\stEditor[2]{% editor comment
    \todo[%
    owner=Editor,
    author=Editor,noline,caption={#1 Comment},color=red!50!white% color of margin note
    ]%
    {#1 Comment}{\color{red}{\bfseries#2}}}% color of comment text


\renewcommand{\@todonotes@addElementToListOfTodos}{%
    \if@todonotes@colorinlistoftodos%
    \addtocontents{tdo}
    {%
        \protect\iftoggle{owner\@todonotes@owner}
        {%
            \protect\contentsline {todo}
            {\protect\fcolorbox{\@todonotes@currentbordercolor}%
                {\@todonotes@currentbackgroundcolor}%
                {\protect\textcolor{\@todonotes@currentbackgroundcolor}{o}}%
                \ \@todonotes@caption
            }{\thepage}{\@currentHref}%
        }{}%
    }%
    \else%
    \addtocontents{tdo}
    {%
        \protect\iftoggle{owner\@todonotes@owner}
        {%
            \protect\contentsline {todo}
            {\@todonotes@caption
            }{\thepage}{\@currentHref}%
        }{}%
    }%
    \fi}%

\makeatother
\usepackage{luacode}

\begin{luacode*}
    function sort_tdo (jobname)
    local lines = {}
    -- read the lines in table 'lines'
    for line in io.lines(jobname) do
    table.insert(lines, line)
    end
    -- sort
    table.sort(lines)
    -- write all the lines
    file=io.open(jobname.."sorted", "w") 
    io.output(file) 
    for i, l in ipairs(lines) do io.write(l, "\n") 
    end
    io.close(file)
    end 
\end{luacode*}

\IfFileExists{\jobname.tdo}{\directlua{sort_tdo("\jobname.tdo")}}{}

\makeatletter
\newcommand*{\sectionbookmark}[1][]{%
    \bookmark[%
    level=section,%
    dest=\@currentHref,%
    #1%
    ]%
}
\makeatother


\begin{document}

\pagenumbering{gobble}% Remove page numbers (and reset to 1)
\clearpage
\thispagestyle{empty}




\toggletrue{ownerEditor}
\section*{Editor Comment}
\sectionbookmark{Editor Comment}
\InputIfFileExists{\jobname.tdosorted}{}

\toggletrue{ownerdefault}
\togglefalse{ownerEditor}
\section*{Reviewer \#1 Comments}
\sectionbookmark{Reviewer \#1 Comments}
\InputIfFileExists{\jobname.tdosorted}{}

\toggletrue{ownerB}
\togglefalse{ownerdefault}
\section*{Reviewer \#2 Comments}
\sectionbookmark{Reviewer \#2 Comments}
\InputIfFileExists{\jobname.tdosorted}{}

\togglefalse{ownerB}
\makeatletter \@starttoc{tdo}\makeatother % to trigger the creation of the list

\clearpage
\pagenumbering{arabic}

\stR{1st}{reviewer} some text

\stEditor{1st}{editor} some text

\end{document}
2

In LuaLaTeX, the global variable file is used to access the file library from lualibs. You code changes file, therefore the library can no longer be accessed which breaks luaotfload.

You can fix this by making file local:

Instead of

file=io.open(jobname.."sorted", "w")

write

local file=io.open(jobname.."sorted", "w")

Also your document changes Lua's default output files using io.output(...). That's also breaking all other Lua code trying to print to the terminal by using the default output. Instead, you can replace io.write by file:write.

This leads to the document:

\documentclass{elsarticle}

\usepackage{mathtools}
\usepackage[tuenc,no-math]{fontspec}
\usepackage[bold-style=TeX]{unicode-math}
\setmathfont[math-style=ISO]{Cambria Math}
\setmainfont[
Ligatures={NoRequired,
    NoCommon,
    NoContextual}
]{Latin Modern Roman}


\usepackage[hidelinks,colorlinks=false,bookmarks=true]{hyperref}
\usepackage[numbered]{bookmark}
\biboptions{square,numbers,sort&compress}
\setlength\marginparwidth{0.8\dimexpr(\paperwidth - \textwidth)/2\relax}
\usepackage[textwidth=\marginparwidth]{todonotes}


\usepackage{etoolbox}

\makeatletter
\newcommand\@todonotes@owner{default}
\define@key{todonotes}%
{owner}{\def\@todonotes@owner{#1}}


\newtoggle{ownerdefault}
\newtoggle{ownerB}
\newtoggle{ownerEditor}


\newcommand\stR[2]{% 1st reviewer comment
    \todo[%
    owner=default,
    author=Reviewer \#1,noline,caption={#1 Comment},color=blue!20%
    ]%
    {#1 Comment}{\color{blue}{\bfseries#2}}}

\newcommand\ndR[2]{% 2nd reviewer comment
    \todo[%
    owner=B,
    author=Reviewer \#2,noline,caption={#1 Comment},color=red!50!white%
    ]%
    {#1 Comment}{\color{red}{\bfseries#2}}}

\newcommand\stEditor[2]{% editor comment
    \todo[%
    owner=Editor,
    author=Editor,noline,caption={#1 Comment},color=red!50!white% color of margin note
    ]%
    {#1 Comment}{\color{red}{\bfseries#2}}}% color of comment text


\renewcommand{\@todonotes@addElementToListOfTodos}{%
    \if@todonotes@colorinlistoftodos%
    \addtocontents{tdo}
    {%
        \protect\iftoggle{owner\@todonotes@owner}
        {%
            \protect\contentsline {todo}
            {\protect\fcolorbox{\@todonotes@currentbordercolor}%
                {\@todonotes@currentbackgroundcolor}%
                {\protect\textcolor{\@todonotes@currentbackgroundcolor}{o}}%
                \ \@todonotes@caption
            }{\thepage}{\@currentHref}%
        }{}%
    }%
    \else%
    \addtocontents{tdo}
    {%
        \protect\iftoggle{owner\@todonotes@owner}
        {%
            \protect\contentsline {todo}
            {\@todonotes@caption
            }{\thepage}{\@currentHref}%
        }{}%
    }%
    \fi}%

\makeatother
\usepackage{luacode}

\begin{luacode*}
    function sort_tdo (jobname)
    local lines = {}
    -- read the lines in table 'lines'
    for line in io.lines(jobname) do
    table.insert(lines, line)
    end
    -- sort
    table.sort(lines)
    -- write all the lines
    local file=io.open(jobname.."sorted", "w") 
    for i, l in ipairs(lines) do file:write(l, "\n") 
    end
    file:close()
    end 
\end{luacode*}

\IfFileExists{\jobname.tdo}{\directlua{sort_tdo("\jobname.tdo")}}{}

\makeatletter
\newcommand*{\sectionbookmark}[1][]{%
    \bookmark[%
    level=section,%
    dest=\@currentHref,%
    #1%
    ]%
}
\makeatother


\begin{document}

\pagenumbering{gobble}% Remove page numbers (and reset to 1)
\clearpage
\thispagestyle{empty}




\toggletrue{ownerEditor}
\section*{Editor Comment}
\sectionbookmark{Editor Comment}
\InputIfFileExists{\jobname.tdosorted}{}

\toggletrue{ownerdefault}
\togglefalse{ownerEditor}
\section*{Reviewer \#1 Comments}
\sectionbookmark{Reviewer \#1 Comments}
\InputIfFileExists{\jobname.tdosorted}{}

\toggletrue{ownerB}
\togglefalse{ownerdefault}
\section*{Reviewer \#2 Comments}
\sectionbookmark{Reviewer \#2 Comments}
\InputIfFileExists{\jobname.tdosorted}{}

\togglefalse{ownerB}
\makeatletter \@starttoc{tdo}\makeatother % to trigger the creation of the list

\clearpage
\pagenumbering{arabic}

\stR{1st}{reviewer} some text

\stEditor{1st}{editor} some text

\end{document}
  • Many thanks for this great help. It would be great if you don't mind adding an answer to my previous question so that nobody would face this clash later. – Diaa Oct 7 at 14:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.