1

Finally my example with different options of bibliography works fine thanks to moewe.

To the below example I needed to add boolean function:

\usepackage{ifthen}

\newboolean{print_or_not} \setboolean{print_or_not}{true} %\setboolean{print_or_not}{false}

and at the end of the example I generally (details in the example) added the condition \ifthenelse:

\ifthenelse{\boolean{print_or_not}} { "PRINT ALL BIBLIOGRAPHIES" } { "DON'T PRINTING ADDITIONAL BIBLIOGRAPHIES AT THE END" }

All the example:

\documentclass[10pt,oneside,a4paper]{book}

\usepackage[utf8]{inputenc} \usepackage[T1]{fontenc}

\usepackage{ifthen}

\newboolean{print_or_not} \setboolean{print_or_not}{true} % \setboolean{print_or_not}{false}

\usepackage[ backend=biber, bibstyle=authoryear, citestyle=numeric, sorting=none, giveninits=true, dashed=false, refsegment=chapter, backref=true, ]{biblatex}

\makeatletter \input{numeric.bbx} \makeatother

\BiblatexSplitbibDefernumbersWarningOff

\DeclareSortingTemplate{none}{ \sort{\field{usera}} \sort{\citeorder} \sort{\intciteorder} }

\DeclareSourcemap{ \maps[datatype=bibtex]{ \map{ \pertype{book} \step[fieldset=usera, fieldvalue=aa] } \map{ \pertype{article} \step[fieldset=usera, fieldvalue=bb] } \map{ \pertype{online} \step[fieldset=usera, fieldvalue=cc] } \map{ \pertype{inproceedings} \step[fieldset=usera, fieldvalue=dd] } } }

\DeclareNameAlias{author}{family-given}
\DeclareNameAlias{translator}{family-given}
\renewcommand*{\revsdnamepunct}{}

