This project is read-only.

Conditional format

Apr 11, 2009 at 1:57 AM

Why wonder how could I resolve this: If certain string (such as author) is unavaiable, I need to that format to be applied to next variable. Like this.

FOREMAN, George. How to lose weight swiftly. 6th ed. New York: GF Publisher, 1969.
HOW TO LOSE WEIGHT SWIFTLY. 6th ed. New York: GF Publisher, 1969.

Something like...

IF string_is_avaiable FORMAT format_1
ELSE FORMAT format_2

Thanks in advance!
Apr 11, 2009 at 10:08 AM
Edited Apr 11, 2009 at 10:09 AM

You can put your basic condition first and all the rest as subparts. Then, you can repeat the all those subparts again after/outside the first one. As this sounds more complicated than it really is, let me illustrate with an example:

<format>{%Author:2%{, %Title%}{, %Year%}}{%Title:u%}{, %Year:s%}</format>

Take a good look at the balancing of the brackets. To explain it a bit better, I'll number them between {}:

{0}%Author:2%{1}, %Title%{1}{2}, %Year%{2}{0}{3}%Title:u%{3}{4}, %Year:s%{4}

So, the main condition is to format the author (between {0}). If the author is available, then the subparts {1} and {2} are processed. Once those are processed, the variables Title and Year are used and will not be used again (unless you would add a ':r' option to them). So since they are used, {3} and {4} will be empty and therefore not displayed.

If the author is not available, then {1} and {2} will not be executed and Title and Year will remain available for {3} and {4}.

Example output:

  • Cullity BD, Introduction to Magnetic Materials, 1972

Your format string might become a bit long this way, but you should be able to achieve almost anything you want.

Apr 11, 2009 at 10:49 AM
The solution I presented in the above post will always work. However, if the difference in formatting is minor (upper/lower case, or just another variable), you could use a shortcut with the or'ing (|) of variables. For your example, the following might work:

{%Author:2|Title:u}{, &lt;b&gt;%Title%&lt;/b&gt;}{. %Edition:o% ed}.

This will display the author followed by the the title in bold. If there is no author, than the title in uppercase will be displayed. As that means the title is already used before, the title won't be displayed again in bold then.
Apr 11, 2009 at 4:25 PM
Edited Apr 11, 2009 at 4:28 PM
Ahh, thank you, Yves! I had thought of the first way you wrote about, but I did get a bit worried about the mess it would be.

I actually didn't know you could { %variable1%|%variable2%} even if those variable weren't connected, that was my mistake. And surely had no idea the format would not display repeated info.

Thank you very much again! =) I'll be posting the style as soon as I finish it.