Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatting of solution environment #351

Closed
StefanFabian opened this issue Jan 19, 2022 · 11 comments
Closed

Formatting of solution environment #351

StefanFabian opened this issue Jan 19, 2022 · 11 comments
Assignees
Labels
customization wiki might be useful for others but not officially supported

Comments

@StefanFabian
Copy link

Is there an option to format how the solution environment looks?
E.g. a runin style like for the subtasks or an indentation of the solution block to differentiate it more clearly from the task descriptions.

@TeXhackse
Copy link
Collaborator

TeXhackse commented Jan 19, 2022

The solution environment so far only adds the contents after a header. The header layout can me modified by redefinition.

This behavior can be changed ofc.
currently a redefinition is quite complicated, because we overwrite the environment itself when switching solution=true/false.

How about if we add a ptxcd_solution (because the module this bundle contains to is named like that) environment which could be redefined by the user to whatever style they prefer.

Then you could add contents before/after the environment without affecting the switch mechanism.

@TeXhackse TeXhackse added customization enhancement New feature or request labels Jan 19, 2022
@TeXhackse
Copy link
Collaborator

TeXhackse commented Jan 19, 2022

I just made a rough draft, so if you insert the followiung into your preamble

\ExplSyntaxOn
\newenvironment{ptxcd_solution}{}{}

\cs_set:Nn \ptxcd_setup_solution: {
	\bool_if:NTF \l_ptxcd_ex_solution_bool {
		\cs_set:cpn {solution} {\ptxcd_solution\ptxcd_ex_solutionheader:}
		\cs_set_eq:cc {endsolution} {endptxcd_solution}
		\cs_set_eq:cc {solution*} {ptxcd_solution}
		\cs_set_eq:cc {endsolution*} {endptxcd_solution}
	}{
		\cs_set_eq:cc {solution} {\if_false:}
		\cs_set_eq:cc {endsolution} {\fi:}
		\cs_set_eq:cc {solution*} {\if_false:}
		\cs_set_eq:cc {endsolution*} {\fi:}
	}
}

\ptxcd_setup_solution: %< this one was added by the edit to init the default setting correctly
\ExplSyntaxOff

You can afterwards redefine the ptxcd_solution environment which will be used internally. E.g. to use a gray box:

\usepackage{tcolorbox}
\tcbuselibrary{breakable}
\renewtcolorbox{ptxcd_solution}{}

This does not affect the headers, because otherwise this feature would conflict the difference of solution and solution*

@StefanFabian
Copy link
Author

Thanks for the quick and thorough reply!
Unfortunately, your rough draft doesn't work for me.
I only see a colorbox if I use ptxcd_solution directly as an environment.

@TeXhackse
Copy link
Collaborator

Oh, if you don't switch the solution boolean later it won't be adjusted. I added \ptxcd_setup_solution: in the example above.

@StefanFabian
Copy link
Author

That solves the change not being applied but it also results in an error:

\begin{tcb@savebox} on input line 77 ended by \end{solution}.

Is there a reason why I shouldn't just use the IfSolutionTF command to renew the solution environment?

\usepackage{changepage}
\renewenvironment{solution}{\begin{adjustwidth}{2em}{0em}\textbf{Lösungsvorschlag:}}{\end{adjustwidth}}

@TeXhackse
Copy link
Collaborator

The \renewcommand will be overwritten by any change of the solution boolean.
This will only work if you enable/disable the boolean directly with the class options.

I messed something up with copying the example the following would probably do what you want to without changepage because it's not necessary to load an additional package:

\ExplSyntaxOn
\newenvironment{ptxcd_solution}{}{}

\cs_set:Nn \ptxcd_setup_solution: {
	\bool_if:NTF \l_ptxcd_ex_solution_bool {
		\cs_set:cpn {solution} {\csname ptxcd_solution\endcsname\ptxcd_ex_solutionheader:}
		\cs_set_eq:cc {endsolution} {endptxcd_solution}
		\cs_set_eq:cc {solution*} {ptxcd_solution}
		\cs_set_eq:cc {endsolution*} {endptxcd_solution}
	}{
		\RenewEnviron{solution}{
			\if_false:
			\BODY
			\fi:
		}
		\RenewEnviron{solution*}{
			\if_false:
			\BODY
			\fi:
		}
	}
}

\ptxcd_setup_solution:
\ExplSyntaxOff

\renewenvironment{ptxcd_solution}{\begin{addmargin}[2em]{0pt}}{\end{addmargin}}

@TeXhackse
Copy link
Collaborator

It It's not working please give me a minimal working example or send me the file via email and I will have a look, then something else is weird (marei@peitex.de)

@StefanFabian
Copy link
Author

I've set up a somewhat small example and invited you.
Thank you for your quick help!

@TeXhackse
Copy link
Collaborator

Alright, had a quick view you load some conflicting packages I will have a closer look during the afternoon it seems like it's a conflict not directly a TUDa-CI bug.

@TeXhackse
Copy link
Collaborator

Additionally it's indeed a bit weird I will have to dig a bit deeper into it.
The error is raised with nested environments, It can be resolved by doing the redefinition without the environment or as an environ (https://ctan.org/pkg/environ).

\renewenvironment{ptxcd_solution}{\addmargin[2em]{0pt}}{\endaddmargin}

or

\RenewEnviron{ptxcd_solution}{\begin{addmargin}[2em]{0pt}\BODY\end{addmargin}}

I will send you an email with some general remarks concerning the package configuration.

I will change the internal definition to an own environment so redefinition will be possible, this will make the change with \ptxcd_setup_solution: no longer necessary with the next update. Finanlly will resolve the open PR then as well.

@TeXhackse TeXhackse self-assigned this Jan 20, 2022
@TeXhackse
Copy link
Collaborator

Shame on me.

I forgot about the generic hooks. We don't need the internal environment at all, one could simply use

\AddToHook{env/solution/before}[solutionindent]{\begin{addmargin}[2em]{0pt}}
\AddToHook{env/solution/after} [solutionindent]{\end{addmargin}}

documentation of this can be found in texdoc lthooks-doc or the file on CTAN.

It requires a current TeX Live installation but simplifies this by a lot. I will try to find some time to write a bit more about this for the wiki.

@TeXhackse TeXhackse added wiki might be useful for others but not officially supported and removed enhancement New feature or request labels Jan 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customization wiki might be useful for others but not officially supported
Projects
None yet
Development

No branches or pull requests

2 participants