As far as i do understand your question you will need some kind of "cross product". You will need two loops to create your classes and also will need variables with variable names.
Example:
@literatureColor: red;
@mathColor: blue;
@geographyColor: yellow;
@computationalscienceColor: orange;
@classes: literature,math,geography,computationalscience;
.outsideloop(@classes; @iterator: 1) {
@pre: extract(@classes,@iterator);
.insideloop(@pre,@classes,@iterator);
& when (@iterator < length(@classes)) {
.outsideloop(@classes,@iterator + 1);
}
}
.insideloop(@pre,@classes,@preiterator,@iterator: 1) {
@post: extract(@classes,@iterator);
& when not (@pre = @post) {
@precolor: "@{pre}Color";
@postcolor: "@{post}Color";
@{pre}-@{post} {
background: linear-gradient(to right, @@precolor 0%, @@postcolor 100%);
}
}
& when (@iterator < length(@classes)) {
.insideloop(@pre,@classes,@preiterator,@iterator + 1);
}
}
.outsideloop(@classes);
The preceding Less code will compile into CSS code as follows:
literature-math {
background: linear-gradient(to right, red 0%, blue 100%);
}
literature-geography {
background: linear-gradient(to right, red 0%, yellow 100%);
}
literature-computationalscience {
background: linear-gradient(to right, red 0%, orange 100%);
}
math-literature {
background: linear-gradient(to right, blue 0%, red 100%);
}
math-geography {
background: linear-gradient(to right, blue 0%, yellow 100%);
}
math-computationalscience {
background: linear-gradient(to right, blue 0%, orange 100%);
}
geography-literature {
background: linear-gradient(to right, yellow 0%, red 100%);
}
geography-math {
background: linear-gradient(to right, yellow 0%, blue 100%);
}
geography-computationalscience {
background: linear-gradient(to right, yellow 0%, orange 100%);
}
computationalscience-literature {
background: linear-gradient(to right, orange 0%, red 100%);
}
computationalscience-math {
background: linear-gradient(to right, orange 0%, blue 100%);
}
computationalscience-geography {
background: linear-gradient(to right, orange 0%, yellow 100%);
}