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

TeX capacity exceeded with custom points style and marginnote #86

Open
thorstengrothe opened this issue Nov 5, 2018 · 8 comments
Open
Labels
compatability Things that relate to other packages that is used together with exercisebank

Comments

@thorstengrothe
Copy link

I got this style defined for my points (needs \usepackage{marginnote}):

\makeatletter
\exercisebanksetup{%
	current points style={%
		\ifnum\exb@currentPoints=\z@%
		\ifnum\totalpoints=\z@%
		\else\phantom{0p}%
		\fi\else
		\marginnote{%
			\rule{1cm}{.5pt}
			\centering{}
			\exb@currentPoints~P.}%
		\fi\ignorespaces}}
\makeatother

with the latest prerelease this leads to an error:

TeX capacity exceeded, sorry [grouping levels=255]. \item A

For testing take the attached file and rename it to *.tex!
custom_points_error.txt

@Strauman
Copy link
Owner

Strauman commented Nov 5, 2018

The current points style is called inside a \leavevmode{\smash...} setup. That is at \At\PartProblemHeaderSuffix. I'm setting up a new hook \At\AfterPPHeader{POINT LOGIC HERE} that will trigger right after the problem header has been printed.

@Strauman Strauman added the compatability Things that relate to other packages that is used together with exercisebank label Nov 5, 2018
@thorstengrothe
Copy link
Author

How do I have to use it? I downloaded the latest prerelease and tested but the error still resists. I tried (see comment in code)

\makeatletter
%\At\AfterPPHeader{% --> commenting this out does not help
\exercisebanksetup{%
	current points style={%
		\ifnum\exb@currentPoints=\z@%
		\ifnum\totalpoints=\z@%
		\else\phantom{0p}%
		\fi\else
		\marginnote{%
			\rule{1cm}{.5pt}
			\centering{}
			\exb@currentPoints~P.}%
		\fi\ignorespaces}}
%	}
\makeatother

@Strauman
Copy link
Owner

Strauman commented Nov 6, 2018

My bad. The issue seem to be with using \marginnote in some specific setting. I guess that what you're trying to do is mark the right margin with the given point style?

@Strauman
Copy link
Owner

Strauman commented Nov 6, 2018

I made a different approach of moving stuff into the right margin. I don't know if it will work in absolutely all cases, but it works fair in basic tests, but it's not perfect. It takes advantage of the new \AfterPPHeader hook:

\documentclass{article}
\usepackage{exercisebank}
\usepackage{lipsum}
% Function to set stuff in right margin
\newbox{\rmarbox}
\newbox{\tmp@rmarbox}
\newcommand\setrightmargin[1]{
  % Calculate how far to move the box right to the margin
  \edef\mdwid{\the\dimexpr\textwidth+\marginparsep}%
  % Get the total height of the content
  \setbox\tmp@rmarbox=\hbox{#1}%
  \edef\totalrmarboxHT{\the\dimexpr-\ht\tmp@rmarbox-\dp\tmp@rmarbox}
  % Make a new box with the height of content.
  % The box has to be moved up (due to \vadjust{}?)
  \setbox\rmarbox=\vbox{\kern\totalrmarboxHT\box\tmp@rmarbox}
  \vadjust{\moveright\mdwid\box\rmarbox}%
}

\exercisebanksetup{%
  exercise directory=exercises,
  current points style={}%<- Remove the current (left hand) style
}

% Setup the points
\makeatletter
\At\AfterPPHeader{
  \ifnum\exb@currentPoints=\z@%
    \ifnum\totalpoints=\z@%
    \else\phantom{0p}%
    \fi\else
    \setrightmargin{%<- Note this changed
      \rule{1cm}{.5pt}
      \centering{}
      \exb@currentPoints~P.}%
  \fi\ignorespaces
}
\makeatother

%% The \makeset{setname}{exercises,to,include} picks exercises from the exercises-folder
%% The \exclude{setname}{1,2,3,...,9} excludes partproblems 1,...,9 from setname
\makeset{1}{firstexercise}
\makeset{2}{firstexercise, \exclude{secondexercise}{1,2}, thirdexercise}

\begin{document}
  \buildset{2}
\end{document}

@thorstengrothe
Copy link
Author

Thank you very much for the code. Yes it works here until now after some testing. One small issue is the additional indention between the number of the part problem and the text, see the image here:

bildschirmfoto_2018-11-06_18-21-01

I think it's very good to use as less foreign packages (here: marginnote) as possible, so your solution is very welcome! Maybe it would be a good idea to make this points style selectable as an option maybe

\SetPointsOnRight
\SetPointsOnLeft

etc... That should be possible with a simple \newcommand definition. I will look at it, when I have more time and the package is more stable, ok?

Regards
Thorsten

@Strauman
Copy link
Owner

Strauman commented Nov 6, 2018

The space seems to be due to your \phantom{0pt} and a few hidden newlines. Here it is removed:

\documentclass{article}
\usepackage{exercisebank}
\usepackage{lipsum}
% Function to set stuff in right margin
\setlength\parindent{0pt}
\newbox{\rmarbox}
\newbox{\tmp@rmarbox}
\newcommand\setrightmargin[1]{%
  % Calculate how far to move the box right to the margin
  \edef\mdwid{\the\dimexpr\textwidth+\marginparsep}%
  % Get the total height of the content
  \setbox\tmp@rmarbox=\hbox{#1}%
  \edef\totalrmarboxHT{\the\dimexpr-\ht\tmp@rmarbox-\dp\tmp@rmarbox}%
  % Make a new box with the height of content.
  % The box has to be moved up (due to \vadjust{}?)
  \setbox\rmarbox=\vbox{\kern\totalrmarboxHT\box\tmp@rmarbox}%
  \vadjust{\moveright\mdwid\box\rmarbox}%
}

\exercisebanksetup{%
  exercise directory=exercises,
  current points style={}%<- Remove the current (left hand) style
}

% Setup the points
\makeatletter
\At\AfterPPHeader{%
  \ifnum\exb@currentPoints=\z@\else%
    \setrightmargin{\rule{1cm}{.5pt}\centering{}\exb@currentPoints~P.}%
  \fi\ignorespaces%
}
\makeatother

%% The \makeset{setname}{exercises,to,include} picks exercises from the exercises-folder
%% The \exclude{setname}{1,2,3,...,9} excludes partproblems 1,...,9 from setname
\makeset{1}{firstexercise}
\makeset{2}{firstexercise, \exclude{secondexercise}{1,2}, thirdexercise}

\begin{document}
  \buildset{2}
\end{document}

@thorstengrothe
Copy link
Author

Looks good, much simpler, works well until now, thank you very much!

@Strauman
Copy link
Owner

Strauman commented Nov 7, 2018

@thorstengrothe No problem! Thanks for testing!
Also - if you figure out a different way of placing stuff in the right margin (without using \marginpar or \marginnote) let me know?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compatability Things that relate to other packages that is used together with exercisebank
Projects
None yet
Development

No branches or pull requests

2 participants