Is there a problem of taking a sefer out of a knapsack on shabbos when one knows that there are muktzah objects (e.g. pens, calculator, etc.) inside? And is there a difference whether one comes into contact with these muktzah objects?
It is permitted to take the sefer out of the knapsak, even though there are other items that are muktzah inside. However, one should be careful not to touch the muktzah items as far as possible, and it is forbidden to move them intentionally.
Sources: The fact that other items will be moved by moving the sefer does not constitute a problem, because this is a classic case of tiltul min hatzad, “indirect moving” that is permitted if done for the purpose of a permitted item (see Gemara, Shabbos 123). Even if the muktzah items will be inadvertently moved by one’s hand, their moving is defined as tiltul min hatzad, and remains permitted (see Shabbos 127; Mishnah Berurah 333:13; Chazon Ish 46:7; Orchos Shaboos, vol. 2, p. 125).