2

In this MWE,

\RequirePackage{luatex85}
\documentclass{elsarticle}
\usepackage[tuenc]{fontspec}
\usepackage{todonotes,etoolbox}

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

\newtoggle{ownerdefault}


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

\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")}}{}

\begin{document}

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

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

    text
\end{document}

the code compiles if I suppress this part:

\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")}}{}

I got a warning:

Shell escape feature is not enabled.

despite enabling shell-escape.

There are also many errors showing up such as:

Missing number, treated as zero. \ifnum\pdf@shellescape>

Missing number, treated as zero. \or

Font \TU/lmr/m/n/7=[lmroman7-regular]:+tlig; at 7pt not loadable: metric data not found or bad. \section*{Reviewer #1 Comments}

Font \OML/cmm/m/it/10=cmmi10 at 10pt not loadable: metric data not found or bad. \section*{Reviewer #1 Comments}

Font \OMS/cmsy/m/n/10=cmsy10 at 10pt not loadable: metric data not found or bad. \section*{Reviewer #1 Comments}

Font \OMX/cmex/m/n/5=cmex10 not loadable: metric data not found or bad. \section*{Reviewer #1 Comments}

Font \OT1/cmr/m/n/7=cmr7 at 7pt not loadable: metric data not found or bad. \section*{Reviewer #1 Comments}


Update

Unfortunately, this code throws the same errors

\RequirePackage{luatex85,shellesc}

\documentclass{elsarticle}

\setlength\marginparwidth{0.8\dimexpr(\paperwidth - \textwidth)/2\relax}
\usepackage{etoolbox,lipsum}
\usepackage[textwidth=\marginparwidth]{todonotes}

\usepackage[tuenc]{fontspec}

\makeatletter
\def\pdf@shellescape{\directlua{tex.sprint(status.shell_escape .. " ")}}
\makeatother


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

\newtoggle{ownerdefault}
\newtoggle{ownerB}


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

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

\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

\directlua{
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") 
zz=io.output() 
io.output(file) 
for i, l in ipairs(lines) do io.write(l, "\string\n") 
end
io.close(file)
io.output(zz)
end 
}

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

\usepackage[hidelinks,colorlinks=false,bookmarks=true]{hyperref}
\usepackage[numbered]{bookmark}

\begin{document}

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

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

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

    \makeatletter \@starttoc{tdo}\makeatother
    \clearpage
    \pagenumbering{arabic}

    \stR{2nd}{comment}
    \lipsum[1-5]
    \stR{1st}{comment}
    \lipsum[1-5]
    \ndR{1st}{comment}

\end{document}

1 Answer 1

1

If I make a more reasonable minimal example I get the same error unless I restore the default output stream (the lines with zz in the lua below). Thanks to Ulrike and wilx in chat)

\RequirePackage{luatex85,shellesc}

\documentclass{article}

\usepackage{todonotes}

\makeatletter

\def\pdf@shellescape{\directlua{tex.sprint(status.shell_escape .. " ")}}

\makeatother


\directlua{
    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") 
    zz=io.output() 
    io.output(file) 
    for i, l in ipairs(lines) do io.write(l, "\string\n") 
    end
    io.close(file)
    io.output(zz)
    end 
}

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

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

    text
\end{document}
3
  • Kindly, take a look at my update. I have extended your working answer to resemble my own case, but it fails.
    – Diaa
    Commented Feb 20, 2017 at 23:15
  • @DiaaAbidou on the updated example in your question I get /tex/luatex/luaotfload/fontloader-2017-02-11.lua:10494: attempt to cal l field 'suffix' (a nil value). <to be read again> sorry stopping today, will look later Commented Feb 20, 2017 at 23:20
  • No problem. Thanks for your consideration and have a nice night :)
    – Diaa
    Commented Feb 20, 2017 at 23:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .