Welcome to TeX! You can make the code apparent by indenting it with 4 spaces, or by marking the code and pressing the {} button. Furthermore we usually don't supply a thanks in the question as that is implicit by your name tag. Enjoy your stay at TeX! :)
–
zerothJun 21 '13 at 8:22

5

I guess you probably wanted to do \let\fistudenti\fi....
–
Claudio FiandrinoJun 21 '13 at 8:32

Thanks @claudio, this is what I wanted indeed.
–
cristianJun 21 '13 at 8:54

3 Answers
3

The conditional primitives\if.., \else and \fi need to be directly visible by TeX and can not be hidden inside macros. If TeX finds a false \if.. clause it looks at all following tokens until it finds a token equal to \else or \fiwithout expanding macros. If it finds another \if.. conditional it increases an internal counter and will look for the \fi for this conditional before looking for the outer one.

If you have a macro like \newcommand{\fistudenti}{\fi} the \fi is hidden and not found. The same is true for own \if.. macros inside a false clause. Both will work in a true clause because there macros are expanded as normal.

To make your macro work you need to use \let\fistudenti\fi instead, which makes \fistudenti a token identical to \fi. This is also the way used by \newif to define now conditionals. The \xxxtrue and \xxxfalse macros defined by it simply include \let\ifxxx\iftrue or \let\ifxxx\iffalse.

Again uncommenting the \studentsversiontrue line will switch between printing the first rather than the second argument.

Note that this can go along with the other method. Which one to use in a particular case probably depends on the size of the material.

Comment character

With a good editor it's not difficult to select a region and add at the beginning of the lines some characters; in this application I choose to prefix the “only students” parts with ^^A.

\documentclass{article}
\newcommand{\showstudents}{\catcode`\^^A=9 }
\newcommand{\hidestudents}{\catcode`\^^A=14 }
\hidestudents % default
\begin{document}
\showstudents
This material is seen by everybody.
^^A This material, instead,
^^A is seen only when so
^^A decided.
And this material always shows.
\end{document}

If the \showstudents line is commented out, the ^^A combination will be seen as a comment character exactly like %. If it's not commented, ^^A will be ignored.

Conditionals. When an \if... is expanded, TeX reads ahead as far as
necessary to determine whether the condition is true or false; and
if false, it skips ahead (keeping track of \if...\fi nesting) until
finding the \else, \or, or \fi that ends the skipped text.

So in your first example the test is true and so it expands the part. In your second example the test is false; and TeX searching a \fi