You can't use '\prevdepth' in restricted horizontal mode
Dear all, I got the error "You can't use '\prevdepth' in restricted horizontal mode” when I compile the following code. If I remove “\starttabulete… \stoptabulate”, then no errors, but the out put is not the form of table. How can I fix this error? Thank you. Best regards, Dalyoung \starttext \startluacode function makeHead(a) local n = #a context.HL() for i = 1, n do context.NC() context(a[i]) end context.NC()context.AR() context.HL() end \stopluacode %\starttabulate[|mcw(1cm)|mcw(1cm)|mcw(1cm)|mcw(1cm)|] \startluacode local a = {"x","y","z","(x\\to y)"} makeHead(a) \stopluacode %\stoptabulate \stoptext
Dear Dalyoung,
I am not sure what the issue is; but as a workaround it seems that using
\ctxlua works:
___________________________________________________
\starttext
\startluacode
function makeHead(a)
local n = #a
context.HL()
for i = 1, n do
context.NC() context(a[i])
end
context.NC()context.AR()
context.HL()
end
\stopluacode
\starttabulate[|mcw(1cm)|mcw(1cm)|mcw(1cm)|mcw(1cm)|]
\ctxlua{local a = {"x","y","z","(x\\to y)"}; makeHead(a)}
\stoptabulate
\stoptext
___________________________________________________
Cheers,
Florent
Le ven. 3 janv. 2025 à 15:58, Jeong Dal via ntg-context
Dear all,
I got the error "You can't use '\prevdepth' in restricted horizontal mode” when I compile the following code.
If I remove “\starttabulete… \stoptabulate”, then no errors, but the out put is not the form of table.
How can I fix this error?
Thank you.
Best regards,
Dalyoung
\starttext
\startluacode function makeHead(a) local n = #a context.HL() for i = 1, n do context.NC() context(a[i]) end context.NC()context.AR() context.HL() end \stopluacode
%\starttabulate[|mcw(1cm)|mcw(1cm)|mcw(1cm)|mcw(1cm)|] \startluacode local a = {"x","y","z","(x\\to y)"} makeHead(a) \stopluacode %\stoptabulate
\stoptext
___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki!
maillist : ntg-context@ntg.nl / https://mailman.ntg.nl/mailman3/lists/ntg-context.ntg.nl webpage : https://www.pragma-ade.nl / https://context.aanhet.net (mirror) archive : https://github.com/contextgarden/context wiki : https://wiki.contextgarden.net
___________________________________________________________________________________
Am 03.01.2025 um 16:53 schrieb Jeong Dal via ntg-context:
Dear all,
I got the error "You can't use '\prevdepth' in restricted horizontal mode” when I compile the following code.
If I remove “\starttabulete… \stoptabulate”, then no errors, but the out put is not the form of table.
How can I fix this error?
Thank you.
Best regards,
Dalyoung
\starttext
\startluacode function makeHead(a) local n = #a context.HL() for i = 1, n do context.NC() context(a[i]) end context.NC()context.AR() context.HL() end \stopluacode
%\starttabulate[|mcw(1cm)|mcw(1cm)|mcw(1cm)|mcw(1cm)|] \startluacode local a = {"x","y","z","(x\\to y)"} makeHead(a) \stopluacode %\stoptabulate
\stoptext
Move the tabulate environment into the luacode environment. \startluacode context.starttabulate{ "|mcw(1cm)|mcw(1cm)|mcw(1cm)|mcw(1cm)|" } local a = {"x","y","z","(x\\to y)"} makeHead(a) context.stoptabulate() \stopluacode Wolfgang
On 1/3/2025 4:53 PM, Jeong Dal via ntg-context wrote:
Dear all,
I got the error "You can't use '\prevdepth' in restricted horizontal mode” when I compile the following code.
If I remove “\starttabulete… \stoptabulate”, then no errors, but the out put is not the form of table.
How can I fix this error?
Thank you.
Best regards,
Dalyoung
\starttext
\startluacode function makeHead(a) local n = #a context.HL() for i = 1, n do context.NC() context(a[i]) end context.NC()context.AR() context.HL() end \stopluacode
%\starttabulate[|mcw(1cm)|mcw(1cm)|mcw(1cm)|mcw(1cm)|] \startluacode local a = {"x","y","z","(x\\to y)"} makeHead(a) \stopluacode %\stoptabulate
\stoptext
\starttext \startluacode function makeHead(p,a) if p == "" then p = string.rep("|k.5",#a) .. "|" end context.starttabulate { p } context.FL() for i=1,#a do context.NC() context(a[i]) end context.NC() context.NR() context.LL() context.stoptabulate() end \stopluacode \startluacode makeHead ( -- "|mcw(1cm)|mcw(1cm)|mcw(1cm)|mcw(2cm)|", "|mcw(1cm)|mcw(1cm)|mcw(1cm)|mcw(2cm)|", { "x", "y", "z", "(x\\to y)" } ) \stopluacode \startluacode makeHead ( "", { "x", "y", "z", "(x\\to y)" } ) \stopluacode \stoptext ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
Dear Florent, Wolfgang, and Hans, Thank you for the solutions. All solutions are working well. I add more rows for the last solution to show the truth table of a logical function. I may modify it for 2-variable function. Thanks again. Best regards, Dalyoung \starttext \startluacode function document.logicFa(p,q,r) local p,q,r if ((p or r) and (not q)) then return "1" else return "0" end end function document.logicFb(p,q) local p,q if ((not p) or q) then return "1" else return "0" end end function document.MakeHead(p,a) if not a then local t = p p = string.rep("|mcw(1cm)",#p-1) .. "|mcw(1.5cm)|" a = t end context.starttabulate { p } context.FL() for i=1,#a do context.NC() context(a[i]) end context.NC() context.NR() context.LL() -- context.stoptabulate() end \stopluacode \startluacode a = { "x", "y","z", "\\overbar{y}(x+z)" } document.MakeHead (a) -- "|mcw(1cm)|mcw(1cm)|mcw(1cm)|mcw(2cm)|”, for i,p in ipairs({true,false}) do for j,q in ipairs({true,false}) do for k,r in ipairs({true,false}) do context.NC() if p then val=1 else val=0 end context(val) context.NC() if q then val=1 else val=0 end context(val) context.NC() if r then val=1 else val=0 end context(val) context.NC() con=document.logicFa(p,q,r) context(con) context.NC() context.AR() end end end context.HL() context.stoptabulate() \stopluacode \stoptext
Dear Florent, Wolfgang, and Hans, I modify the code given by Hans as following: 1. Place the function definition ab the beginning of the file. I use if function to check the number of element of a and apply it to the number of columns. 2. And call the functions in the text. It works! It draw the truth table of the given logic functions. Thanks a lot. Best regards, Dalyoung \startluacode function document.MakeHead(p,a) if not a then local t = p p = string.rep("|mcw(1cm)",#p-1) .. "|mcw(1.5cm)|" a = t end context.starttabulate { p } context.FL() for i=1,#a do context.NC() context(a[i]) end context.NC() context.NR() context.LL() end function document.truthTable(a) document.MakeHead (a) for i,s in ipairs({true,false}) do for j,t in ipairs({true,false}) do for k,u in ipairs({true,false}) do if s then val=1 else val=0 end context.NC() context(val) context.NC() if t then val=1 else val=0 end context(val) context.NC() if #a == 3 then break end if u then val=1 else val=0 end context(val) context.NC() con=document.logicFa(s,t,u) context(con) context.NC() context.AR() end if #a == 3 then con=document.logicF2(s,t) context(con) context.NC() context.AR() end end end context.HL() context.stoptabulate() end \stopluacode In the text call the functions as following: \startplacetable[location=here,reference=tbl:Fxyz] \startluacode function document.logicFa(p,q,r) if ((not p or not q) and r) or (p and (q or not r)) then return "1" else return "0" end end a = { "p", "q", "r","f(p,q,r)"} document.truthTable(a) \stopluacode \stopplacetable
On 1/4/2025 12:27 AM, Jeong Dal via ntg-context wrote:
Dear Florent, Wolfgang, and Hans,
I modify the code given by Hans as following:
1. Place the function definition ab the beginning of the file. I use if function to check the number of element of a and apply it to the number of columns.
2. And call the functions in the text.
It works! It draw the truth table of the given logic functions.
Thanks a lot.
Best regards,
Dalyoung
\startluacode function document.MakeHead(p,a) if not a then local t = p p = string.rep("|mcw(1cm)",#p-1) .. "|mcw(1.5cm)|" a = t end context.starttabulate { p } context.FL() for i=1,#a do context.NC() context(a[i]) end context.NC() context.NR() context.LL() end
function document.truthTable(a) document.MakeHead (a) for i,s in ipairs({true,false}) do for j,t in ipairs({true,false}) do for k,u in ipairs({true,false}) do if s then val=1 else val=0 end context.NC() context(val) context.NC() if t then val=1 else val=0 end context(val) context.NC() if #a == 3 then break end if u then val=1 else val=0 end context(val) context.NC() con=document.logicFa(s,t,u) context(con) context.NC() context.AR() end if #a == 3 then con=document.logicF2(s,t) context(con) context.NC() context.AR() end end end context.HL() context.stoptabulate() end \stopluacode
In the text call the functions as following:
\startplacetable[location=here,reference=tbl:Fxyz] \startluacode function document.logicFa(p,q,r) if ((not p or not q) and r) or (p and (q or not r)) then return "1" else return "0" end end a = { "p", "q", "r","f(p,q,r)"} document.truthTable(a) \stopluacode \stopplacetable
Best use 'local' for val, con, a etc or do this: \startluacode function document.MakeHead(p,a) if not a then local t = p p = string.rep("|mcw(1cm)",#p-1) .. "|mcw(1.5cm)|" a = t end context.starttabulate { p } context.FL() for i=1,#a do context.NC() context(a[i]) end context.NC() context.NR() context.LL() end function document.MakeFooter() context.HL() context.stoptabulate() end function document.truthTable(a) document.MakeHead(a) for i,s in ipairs({true,false}) do for j,t in ipairs({true,false}) do for k,u in ipairs({true,false}) do context.NC() context(s and "1" or "0") context.NC() context(t and "1" or "0") context.NC() if #a == 3 then break end context(u and "1" or "0") context.NC() context(document.logicFa(s,t,u)) context.NC() context.AR() end if #a == 3 then context(document.logicF2(s,t)) context.NC() context.AR() end end end document.MakeFooter() end \stopluacode \startplacetable[location=here,reference=tbl:Fxyz] \startluacode function document.logicFa(p,q,r) if ((not p or not q) and r) or (p and (q or not r)) then return "1" else return "0" end end document.truthTable { "p", "q", "r","f(p,q,r)" } \stopluacode \stopplacetable you don't need the intermediate variables Hans ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
On 1/3/2025 4:53 PM, Jeong Dal via ntg-context wrote:
Dear all,
I got the error "You can't use '\prevdepth' in restricted horizontal mode” when I compile the following code.
If I remove “\starttabulete… \stoptabulate”, then no errors, but the out put is not the form of table.
How can I fix this error?
Thank you.
Best regards,
Dalyoung
\starttext
\startluacode function makeHead(a) local n = #a context.HL() for i = 1, n do context.NC() context(a[i]) end context.NC()context.AR() context.HL() end \stopluacode
%\starttabulate[|mcw(1cm)|mcw(1cm)|mcw(1cm)|mcw(1cm)|] \startluacode local a = {"x","y","z","(x\\to y)"} makeHead(a) \stopluacode %\stoptabulate
\stoptext
or \starttext \startluacode function document.MakeHead(p,a) if not a then local t = p p = string.rep("|k.5",#p) .. "|" a = t end context.starttabulate { p } context.FL() for i=1,#a do context.NC() context(a[i]) end context.NC() context.NR() context.LL() context.stoptabulate() end \stopluacode \startluacode document.MakeHead ( "|mcw(1cm)|mcw(1cm)|mcw(1cm)|mcw(2cm)|", { "x", "y", "z", "(x \\to y)" } ) \stopluacode \startluacode document.MakeHead { "x", "y", "z", "(x \\to y)" } \stopluacode \stoptext ----------------------------------------------------------------- Hans Hagen | PRAGMA ADE Ridderstraat 27 | 8061 GH Hasselt | The Netherlands tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl -----------------------------------------------------------------
participants (5)
-
Florent Michel
-
Hans Hagen
-
Hans Hagen
-
Jeong Dal
-
Wolfgang Schuster