Am 10.09.2010 um 10:05 schrieb Cecil Westerhof:
I am learning to work with ConTeXt. At the moment I have the following defined:
I guess we need a context programmers guide.
\newdimen\CheckBoxMargin \CheckBoxMargin=2em \newdimen\CheckBoxWidth \CheckBoxWidth=2.5em \newdimen\CheckBoxDistance \CheckBoxDistance=.5em
Get rid of this stuff and use a setup command: \def\setupCheckBox {\dodoubleargument\getrawparameters[CheckBox]} \setupCheckBox [Margin=2em, Width=2.5em, Distance=.5em]
\definesymbol[CheckBox][{[~~~]}] \def\startcheckbox[#1]{ \blank \leftaligned{#1} \startitemize[packed, intro, joinedup][margin=\CheckBoxMargin, symbol=CheckBox, width=\CheckBoxWidth, distance=\CheckBoxDistance] }
\def\stopcheckbox{ \stopitemize \blank \crlf }
Brr, latex style. Why \crlf at the end of \stopcheckbox, to get a bigger space use \blank[...].
\def\GetNiveauOfService[#1]{ \blank #1 {\switchtobodyfont[0.5em](1 = low, 9 = high)} \startitemize[packed, intro, joinedup, columns][n=9, symbol=CheckBox, width=\CheckBoxWidth, distance=\CheckBoxDistance] \dorecurse{9}{ \item \recurselevel } \stopcheckbox }
\def\GetNiveauOfService {\dodoubleempty\doGetNiveauOfService} \def\doGetNiveauOfService[#1][#2]% {\blank #1 {\switchtobodyfont[0.5em]\doifsomethingelse{#2}{#2}{(1 = \translate[en=low,nl=weinig], 9 = \translate[en=high,nl=veel])}} \startitemize[packed,intro,joinedup,columns][n=9,symbol=CheckBox, width=\CheckBoxWidth,distance=\CheckBoxDistance] \dorecurse{9}{\item \recurselevel} \stopitemize}
I have a few questions about this.
In GetNiveauOfService 9 is used three times. I like DRY, so I was wondering if there would be a better way to do this?
??? (Note: I switched your following two questions)
Lastly, in GetNiveauOfService there is text. How can I make this language dependent. For example in English I want: (1 = low, 9 = high) but in Dutch: (1 = weinig, 9 = veel) and properly it would be a good idea to have two optional parameters when you want other descriptions. How would I do this?
See my version of the command, there is a second optional argument which can be used to set a alternative text.
Next step would be that the number of checkboxes could be a parameter. The default would be nine and if given, the given value would be used. How would I do this?
Then the 'normal' checkboxes. The default is one column. But I would like to have the possibility to use a parameter to for example make checkboxes in three columns. How would I do this?
For the last question i showed you how you can use a optional parameter to set alternative text but as you want more and more parameter you should first think about the interface for you commands (e.g. key-value makes more sense than lots of text arguments because you can’t make all of them optional in this case. Wolfgang