How can use \sec and \secc from inside another macro definition in Opmac

Can anyone point me in the right direction? I need to wrap up basically the entire content of an article in a macro definition(this is how user passes it into my template), which contains references \sec and \secc. For some reason when I use those macros inside another \def, it fails with a cryptic: "Paragraph ended before \eoldefA was complete."

\input opmac

\def\fails{
\sec Test 2

Some Text
}

\fails

\sec Test 1
This is Okay

\end


Output:

This is pdfTeX, Version 3.14159265-2.6-1.40.19 (TeX Live 2018/W32TeX) (preloaded format=pdftex)
restricted \write18 enabled.
entering extended mode
(./test.tex (./opmac.tex
This is OPmac (Olsak's Plain macros), version <Mar. 2018a>
(c:/texlive/2018/texmf-dist/tex/csplain/fonts/ams-math.tex
FONT: AMS math fonts - \mathchardef's prepared, 12 math families preloaded.)
OPmac: etex.src macros detected)
Runaway argument?
Test 2
! **Paragraph ended before \eoldefA was complete.**
\par
\fails -> \sec Test 2 \par
Some Text
l.9 \fails


You simply can't use \sec in the argument to another command, because it relies on delimiting the title with the end-of-line character inserted by TeX, but when you embed the code in a macro, the end-of-line gets converted to a space.

In my opinion this is a bad decision, because the code is quite fragile; much better it would be delimiting the title with \par (which requires the user to leave a blank line after the section title.

Workaround:

\input opmac

\expandafter\let\expandafter\isec\csname\string\sec:M\endcsname

\def\fails{
\isec{Test 2}

Some Text
}

\fails

\sec Test 1
This is Okay

\end


• Thanks a bundle guys, I was really stuck on this! This way looks very clean to type too. – vlsh Dec 7 '19 at 2:59

What's happening is that opmac is doing some funky stuff with character codes to allow the \sec command to terminate its argument with a blank line. If you want to know more you’ll need to study the chapters of the TeXbook that talk about how TeX's “digestive” process works (not sure how deep into TeX programming you are or are willing to get). How much control do you have over how the input is coming into your template and what are your more global needs?

• I have all the control, I'm just trying to make it simpler for non-computer people at our factory to write procedure manuals. I don't want anything "complex" to show up in the file they are editing, they don't need to know how I render title page, bill of materials, etc. Anyway, I'd be willing to fix up \sec if I have to, I saw it switches charcodes, but didn't understand why. – vlsh Dec 6 '19 at 11:16

This problem is described on page 16 of opmac-d.pdf document, where the solution is suggested:

\def\mymacro#1{... \csname\string\sec:M\endcsname{#1} ...}


\def\fails

You can see another very similar solution using \bracedparam macro from OPmac trick 0036.
• @egreg Your solution includes 39 more characters in source code than mine. So, it is problematic to say that it is more difficult to type. Of course, if somebody needs to use \sec in his/her macro more than once then he/she can define new macro, this is obvious. For example \def\mysec{\csname\string\sec:M\endcsname}. – wipet Dec 7 '19 at 5:21