\defbibheading{subsubbibintoc}[\refname]{\subsection{#1}} \defbibheading{subsubbibliography}[\refname]{\subsection{#1}}

\addbibresource{biblatex-examples.bib}

\begin{document} \pagestyle{empty} \tableofcontents \chapter{First chapter}

Lorem \autocite{sigfridsson} ipsum \autocite{nietzsche:ksa1} dolor \autocite{moraux} sit \autocite{knuth:ct:c}~\autocite{spiegelberg}.

\printbibheading[title=Chapter bibliography,heading=subbibintoc] \printbibliography[segment=\therefsegment,type=book,heading=subsubbibintoc,title={Books}] \printbibliography[segment=\therefsegment,type=article,heading=subsubbibintoc,title={Articles}] \printbibliography[segment=\therefsegment,type=online,heading=subsubbibintoc,title={Online}] \printbibliography[segment=\therefsegment,type=inproceedings,heading=subsubbibintoc,title={Conferences}]

\vspace{5mm} {\let\clearpage\relax \chapter{Second chapter}}

Lorem~\cite{vizedom:related} ipsum~\cite{gerhardt} dolor~\cite{augustine} sit~\cite{ctan}.

\printbibheading[title=Chapter bibliography,heading=subbibintoc] \printbibliography[segment=\therefsegment,type=book,heading=subsubbibintoc,title={Books}] \printbibliography[segment=\therefsegment,type=article,heading=subsubbibintoc,title={Articles}] \printbibliography[segment=\therefsegment,type=online,heading=subsubbibintoc,title={Online}] \printbibliography[segment=\therefsegment,type=inproceedings,heading=subsubbibintoc,title={Conferences}]

\vspace{5mm} {\let\clearpage\relax \chapter{Third chapter}}

Lorem~\cite{wassenberg}, ipsum~\cite{baez/online}.

% COMENTING \ifthenelse ALL IS CORRECT below \ifthenelse{\boolean{print_or_not}} { % COMENTING above

\printbibheading[title=Chapter bibliography,heading=subbibintoc] \printbibliography[segment=\therefsegment,type=book,heading=subsubbibintoc,title={Books}] \printbibliography[segment=\therefsegment,type=article,heading=subsubbibintoc,title={Articles}] \printbibliography[segment=\therefsegment,type=online,heading=subsubbibintoc,title={Online}] \printbibliography[segment=\therefsegment,type=inproceedings,heading=subsubbibintoc,title={Conferences}]

\printbibheading[title=Global Bibliography,heading=bibintoc] \printbibliography[type=book,heading=subsubbibliography,title={Books}] \printbibliography[type=article,heading=subsubbibliography,title={Articles}] \printbibliography[type=online,heading=subsubbibliography,title={Online}] \printbibliography[type=inproceedings,heading=subsubbibliography,title={Conferences}]

\csletcs{saved@blx@refcontext@context}{blx@refcontext@context} \newrefcontext[sorting=nyt] \makeatletter \AtNextBibliography{% \def\blx@setdefaultrefcontext#1{}% \csletcs{blx@refcontext@context}{saved@blx@refcontext@context}} \makeatother \printbibliography[title=Global Bibliography (alphabetic),heading=bibintoc]

\newrefcontext[sorting=nyt] \makeatletter \AtNextBibliography{% \def\blx@setdefaultrefcontext#1{}% \DeclareFieldFormat{labelnumberwidth}{#1\addperiod}} \makeatother \printbibliography[title={Global Bibliography (alphabetic & continuous numbering)},heading=bibintoc]

% COMENTING below } { \printbibheading[title=DON'T PRINT BIBLIOGRAPHY,heading=bibintoc] } % COMENTING above

\end{document}

The reason such a decision is simply I need to print an additional global bibliography or not.

The problem is that if part of the code is taken with boolean option like below

\ifthenelse{\boolean{print_or_not}}{}{}

the citation number changes [6] is [8] etc

enter image description here

enter image description here

....like before described in the topic \begingroup \endgroup changing citation numbers. When all example work without boolean option everything is OK!

We can check this problem simply by commenting boolean option in the code or uncomment it. Lines pointed in the code as 104-105 and 138-141.

What is the reason of such the wrong citation with boolean option and whether this can be fixed? It could be the last serious problem of my "episodes of topics".

moewe
  • 175,683
L. Flis
  • 53
  • 2
    This looks like it could be an interesting question (especially since not using ifthen turns out to work), but your example has so much extra stuff in it that I can't quite follow. – Teepeemm Nov 01 '22 at 19:38
  • The example is the same. I added only ifthen to print you solution or not - Global bib. We can see the problem doesn't exist with ordinary \if \elsel \fi. This can mean that the question should be directed to the author of ifthen package why it spoil the bibliogrphy. From the begining I useded ifthen package because it seemsed to be more easy to use. From the moment it spoiled my bibliography I just used \if \elsel \fi and evrythong is OK. The problem is that I would like to know if it is bug in the packaga and can be fixed or not. If not I will saty with \if \elsel \fi. – L. Flis Nov 02 '22 at 17:25

2 Answers2

3

The problem here is that the code essentially boils down to something of the following form

\ifthenelse{\boolean{print_or_not}}
  {...
   \csletcs{saved@blx@refcontext@context}{blx@refcontext@context}
   \newrefcontext[sorting=nyt]
   \makeatletter
   \AtNextBibliography{%
     \def\blx@setdefaultrefcontext#1{}%
     \csletcs{blx@refcontext@context}{saved@blx@refcontext@context}}
   \makeatother
   \printbibliography[title=Global Bibliography (alphabetic),heading=bibintoc]

\newrefcontext[sorting=nyt] \makeatletter \AtNextBibliography{% \def\blx@setdefaultrefcontext#1{}% \DeclareFieldFormat{labelnumberwidth}{#1\addperiod}} \makeatother \printbibliography[title={Global Bibliography (alphabetic &amp; continuous numbering)},heading=bibintoc] ...} {<print nothing>}

where we need the \makeatletter...\makeatother block because we want to redefine an internal macro with an @ in its name (\def\blx@setdefaultrefcontext#1{}).

However, the rules of TeX parsing mean that \makeatletter...\makeatother have no effect when used inside a macro argument (the argument being the <true> branch of the \ifthenelse{<condition>}{<true>}{<false>}). (This is the same effect that makes it hard to use verbatim and friends inside of footnotes and the like.)

A simple solution is to move the \makeatletter...\makeatother outside the macro call

\makeatletter
\ifthenelse{\boolean{print_or_not}}
  {...
   \csletcs{saved@blx@refcontext@context}{blx@refcontext@context}
   \newrefcontext[sorting=nyt]
   \AtNextBibliography{%
     \def\blx@setdefaultrefcontext#1{}%
     \csletcs{blx@refcontext@context}{saved@blx@refcontext@context}}
   \printbibliography[title=Global Bibliography (alphabetic),heading=bibintoc]

\newrefcontext[sorting=nyt] \AtNextBibliography{% \def\blx@setdefaultrefcontext#1{}% \DeclareFieldFormat{labelnumberwidth}{#1\addperiod}} \printbibliography[title={Global Bibliography (alphabetic &amp; continuous numbering)},heading=bibintoc] ...} {<print nothing>} \makeatother

The problems also does not occur if you use simple conditionals of the form

\if<cond>
  <print bib>
\else
  <print nothing>
\fi

because then the \makeatletter...\makeatother is not caught up inside a macro acrgument.

moewe
  • 175,683
  • Thank you for explanation. Finally this is better to use simple conditionals \if \else \ \fi. It seems to work even faster and I used it only for this decision then I finnally swited to \if \else \ \fi. – L. Flis Nov 03 '22 at 13:28
0

I have found solution. Agaist ifthen package I simply ued \if \elsel \fi function with \newif\ifprintornot and \printornottrue seting of variable. This solution works even faster than using ifthen package.

Apparently some bug exist in ifthen package. I am still interested in using ifthen package and I wil try to report the problem to the author. If someone find solution for the ifthen package please report here his answer.

Below the all working 100% example chcked and ready to use:

\documentclass[10pt,oneside,a4paper]{book}

\usepackage[utf8]{inputenc} \usepackage[T1]{fontenc}

\newif\ifprintornot \printornottrue

\usepackage[ backend=biber, bibstyle=authoryear, citestyle=numeric, sorting=none, giveninits=true, dashed=false, refsegment=chapter, backref=true, ]{biblatex}

\makeatletter \input{numeric.bbx} \makeatother

\BiblatexSplitbibDefernumbersWarningOff

\DeclareSortingTemplate{none}{ \sort{\field{usera}} \sort{\citeorder} \sort{\intciteorder} }

\DeclareSourcemap{ \maps[datatype=bibtex]{ \map{ \pertype{book} \step[fieldset=usera, fieldvalue=aa] } \map{ \pertype{article} \step[fieldset=usera, fieldvalue=bb] } \map{ \pertype{online} \step[fieldset=usera, fieldvalue=cc] } \map{ \pertype{inproceedings} \step[fieldset=usera, fieldvalue=dd] } } }

\DeclareNameAlias{author}{family-given}
\DeclareNameAlias{translator}{family-given}
\renewcommand*{\revsdnamepunct}{}

\defbibheading {subsubbibintoc}[\refname]{\subsection{#1}} \defbibheading{subsubbibliography}[\refname]{\subsection{#1}}

\addbibresource{biblatex-examples.bib}

\begin{document} \pagestyle{empty} \tableofcontents \chapter{First chapter}

Lorem \autocite{sigfridsson} ipsum \autocite{nietzsche:ksa1} dolor \autocite{moraux} sit \autocite{knuth:ct:c}~\autocite{spiegelberg}.

\printbibheading[title=Chapter bibliography,heading=subbibintoc] \printbibliography[segment=\therefsegment,type=book,heading=subsubbibintoc,title={Books}] \printbibliography[segment=\therefsegment,type=article,heading=subsubbibintoc,title={Articles}] \printbibliography[segment=\therefsegment,type=online,heading=subsubbibintoc,title={Online}] \printbibliography[segment=\therefsegment,type=inproceedings,heading=subsubbibintoc,title={Conferences}]

\vspace{5mm} {\let\clearpage\relax \chapter{Second chapter}}

Lorem~\cite{vizedom:related} ipsum~\cite{gerhardt} dolor~\cite{augustine} sit~\cite{ctan}.

\printbibheading[title=Chapter bibliography,heading=subbibintoc] \printbibliography[segment=\therefsegment,type=book,heading=subsubbibintoc,title={Books}] \printbibliography[segment=\therefsegment,type=article,heading=subsubbibintoc,title={Articles}] \printbibliography[segment=\therefsegment,type=online,heading=subsubbibintoc,title={Online}] \printbibliography[segment=\therefsegment,type=inproceedings,heading=subsubbibintoc,title={Conferences}]

\vspace{5mm} {\let\clearpage\relax \chapter{Third chapter}}

Lorem~\cite{wassenberg}, ipsum~\cite{baez/online}.

\ifprintornot

\printbibheading[title=Chapter bibliography,heading=subbibintoc] \printbibliography[segment=\therefsegment,type=book,heading=subsubbibintoc,title={Books}] \printbibliography[segment=\therefsegment,type=article,heading=subsubbibintoc,title={Articles}] \printbibliography[segment=\therefsegment,type=online,heading=subsubbibintoc,title={Online}] \printbibliography[segment=\therefsegment,type=inproceedings,heading=subsubbibintoc,title={Conferences}]

\printbibheading[title=Global Bibliography,heading=bibintoc] \printbibliography[type=book,heading=subsubbibliography,title={Books}] \printbibliography[type=article,heading=subsubbibliography,title={Articles}] \printbibliography[type=online,heading=subsubbibliography,title={Online}] \printbibliography[type=inproceedings,heading=subsubbibliography,title={Conferences}]

\csletcs{saved@blx@refcontext@context}{blx@refcontext@context} \newrefcontext[sorting=nyt] \makeatletter \AtNextBibliography{% \def\blx@setdefaultrefcontext#1{}% \csletcs{blx@refcontext@context}{saved@blx@refcontext@context}} \makeatother \printbibliography[title=Global Bibliography (alphabetic),heading=bibintoc]

\newrefcontext[sorting=nyt] \makeatletter \AtNextBibliography{% \def\blx@setdefaultrefcontext#1{}% \DeclareFieldFormat{labelnumberwidth}{#1\addperiod}} \makeatother \printbibliography[title={Global Bibliography (alphabetic &amp; continuous numbering)},heading=bibintoc]

\else

\printbibheading[title=DON'T PRINT BIBLIOGRAPHY,heading=bibintoc]

\fi

\end{document}

It is all done well! I FINISHED my long adventure for now with different sort of citations in BiBLaTeX.

L. Flis
  • 53