olsak / OpTeX

OpTeX - LuaTeX format with extended Plain TeX macros
http://petr.olsak.net/optex/
35 stars 14 forks source link

\printdoc does not handle TAB correctly #51

Closed robertbachmann closed 3 years ago

robertbachmann commented 3 years ago
  1. In doc.opm we currently don't have defintion for \t, causing an error when a ^^I is encountered
  2. Adding a simple defintion for \t fixes (1) but there is still a problem with reading \_doc lines that start with TAB

Test documents:

% main.tex
\load[doc]
\def\t{\ } % <- workaround
\printdoc sample
\bye
% sample.tex
\_codedecl{\foo}{...}

% next lines are indented with SPACES
    \_doc
    Here is a note. Lorem ipsum.
    \_cod

% next lines are indented with TAB
    \def\dummya{}

    \_doc
    Here is another note indented with tabs. Lorem ipsum.
    \_cod

\_endcode
\_endinput

The second \_doc is not processed correctly

image

olsak commented 3 years ago

The section 2.40, third paragraph, says, that \_doc must be preceded by two spaces. The reason is that \_doc should be somewhere in the code (for example \_def\_doc or \_def \_doc and we want to skip such occurrence and keep in the listing mode. Moreover, when OpTeX is in listing mode then space has active category. So, it is not simple to switch between space and ^^I. I will think about the possibility of using ^^I. But in this moment I don't see simple solution. And I don't want to add an obscure solution.

robertbachmann commented 3 years ago

Commit 2d93977 fixes my main problem.

Discovered this problem by accident. Most of my editors can be configured to insert TAB or spaces (when pressing TAB key). Edited a file with TeXworks, and TeXworks seems to always use TABs.

You can close the issue if you want.

olsak commented 3 years ago

You can re-define \_Doc after \load[doc]. For example

\edef\_Doc{\bslash _doc}

Now, all occurrences of \_doc starts documentation mode. You must not have any \_doc nor \_docsomething in your code in this case. Or, you can define

\bgroup \lccode\string`~=\string`\^^I
        \lowercase{\egroup\edef\_Doc{\noexpand~\_bslash _doc}}

Now, all occurrences of ^^I\_doc starts doc. mode. But not space\_doc. I can write something about this to the OpTeX tricks.

robertbachmann commented 3 years ago

I quickly tried out the following diff and it seems to work fine with sample.tex (Didn't do much testing yet)

diff --git a/optex/base/doc.opm b/optex/base/doc.opm
index 872797e..d56316c 100644
--- a/optex/base/doc.opm
+++ b/optex/base/doc.opm
@@ -58,12 +58,15 @@
    \_def\_tmpa{\_empty#1}%
    \_let\_next=\_readverbline
    \_ea\_isinlist\_ea\_tmpa\_ea{\_Doc}\_iftrue \_let\_next=\_processinput \_fi
+   \_ea\_isinlist\_ea\_tmpa\_ea{\_DocT}\_iftrue \_let\_next=\_processinput \_fi
    \_ea\_isinlist\_ea\_tmpa\_ea{\_Endcode}\_iftrue \_endinput \_let\_next=\_processinput \_fi
    \_ifx\_next\_readverbline \_addto\_tmpb{#1^^J}\_fi
    \_next
 }
 {\_catcode`\ =13 \_gdef\_aspace{ }}\_def\_asp{\_ea\_noexpand\_aspace}
 \_edef\_Doc{\_asp\_asp\_bslash _doc}
+\bgroup \lccode\string`~=\string`\^^I
+        \lowercase{\egroup\edef\_DocT{\noexpand~\_bslash _doc}}
 \_edef\_Endcode{\_noexpand\_empty\_bslash _endcode}

    \_doc -----------------------------