TransWikia.com

How to create unique clozes in ConTeXt in a PDF that users can type in?

TeX - LaTeX Asked on November 29, 2020

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}], defsomevalue{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?

One Answer

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]

newcountclozecount
defmycloze{%
  global advance clozecount by 1
  definefield[uniqclozetheclozecount][line]%
  field[uniqclozetheclozecount]%
}

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

Correct answer by Marcel Krüger on November 29, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP