0

Using the answer at How to let users type in clozes in PDF?, I was able to create a cloze document where users type in the fill-in-the-blanks in a PDF. I used the code in a macro, so it calls the same \field[cloze] multiple times.

\setupinteraction[state=start]

\definefield[cloze][line]

\starttext

Frogs have four \field[cloze] and two eyes.
Frogs have four \field[cloze] and two eyes.
Frogs have four \field[cloze] and two eyes.
Frogs have four \field[cloze] and two eyes.

\stoptext

<<-- Try typing in one field and it copies to the other fields.

The problem is when users fill in the first cloze, Adobe Acrobat automatically fills in all of the other clozes with the exact same value. I need the user to type different values in.

\setupinteraction[state=start]

\definefield[cloze1][line]
\definefield[cloze2][line]
\definefield[cloze3][line]
\definefield[cloze4][line]

\starttext

Frogs have four \field[cloze1] and two eyes.
Frogs have four \field[cloze2] and two eyes.
Frogs have four \field[cloze3] and two eyes.
Frogs have four \field[cloze4] and two eyes.

\stoptext

<<-- Try typing in one field and it no longer copies to the other fields.

Now the solution in a Minimal Working Answer is to change \field[cloze] to have different names for each cloze, such as \field[tree] and \field[mountain], the problem is, I'm using it embedded within some complex macros. I tried using \field[#1] to send a different value, and \field[\expanded[#1]] and \field[\randomnumber{0}{10000000}], \def\somevalue{\randomnumber{0}{10000000}}\field{\expanded{somevalue}}, etc. and many many other combinations of code, but everything I attempt fails to compile. Due to it being deep in many layers of macros, I can't manually chane \field[cloze] to other values.

How can I use the code from the answer, but in a way that each cloze is a place where users can type a unique value, and that value doesn't get automatically copies to every cloze?

3
  • \field{\expanded{somevalue}} won't do anything. You need something like \expanded{\field[\somevalue]}. Commented Aug 26, 2020 at 2:42
  • BTW, that seems to be an Acrobat-specific problem, because Evince does not autofill all the fields. Commented Aug 26, 2020 at 2:46
  • 1
    @HenriMenke This is only implemented by Acrobat and Chromium's PDF viewer I think, but it is specified in the PDF spec: If multiple fields have the same (fully qualified) name, they are different representations of the same underlying field and have no independent value. Commented Aug 26, 2020 at 2:59

1 Answer 1

3

You don't need expanded, ConTeXt expands the name anyway. Also I would recommend a gloabl counter instead of a random value. That makes the document more reproducible and reliable.

\setupinteraction[state=start]

\newcount\clozecount
\def\mycloze{%
  \global \advance \clozecount by 1
  \definefield[uniqcloze\the\clozecount][line]%
  \field[uniqcloze\the\clozecount]%
}

\starttext

Frogs have four \mycloze\ and two eyes.
Frogs have four \mycloze\ and two eyes.
Frogs have four \mycloze\ and two eyes.
Frogs have four \mycloze\ and two eyes.

\stoptext

You must log in to answer this question.

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