2

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.**
<to be read again>
                   \par
\fails -> \sec Test 2 \par
                           Some Text
l.9 \fails
4

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

enter image description here

| improve this answer | |
  • 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
2

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?

| improve this answer | |
  • 1
    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
2

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} ...}

Or, in your code:

\def\fails
   \csname\string\sec:M\endcsname{Test 2}
   Some Text
}

You can see another very similar solution using \bracedparam macro from OPmac trick 0036.

| improve this answer | |
  • Which is the same solution I proposed, only more difficult to type. – egreg Dec 6 '19 at 22:02
  • No wonder I didn't see it, that manual is in czech! – vlsh Dec 7 '19 at 2:42
  • @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

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.