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

sidecite only once per page #216

Open
fredguth opened this issue Mar 4, 2022 · 7 comments · May be fixed by #254
Open

sidecite only once per page #216

fredguth opened this issue Mar 4, 2022 · 7 comments · May be fixed by #254

Comments

@fredguth
Copy link

fredguth commented Mar 4, 2022

Summary

Currently, sidecite appears to be adding citation to the margin everytime you call sidecite.

Details

When you \sidecite{key} more than once \sidecite{key} in the same page. There should be only one citation in the margin.

See: https://tex.stackexchange.com/q/444827/157312

I am trying to fix this, if successful I will PR a change. But I am still a beginner with kaobook code.

@fredguth
Copy link
Author

fredguth commented Mar 4, 2022

Besides, documentation says you cannot change the position of citation in the margin, although I believe you already created this feature in the code.

@fredguth
Copy link
Author

fredguth commented Mar 4, 2022

Changing kaobiblio.sty
I was able to mark sidenotes as new (N) or old (O), but when I tried to prevent \formatmargincitation{...} of running, there is an error.

This works:

\NewDocumentCommand{\registerkey}{}{%
  \ifcsundef{cbx@instcount@curr@\the\c@refsection @\thefield{entrykey}}
    {\csnumgdef{cbx@instcount@curr@\the\c@refsection @\thefield{entrykey}}{0}}
    {}%
  \csnumgdef{cbx@instcount@last@\the\c@refsection @\thefield{entrykey}}{%
    \csuse{cbx@instcount@curr@\the\c@refsection @\thefield{entrykey}}}%
  \csnumgdef{cbx@instcount@curr@\the\c@refsection @\thefield{entrykey}}{\value{instcount}}}

\def\iflastciteonsamepage{
  \ifsamepage
    {\number\csuse{cbx@instcount@curr@\the\c@refsection @\thefield{entrykey}}}
    {\number\csuse{cbx@instcount@last@\the\c@refsection @\thefield{entrykey}}}
}
\NewDocumentCommand{\sidecite}{o o o m}{%
	\RenewDocumentCommand{\kaobiblio@marginnote}{m}{%
		\marginnote[#1]{##1}%
	}%
	\DeclareCiteCommand{\kaobiblio@sidecite}[\kaobiblio@marginnote]{%
	}{%
		\registerkey
		\iflastciteonsamepage
     	{O)}
     	{N)}
		\formatmargincitation{\thefield{entrykey}}
	}{%
		\\% separator between multiple citations
	}{%
	}%
	% With this we print the marker in the text and add the item to the bibliography at the end
	\IfNoValueOrEmptyTF{#2}%
	{\def\@tempa{\cite{#4}\kaobiblio@sidecite{#4}}}%
	{\IfNoValueOrEmptyTF{#3}%
		{\IfNoValueTF{#3}%
			{\def\@tempa{\cite[#2]{#4}\kaobiblio@sidecite{#4}}}%
			{\def\@tempa{\cite[#2][]{#4}\kaobiblio@sidecite{#4}}}% postnote is empty, so pass empty postnote
		}%
		{\def\@tempa{\cite[#2][#3]{#4}\kaobiblio@sidecite{#4}}}%
	}%
	\ifkaobiblio@addspace%
		\unskip~\@tempa%
	\else%
		\@tempa%
	\fi%
}

This does not work:

\NewDocumentCommand{\registerkey}{}{%
  \ifcsundef{cbx@instcount@curr@\the\c@refsection @\thefield{entrykey}}
    {\csnumgdef{cbx@instcount@curr@\the\c@refsection @\thefield{entrykey}}{0}}
    {}%
  \csnumgdef{cbx@instcount@last@\the\c@refsection @\thefield{entrykey}}{%
    \csuse{cbx@instcount@curr@\the\c@refsection @\thefield{entrykey}}}%
  \csnumgdef{cbx@instcount@curr@\the\c@refsection @\thefield{entrykey}}{\value{instcount}}}

\def\iflastciteonsamepage{
  \ifsamepage
    {\number\csuse{cbx@instcount@curr@\the\c@refsection @\thefield{entrykey}}}
    {\number\csuse{cbx@instcount@last@\the\c@refsection @\thefield{entrykey}}}
}
\NewDocumentCommand{\sidecite}{o o o m}{%
	\RenewDocumentCommand{\kaobiblio@marginnote}{m}{%
		\marginnote[#1]{##1}%
	}%
	\DeclareCiteCommand{\kaobiblio@sidecite}[\kaobiblio@marginnote]{%
	}{%
		\registerkey
		\iflastciteonsamepage
     	{%nothing here%}
     	{\formatmargincitation{\thefield{entrykey}}}
		
	}{%
		\\% separator between multiple citations
	}{%
	}%
	% With this we print the marker in the text and add the item to the bibliography at the end
	\IfNoValueOrEmptyTF{#2}%
	{\def\@tempa{\cite{#4}\kaobiblio@sidecite{#4}}}%
	{\IfNoValueOrEmptyTF{#3}%
		{\IfNoValueTF{#3}%
			{\def\@tempa{\cite[#2]{#4}\kaobiblio@sidecite{#4}}}%
			{\def\@tempa{\cite[#2][]{#4}\kaobiblio@sidecite{#4}}}% postnote is empty, so pass empty postnote
		}%
		{\def\@tempa{\cite[#2][#3]{#4}\kaobiblio@sidecite{#4}}}%
	}%
	\ifkaobiblio@addspace%
		\unskip~\@tempa%
	\else%
		\@tempa%
	\fi%
}

First I thought the problem was the '\' without nothing before, but it is more than that.

Hope someone can help.

@pierrejacquet
Copy link

pierrejacquet commented Mar 7, 2022

Looking for this functionnality too. It would be nice if this modification could also integrate the option to sidecite a reference once per document (sidecite only the first time). So like a switch between "each time/ once per page / once per document". I have no idea if it's feasible since I have little knowledge in LaTeX prog.

@fredguth
Copy link
Author

fredguth commented Mar 17, 2022

This issue seems related to #217 and #220.

@fmarotta, I guess you are too busy to make these changes. Could you take a glance at least to give us some hints on how could we try to fix this issue? I would gladly help if I could. But, at this point, I have no idea how.

@pi8027
Copy link
Contributor

pi8027 commented Apr 7, 2022

I'm looking for this feature too. But I'd like to do that selectively for each page (for pages with fewer citations, I prefer not doing that), and to control their position since I use \sidenote a lot. (I just wanted to express my needs, but I have no idea how to implement that.)

@AlexanderZeilmann
Copy link
Contributor

AlexanderZeilmann commented Jun 3, 2022

@fredguth may I ask what error you encountered with your code? For me it seems to work just fine.

The only change I made was to convert

\iflastciteonsamepage
{%nothing here%}
{\formatmargincitation{\thefield{entrykey}}}

to

\iflastciteonsamepage
{}
{\formatmargincitation{\thefield{entrykey}}}

such that the first closing bracket is not commented out.

The only problem is that the horizontal alignment of the first line of the margin citation is slightly misaligned. This problem is probably the same as #220.

@fredguth
Copy link
Author

fredguth commented Jun 28, 2022

@AlexanderZeilmann I created a PR for this feature. Although, it is breaking another feature.... /sidecite{key1, key2} does not work anymore, so I don't know if it will be merged.

On the other matter...
Indeed, I tried addspace=false and addspace=true and it makes no difference.

fredguth added a commit to fredguth/kaobook that referenced this issue Sep 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants