0

I want to make each block with a question in minipage.

When creating a minipage in function printall I get an error: Extra \endgroup. \print, Too many }'s. \print ....

How to fix it?

MWE:

% !TeX program = lualatex
% !TeX encoding = utf-8
%============================================================================================
\documentclass[14pt]{extarticle}
\usepackage{polyglossia}
%==========================================================
\usepackage{amsmath,amssymb}
\usepackage{unicode-math}
%==========================================================
\setdefaultlanguage[spelling=modern]{russian}
\setotherlanguage{english}
\defaultfontfeatures{Ligatures={TeX}}
\setmainfont{Times New Roman}
\newfontfamily{\cyrillicfont}{Times New Roman}
\setsansfont{Arial}
\newfontfamily{\cyrillicfontsf}{Arial}
\setmonofont{Courier New}
\newfontfamily\cyrillicfonttt[Script=Cyrillic]{Courier New}
%==========================================================
\usepackage[tracking=true]{microtype}
\microtypecontext{kerning=russian}
\usepackage{graphicx}
\usepackage{xcolor}
\usepackage{hyperref}
\hypersetup{%
    pdfencoding=auto
}
\usepackage[a4paper, left=25mm, right=20mm, top=20mm, bottom=20mm]{geometry}
\usepackage{indentfirst}
\usepackage{luacode}
%==========================================================
\begin{luacode*}
function createtbl()
    tbl=tbl or {}
    table.insert(tbl, {q="Какое из свойств \\textbf{реляционной алгебры} представлено далее?\\par \\begin{equation*} \\begin{aligned}U(U(R, S), T) &\\rightarrow U(R, U(S, T)) \\\\ CP(CP(R, S), T) &\\rightarrow CP(R, CP(S, T)) \\\\ J_{F_2}(J_{F_1}(R, S), T)&\\rightarrow J_{F_1}(R, J_{F_2}(S, T)) \\end{aligned} \\end{equation*}",
    a=2,
    [1]="{=1}~Коммутативность",
    [2]="{=2}~Ассоциативность бинарных операций",
    [3]="{=3}~Идемпотентность унарных операций",
    [4]="{=4}~Дистрибутивность бинарных операций между бинарными",
    [5]="{=5}~Факторизация унарных операций"
    })

    table.insert(tbl, {q="С помощью какого тега в \\textbf{XML} объявляют пространства имен?",
    a=1,
    [1]="{=1}~xmlns",
    [2]="{=2}~xhtml",
    [3]="{=3}~xmlds",
    [4]="{=4}~xslns"
    })
    tex.print("\\newcommand{\\nvopr}{" .. #tbl .. "}")
end

function printall(arr)
    local ans = "["
--  tex.print("\\medskip\\noindent\\hrule height 1pt\\medskip")
    tex.print("\\noindent\\fbox{\\begin{minipage}[c]{\\dimexpr\\linewidth-1ex\\relax}")
    for i,n in ipairs(arr) do
        ans = ans .. n.a .. ","
        tex.print("\\noindent", i .. ".", n.q, "\\par")
        tex.print("\\begin{Form}")
        for j = 1, #n do
            local s = "\\ChoiceMenu[radio, borderwidth=0.5pt, bordercolor=black, radiosymbol=\\ding{52}, name=button" .. i .. "]{}" .. n[j]
            if j == #n then s = s .. ".\\par"
            else s = s .. ";\\par"
            end
            tex.print(s)
        end
        tex.print("\\end{Form}")
        tex.print("\\end{minipage}}")
--      tex.print("\\medskip\\noindent\\hrule height 1pt\\medskip")
    end
    ans = ans:sub(1, ans:len()-1) .. "]"
    tex.print("\\newcommand{\\answer}{" .. ans .. "}")
end
\end{luacode*}
%==========================================================
\def\print{\directlua{printall(tbl)}}
\makeatletter
\def\DefaultHeightofChoiceMenu{3mm}
\def\DefaultWidthofChoiceMenu{4mm}
\makeatother
\begin{document}
%==========================================================
\directlua{createtbl()}
\print
\centerline{\textcolor{red}{minipage works:}}
\noindent\fbox{\begin{minipage}[c]{\dimexpr\linewidth-1ex\relax}
1111\par
1223\\
12232
\end{minipage}}
%==========================================================
\end{document}

Result with an error:

enter image description here

2
  • unrelated but don't use the Form environment more than once in a document. Actually a simple \Form at the begin is enough to initialize everything. Beside this I suggest that you minimize your document, e.g. it shouldn't load lots of fonts no present on all system. And don't use pdfencoding=auto, that is the wrong encoding for luatex. Commented Jan 11, 2023 at 10:29
  • Fixed: \begin{Form} \print \end{Form} and removed from the function. minipage doesn't work! I'll remove the extra fonts later. Thanks @Ulrike Fischer.
    – Youra_P
    Commented Jan 11, 2023 at 10:40

1 Answer 1

0

If you change the tex.print to print in your main function, so you see what it is writing you see

\noindent
\fbox{\begin{minipage}[c]{\dimexpr\linewidth-1ex\relax}
\noindent
1.      Какое из свойств \textbf{реляционной алгебры} представлено далее?\par
\begin{equation*} \begin{aligned}U(U(R, S), T) &\rightarrow U(R, U(S, T)) \\ CP(CP(R, S), T) &\rightarrow CP(R, CP(S, T)) \\ J_{F_2}(J_{F_1}(R, S), T)&\rightarrow J_{F_1}(R, J_{F_2}(S, T)) \end{aligned}
\end{equation*}\par
\begin{Form}
\end{Form}
\end{minipage}}
\noindent       2.      С помощью какого тега в \textbf{XML} объявляют пространства имен?       \par
\begin{Form}
\end{Form}
\end{minipage}}
\newcommand{\answer}{[2,1]}

so you start one minipage but end two, hence the error.

I suspect you intended

tex.print("\\end{minipage}}

to be after the end, so outside the loop.

4
  • I didn't know how to view the generated code. I typed it into a file and saw an error. Thank you for your help, @David Carlisle.
    – Youra_P
    Commented Jan 11, 2023 at 11:02
  • Where does print output to? @David Carlisle.
    – Youra_P
    Commented Jan 11, 2023 at 11:19
  • 1
    the terminal (not log) you can use texio.write to print to the log if you prefer @Youra_P Commented Jan 11, 2023 at 11:34
  • Thank, @David Carlisle.
    – Youra_P
    Commented Jan 11, 2023 at 14:37

You must log in to answer this question.

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