I am planning on writing a science text under the CC BY-SA 4.0 license. The text will contain code blocks for commonly preformed analysis from the relevant field of study. Additionally, it will use common packages from R and Python. I only want to ensure that text remains open and free to use to ensure that it doesn't end up exclusively behind a pay wall like all other texts covering the topic of interest. The code in the code blocks in the text are generally adapted from established code or there are only few ways to wite it because it's a specific analysis.
My questions are as follows;
Given that the text and LaTex code used to build the document will be licensed under CC BY-SA 4.0 license, if someone use the publish code blocks in their analysises do they also have apply CC BY-SA 4.0 license for any works that use the analysises and code?
Should I license only the text, the LaTex code, and images under CC BY-SA 4.0 license and specify the code blocks are licensed under a different license?
If the answer to (2) is "yes", what are good license options to allow individuals to use the code blocks without any restrictions or requirements? Also what the most appropriate way to specify the license in this case or are there examples? Alternatively, can I specify that code examples in the text are excluded from the license?