How to draw A ⊕ B ⊕ C as a Venn diagram?











up vote
17
down vote

favorite
3












You see my code and please answer my two questions:



documentclass{article}
usepackage{amsmath,amssymb,mathptmx}
usepackage{pstricks}
usepackage{pst-node}
usepackage{auto-pst-pdf}
begin{document}
begin{pspicture}[showgrid](-3,-3)(8,8)%[linestyle=none]
psclip{%
pscircle(0,0){3}
pscircle(4,0){3} }
pscircle[fillcolor=blue,fillstyle=solid](2,3){3}
endpsclip
pscircle(0,0){3}
pscircle(4,0){3}
pscircle(2,3){3}
end{pspicture}
end{document}


The output picture:



enter image description here



Picture 1:



enter image description here



Its code (use TikZ):



documentclass{article}
usepackage{tikz}

begin{document}
begin{tikzpicture}
fill[blue,even odd rule] (0,0) circle (3) (4,0) circle (3) (2,3) circle (3);
end{tikzpicture}


My questions:




  • How to make my picture like Picture 1? Truly I don't know how to fill color to it.


  • (After completing the previous question) Do you see the TikZ code of Picture 1? Look at the important option even odd rule. Do PStricks have the equivalent command, macro,.. as TikZ?




Notice: I prefer PStricks to TikZ but sometimes I recognize the TikZ code is better.




Sorry if I make you being uncomfortable.










share|improve this question
























  • @ Dũng Vũ Thank you.
    – chishimotoji
    Nov 30 at 6:39















up vote
17
down vote

favorite
3












You see my code and please answer my two questions:



documentclass{article}
usepackage{amsmath,amssymb,mathptmx}
usepackage{pstricks}
usepackage{pst-node}
usepackage{auto-pst-pdf}
begin{document}
begin{pspicture}[showgrid](-3,-3)(8,8)%[linestyle=none]
psclip{%
pscircle(0,0){3}
pscircle(4,0){3} }
pscircle[fillcolor=blue,fillstyle=solid](2,3){3}
endpsclip
pscircle(0,0){3}
pscircle(4,0){3}
pscircle(2,3){3}
end{pspicture}
end{document}


The output picture:



enter image description here



Picture 1:



enter image description here



Its code (use TikZ):



documentclass{article}
usepackage{tikz}

begin{document}
begin{tikzpicture}
fill[blue,even odd rule] (0,0) circle (3) (4,0) circle (3) (2,3) circle (3);
end{tikzpicture}


My questions:




  • How to make my picture like Picture 1? Truly I don't know how to fill color to it.


  • (After completing the previous question) Do you see the TikZ code of Picture 1? Look at the important option even odd rule. Do PStricks have the equivalent command, macro,.. as TikZ?




Notice: I prefer PStricks to TikZ but sometimes I recognize the TikZ code is better.




Sorry if I make you being uncomfortable.










share|improve this question
























  • @ Dũng Vũ Thank you.
    – chishimotoji
    Nov 30 at 6:39













up vote
17
down vote

favorite
3









up vote
17
down vote

favorite
3






3





You see my code and please answer my two questions:



documentclass{article}
usepackage{amsmath,amssymb,mathptmx}
usepackage{pstricks}
usepackage{pst-node}
usepackage{auto-pst-pdf}
begin{document}
begin{pspicture}[showgrid](-3,-3)(8,8)%[linestyle=none]
psclip{%
pscircle(0,0){3}
pscircle(4,0){3} }
pscircle[fillcolor=blue,fillstyle=solid](2,3){3}
endpsclip
pscircle(0,0){3}
pscircle(4,0){3}
pscircle(2,3){3}
end{pspicture}
end{document}


The output picture:



enter image description here



Picture 1:



enter image description here



Its code (use TikZ):



documentclass{article}
usepackage{tikz}

begin{document}
begin{tikzpicture}
fill[blue,even odd rule] (0,0) circle (3) (4,0) circle (3) (2,3) circle (3);
end{tikzpicture}


My questions:




  • How to make my picture like Picture 1? Truly I don't know how to fill color to it.


  • (After completing the previous question) Do you see the TikZ code of Picture 1? Look at the important option even odd rule. Do PStricks have the equivalent command, macro,.. as TikZ?




Notice: I prefer PStricks to TikZ but sometimes I recognize the TikZ code is better.




Sorry if I make you being uncomfortable.










share|improve this question















You see my code and please answer my two questions:



documentclass{article}
usepackage{amsmath,amssymb,mathptmx}
usepackage{pstricks}
usepackage{pst-node}
usepackage{auto-pst-pdf}
begin{document}
begin{pspicture}[showgrid](-3,-3)(8,8)%[linestyle=none]
psclip{%
pscircle(0,0){3}
pscircle(4,0){3} }
pscircle[fillcolor=blue,fillstyle=solid](2,3){3}
endpsclip
pscircle(0,0){3}
pscircle(4,0){3}
pscircle(2,3){3}
end{pspicture}
end{document}


The output picture:



enter image description here



Picture 1:



enter image description here



Its code (use TikZ):



documentclass{article}
usepackage{tikz}

begin{document}
begin{tikzpicture}
fill[blue,even odd rule] (0,0) circle (3) (4,0) circle (3) (2,3) circle (3);
end{tikzpicture}


My questions:




  • How to make my picture like Picture 1? Truly I don't know how to fill color to it.


  • (After completing the previous question) Do you see the TikZ code of Picture 1? Look at the important option even odd rule. Do PStricks have the equivalent command, macro,.. as TikZ?




Notice: I prefer PStricks to TikZ but sometimes I recognize the TikZ code is better.




Sorry if I make you being uncomfortable.







color pstricks






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 30 at 9:15









Community

1




1










asked Nov 30 at 6:08









chishimotoji

397212




397212












  • @ Dũng Vũ Thank you.
    – chishimotoji
    Nov 30 at 6:39


















  • @ Dũng Vũ Thank you.
    – chishimotoji
    Nov 30 at 6:39
















@ Dũng Vũ Thank you.
– chishimotoji
Nov 30 at 6:39




@ Dũng Vũ Thank you.
– chishimotoji
Nov 30 at 6:39










5 Answers
5






active

oldest

votes

















up vote
19
down vote



accepted










A PSTricks solution just for fun!



Answer 1



documentclass[pstricks]{standalone}
begin{document}
begin{pspicture}(-5,-5)(5,5)
pscustom[fillstyle=eofill,fillcolor=blue]
{
pscircle(1.5;90){3}
pscircle(1.5;-30){3}
pscircle(1.5;210){3}
}
end{pspicture}
end{document}


enter image description here



The stroke color is left black just for a trivial reason.



Cartesian coordinates are used in response to the request.



documentclass[pstricks]{standalone}
begin{document}
begin{pspicture}(-5,-5)(5,5)
pscustom[fillstyle=eofill,fillcolor=blue]
{
pscircle(0,1.5){3}
pscircle(1.29,-0.75){3}
pscircle(-1.29,-0.75){3}
}
end{pspicture}
end{document}


Answer 2



Non-zero winding rule:



documentclass[pstricks,border=12pt]{standalone}
begin{document}
begin{pspicture}[showgrid=t](-3,-3)(3,3)
pscustom[fillstyle=solid,fillcolor=red]
{
pscircle{1}
pscircle{2}
}
end{pspicture}
end{document}


enter image description here



Non-zero winding rule:



documentclass[pstricks,border=12pt]{standalone}
begin{document}
begin{pspicture}[showgrid=t](-3,-3)(3,3)
pscustom[fillstyle=solid,fillcolor=red]
{
psarcn(0,0){1}{360}{0}
pscircle{2}
}
end{pspicture}
end{document}


enter image description here



Even-odd rule:



documentclass[pstricks,border=12pt]{standalone}
begin{document}
begin{pspicture}[showgrid=t](-3,-3)(3,3)
pscustom[fillstyle=eofill,fillcolor=red]
{
pscircle{1}
pscircle{2}
}
end{pspicture}
end{document}


enter image description here






share|improve this answer























  • As your code, the important option is " fillstyle=eofill " . I haven't known that there is a option as " fillstyle=eofill " before. It doesn't within PStrick User's Guide.
    – chishimotoji
    Nov 30 at 8:42


















up vote
15
down vote



+500










Here is an answer based on the one by @Thomas. Differences




  • the "elementary" regions I, II, ..., VIII are not numbered the same. My numbering is that "N" is the Roman number of "n+1" where "n" in binary is "abc", and the region is intersection of A or not A with B or not B with C or not C according to a, b, c = 0 or 1. (Boolean logic)


  • the macro needs only one input: a TeX formula for the set. Please enrich the syntax by adding suitable definitions converting TeX math macros into Boolean logic notation, as understood by xintexpr


  • I have dropped all fancy customization of colors, but xparse virtuosos will add the fancy optional arguments to re-install it if needed.



Thus, the big point here is that xintexpr computes automatically from the TeX typesetting formula which regions are to be filled in diagram.




attention to setminus it must be used either with parentheses setminus (...) or without but then with only one letter setminus A
ok, setminus Acap B not ok, because the translation here to xintexpr
boolean will do naively something equivalent to and not(A) and B, not the expected and not(A and B). In short, you must treat setminus as having maximally tying precedence.




documentclass[pstricks, border=10pt]{standalone}
usepackage{pst-node}
usepackage{xparse,xintexpr}

defKOEA{1.9,2.2}
defFOEA{1.4,1}

defKOEB{3.3,2.2}
defFOEB{1.2,1}

defKOEC{2.75,1.4}
defFOEC{1.4,1}

defKOEO{2.5,2}
defFOEO{2.5,2.0}

NewDocumentCommand{EreignisA}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEA)(FOEA)}{%
psellipse(KOEA)(FOEA)}%
}

NewDocumentCommand{EreignisB}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEB)(FOEB)}{%
psellipse(KOEB)(FOEB)}%
}

NewDocumentCommand{EreignisC}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEC)(FOEC)}{%
psellipse(KOEC)(FOEC)}%
}

NewDocumentCommand{EreignisOmega}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEO)(FOEO)}{%
psellipse(KOEO)(FOEO)}%
}

NewDocumentCommand{EndeEllipsen}{sm}{%
EreignisOmega%
pnodes(0.25,3.75){Omega}(0.25,0.25){A}(4.75,3.75){B}(4.75,0.25){C}(2.5,-0.5){E}
pnodes(0.7,3.36){MOmega}(0.85,1.55){MA}(4,3){MB}(3.8,0.75){MC}
EreignisA
EreignisB
EreignisC
rput[t](E){#2}%
IfBooleanF{#1}{%
rput(Omega){$Omega$}pcline[nodesepA=0.25](Omega)(MOmega)
rput(A){$A$}pcline[nodesepA=0.25](A)(MA)
rput(B){$B$}pcline[nodesepA=0.25](B)(MB)
rput(C){$C$}pcline[nodesepA=0.2](C)(MC)
}%
}

NewDocumentCommand{codeclip}{m}{%
pscustom[linestyle=none]{%
code{/clip /eoclip load def}%
psframe(-maxdimen,-maxdimen)(maxdimen,maxdimen)
#1
}%
}

%ExplSyntaxOn
% We could use some automated macro creation but well
% 000
NewDocumentCommand{arealI}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
}%
codeclip{%
EreignisB
}%
codeclip{%
EreignisC
}%
}%
EreignisOmega*[#1][#2]%
endpsclip
}%
% 001
NewDocumentCommand{arealII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
}%
codeclip{%
EreignisB
}%
}%
EreignisC*[#1][#2]%
endpsclip
}
% 010
NewDocumentCommand{arealIII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
}%
codeclip{%
EreignisC
}%
}%
EreignisB*[#1][#2]%
endpsclip
}
% 011
NewDocumentCommand{arealIV}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisB
EreignisC
}%
codeclip{%
EreignisA
}%
}%
EreignisB*[#1][#2]%
EreignisC*[#1][#2]%
endpsclip
}
% 100
NewDocumentCommand{arealV}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisB
}%
codeclip{%
EreignisC
}%
}%
EreignisA*[#1][#2]%
endpsclip
}
% 101
NewDocumentCommand{arealVI}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisC
}%
codeclip{%
EreignisB
}%
}%
EreignisA*[#1][#2]%
EreignisC*[#1][#2]%
endpsclip
}
% 110
NewDocumentCommand{arealVII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
}%
codeclip{%
EreignisC
}%
}%
EreignisA*[#1][#2]%
EreignisB*[#1][#2]%
endpsclip
}
% 111
NewDocumentCommand{arealVIII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
}%
codeclip{%
EreignisA
EreignisC
}%
codeclip{%
EreignisB
EreignisC
}%
}%
EreignisA*[#1][#2]%
EreignisB*[#1][#2]%
EreignisC*[#1][#2]%
endpsclip
}
%ExplSyntaxOff

%xintverbosetrue
makeatletter
newcommandVennFromTeX[1]{%
VennFromTeX@main #1%
}%
defVennFromTeX@main$#1${%
begingroup
xintglobaldefstrue
defoverline##1{!(##1)}% or not(##1)
defcap{&&}% or 'and'
defcup{||}% or 'or'
defoplus{ 'xor' }%
defsetminus##1{ifx(##1&&!(else &&!(##1)fi}%
letbiglempty
letbigrempty
% ....
% (add above all needed extra definitions: letBiglempty etc...)
xintdeffunc MyBool(A, B, C) := #1;% #1 must use A, B, C only
endgroup
% we could make a loop here (using @Roman), but let's stay simple
% I trust xparse experts can wrap this up in macros allowing to customize
% the colors
% ATTENTION THAT THESE arealI...VIII ARE NOT THE SAME AS IN @THOMAS ANSWER
xintifboolexpr{MyBool(0, 0, 0)}{arealI[cyan][0.8]}{}%
xintifboolexpr{MyBool(0, 0, 1)}{arealII[cyan][0.8]}{}%
xintifboolexpr{MyBool(0, 1, 0)}{arealIII[cyan][0.8]}{}%
xintifboolexpr{MyBool(0, 1, 1)}{arealIV[cyan][0.8]}{}%
xintifboolexpr{MyBool(1, 0, 0)}{arealV[cyan][0.8]}{}%
xintifboolexpr{MyBool(1, 0, 1)}{arealVI[cyan][0.8]}{}%
xintifboolexpr{MyBool(1, 1, 0)}{arealVII[cyan][0.8]}{}%
xintifboolexpr{MyBool(1, 1, 1)}{arealVIII[cyan][0.8]}{}%
EndeEllipsen{$#1$}%
}%
makeatother

begin{document}

%testing if I, II, ..., VIII are as expected
% makeatletter
% xintFor*#1in{xintSeq{0}{7}}do{%
% begin{pspicture}(0,-1)(5,4)
% rput(2,0){thenumexpr1+#1}
% @nameuse{areal@Roman{numexpr1+#1}}[cyan][0.8]
% EndeEllipsen{}
% end{pspicture}
% }%
% end{document}


begin{pspicture}(0,-1)(5,4)
VennFromTeX{$Acap Bcap C$}%
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennFromTeX{$Acap (Bcup C)$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennFromTeX{$(overline{A}cap overline{B})cup C$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennFromTeX{$overline{A}setminus (Bcap C)$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennFromTeX{$(overline{A}setminus B)cap C$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennFromTeX{$(Asetminus B)cup (Bcap C)$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennFromTeX{$bigl((Acap B)cup (Acap C)bigr)setminus(Acap Bcap C)$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennFromTeX{$Aoplus Boplus C$}
end{pspicture}

end{document}


Produces



enter image description here



enter image description here



enter image description here



enter image description here



enter image description here



enter image description here



enter image description here



enter image description here







Here is code to generate all 256 Venn diagrams. Just insert it in body of above document and don't forget to add usepackage{xintbinhex} to preamble.



% generating all graphics

% 0<= n <= 255 has eight binary digits
% abcdefgh
% a=1 -> region VIII is included (A cap B cap C)
% b=1 -> region VII is included
% ...
% h=1 -> region I is included (overline{A}cap overline{B} cap overline{C})
% We want also to describe the region as a formula...
% We could use 8 xintFor loops #1, ..., #8, but then
% we still need to convert #1*7 to binary, #2*6, #3*5 etc...
% I thus use xintbinhex per convenience but ifodd would be enough
% As I use xintbinhex, I also use a single xintFor* loop

%defgobbleone#1{}%
defgobbletwo#1#2{}%
xintFor* #1 in {xintSeq{0}{255}}:
{%
xintDigitsOfxintDecToBin{thenumexpr256+#1relax}toRegions
% due to leading 1 there will be a shift of indexing in Regions
edefx{xintifboolexpr{Regions{thenumexpr9-0}}% 000
{unexpanded{allowbreakcup
overline{A}capoverline{B}capoverline{C}}}%
{}%
xintifboolexpr{Regions{9-1}}% 001
{unexpanded{allowbreakcup overline{A}capoverline{B}cap C}}%
{}%
xintifboolexpr{Regions{9-2}}% 010
{unexpanded{allowbreakcup overline{A}cap B capoverline{C}}}%
{}%
xintifboolexpr{Regions{9-3}}% 011
{unexpanded{allowbreakcup overline{A} cap B cap C}}%
{}%
xintifboolexpr{Regions{9-4}}% 100
{unexpanded{allowbreakcup Acap overline{B}cap overline{C}}}%
{}%
xintifboolexpr{Regions{9-5}}% 101
{unexpanded{allowbreakcup Acap overline{B}cap C}}%
{}%
xintifboolexpr{Regions{9-6}}% 110
{unexpanded{allowbreakcup Acap Bcap overline{C}}}%
{}%
xintifboolexpr{Regions{9-7}}% 111
{unexpanded{allowbreakcup Acap B cap C}}%
{}%
}%
xintifForFirst{defx{emptyset}}
{oodefx{expandaftergobbletwox}}%
begin{pspicture}(0,-2)(5,4)
% I will leave here each Region as individual call, so a color can
% be added by modifying this code
xintifboolexpr{Regions{9-0}}{arealI[cyan][0.8]}{}%
xintifboolexpr{Regions{9-1}}{arealII[cyan][0.8]}{}%
xintifboolexpr{Regions{9-2}}{arealIII[cyan][0.8]}{}%
xintifboolexpr{Regions{9-3}}{arealIV[cyan][0.8]}{}%
xintifboolexpr{Regions{9-4}}{arealV[cyan][0.8]}{}%
xintifboolexpr{Regions{9-5}}{arealVI[cyan][0.8]}{}%
xintifboolexpr{Regions{9-6}}{arealVII[cyan][0.8]}{}%
xintifboolexpr{Regions{9-7}}{arealVIII[cyan][0.8]}{}%
EndeEllipsen{parbox{4cm}{centering$x$}}%
end{pspicture}%
}%


Defect: the description of the set is as a disjoint union of atomic events. There might be some canonical shorter description but I never really thought about it. For example one of those diagram will represent $Omegasetminus A$ but this not the way it will be legended.



Here is how this example comes out (on page 16 of document with nothing else, i.e. it corresponds to #1 = 15 in the loop, 15=1111 means to keep atomic events 0=000, 1=001, 2=010, 3=011, which is complement of A in Omega.



enter image description here







Here is now with 4 sets.



This time, with TikZ code (I know neither PSTricks nor TikZ and can only survive from copying pre-existing drawing instructions; in this case I started from https://tex.stackexchange.com/a/100091/4686 by @JohnHammersley in 2013).



First I include an image of all atomic events, which are the regions to which the Atomic... macros in code next refer. (this was done for checking while preparing answer)



enter image description here



Here is the code for VennFromTeX, use it as VennFromTeX{$ set formula with A, B, C, D $}. Same instructions as above for three sets.
(one may wish to enlarge the syntax for example by allowing use of U or Omega and defining it in xintexpr to be simply 1, and similarly emptyset could be defined to be 0).



documentclass[12pt, tikz, border=10pt]{standalone}

usepackage{tikz}

usetikzlibrary{positioning,shapes.geometric}

usepackage{xintexpr}% for VennFromTeX


% For drawing
deffirstellip{(-1.6, 0) ellipse [x radius=3cm, y radius=1.5cm, rotate=-50]}
defsecondellip{(-0.3, 1cm) ellipse [x radius=3cm, y radius=1.5cm, rotate=-50]}
defthirdellip{(0.3, 1cm) ellipse [x radius=3cm, y radius=1.5cm, rotate=50]}
deffourthellip{(1.6, 0) ellipse [x radius=3cm, y radius=1.5cm, rotate=50]}

defbounding{(-5,-3) rectangle (5,4)}

% Elementary sets
% ABCD
% abcd a, b, c, d in {0, 1}
defAtomic{% 0000
begin{scope}[even odd rule]% exterior
clip firstellip (-5,-5) rectangle (5,5);
clip secondellip (-5,-5) rectangle (5,5);
clip thirdellip (-5,-5) rectangle (5,5);
clip fourthellip (-5,-5) rectangle (5,5);
fill[yellow] bounding;
end{scope}
}%
defAtomici{% 0001
begin{scope}[even odd rule]% fourth ellipse corner
clip firstellip (-5,-5) rectangle (5,5);
clip secondellip (-5,-5) rectangle (5,5);
clip thirdellip (-5,-5) rectangle (5,5);
fill[yellow] fourthellip;
end{scope}
}%
defAtomicii{% 0010
begin{scope}[even odd rule]% third ellipse corner
clip firstellip (-5,-5) rectangle (5,5);
clip secondellip (-5,-5) rectangle (5,5);
clip fourthellip (-5,-5) rectangle (5,5);
fill[yellow] thirdellip;
end{scope}
}%
defAtomiciii{% 0011
begin{scope}[even odd rule]%
clip firstellip (-5,-5) rectangle (5,5);
clip secondellip (-5,-5) rectangle (5,5);
clip fourthellip;
fill[yellow] thirdellip;
end{scope}
}%
defAtomiciv{% 0100
begin{scope}[even odd rule]% second ellipse corner
clip firstellip (-5,-5) rectangle (5,5);
clip thirdellip (-5,-5) rectangle (5,5);
clip fourthellip (-5,-5) rectangle (5,5);
fill[yellow] secondellip;
end{scope}
}%
defAtomicv{% 0101
begin{scope}[even odd rule]%
clip firstellip (-5,-5) rectangle (5,5);
clip thirdellip (-5,-5) rectangle (5,5);
clip fourthellip;
fill[yellow] secondellip;
end{scope}
}%
defAtomicvi{% 0110
begin{scope}[even odd rule]%
clip firstellip (-5,-5) rectangle (5,5);
clip thirdellip;
clip fourthellip (-5,-5) rectangle (5,5);
fill[yellow] secondellip;
end{scope}
}%
defAtomicvii{% 0111
begin{scope}[even odd rule]%
clip firstellip (-5,-5) rectangle (5,5);
clip thirdellip;
clip fourthellip;
fill[yellow] secondellip;
end{scope}
}%
defAtomicviii{% 1000
begin{scope}[even odd rule]%
clip secondellip (-5,-5) rectangle (5,5);
clip thirdellip (-5,-5) rectangle (5,5);
clip fourthellip (-5,-5) rectangle (5,5);
fill[yellow] firstellip;
end{scope}
}%
defAtomicix{% 1001
begin{scope}[even odd rule]%
clip secondellip (-5,-5) rectangle (5,5);
clip thirdellip (-5,-5) rectangle (5,5);
clip fourthellip;
fill[yellow] firstellip;
end{scope}
}%
defAtomicx{% 1010
begin{scope}[even odd rule]%
clip secondellip (-5,-5) rectangle (5,5);
clip thirdellip;
clip fourthellip (-5,-5) rectangle (5,5);
fill[yellow] firstellip;
end{scope}
}%
defAtomicxi{% 1011
begin{scope}[even odd rule]%
clip secondellip (-5,-5) rectangle (5,5);
clip thirdellip;
clip fourthellip;
fill[yellow] firstellip;
end{scope}
}%
defAtomicxii{% 1100
begin{scope}[even odd rule]%
clip secondellip;
clip thirdellip (-5,-5) rectangle (5,5);
clip fourthellip (-5,-5) rectangle (5,5);
fill[yellow] firstellip;
end{scope}
}%
defAtomicxiii{% 1101
begin{scope}[even odd rule]%
clip secondellip;
clip thirdellip (-5,-5) rectangle (5,5);
clip fourthellip;
fill[yellow] firstellip;
end{scope}
}%
defAtomicxiv{% 1110
begin{scope}[even odd rule]%
clip secondellip;
clip thirdellip;
clip fourthellip (-5,-5) rectangle (5,5);
fill[yellow] firstellip;
end{scope}
}%
defAtomicxv{% 1111
begin{scope}[even odd rule]%
clip secondellip;
clip thirdellip;
clip fourthellip;
fill[yellow] firstellip;
end{scope}
}%

makeatletter
newcommandVennFromTeX[1]{VennFromTeX@main #1}%

defVennFromTeX@main$#1${%
begingroup
xintglobaldefstrue
defoverline##1{!(##1)}% or not(##1)
defcap{&&}% or 'and'
defcup{||}% or 'or'
defoplus{ 'xor' }%
defsetminus##1{ifx(##1&&!(else &&!(##1)fi}%
letbiglempty
letbigrempty
% ....
% (add above all needed extra definitions: letBiglempty etc...)
xintdeffunc MyBool(A, B, C, D) := #1;% #1 must use A, B, C, Donly
endgroup
begin{tikzpicture}

xintFor* ##1 in {01}:
{%
xintFor* ##2 in {01}:
{%
xintFor* ##3 in {01}:
{%
xintFor* ##4 in {01}:
{%
xintifboolexpr{MyBool(##1, ##2, ##3, ##4)}
{csname
Atomicromannumeralnumexpr##1*8+##2*4+##3*2+##4endcsname}%
{}%
}%
}%
}%
}%
draw bounding;

% fill[white] firstellip;
% fill[white] secondellip;
% fill[white] thirdellip;
% fill[white] fourthellip;

draw firstellip node [label={[xshift=-2cm, yshift=-0.9cm]$A$}] {};
draw secondellip node [label={[xshift=-2.1cm, yshift=2.1cm]$B$}] {};
draw thirdellip node [label={[xshift=2.1cm, yshift=2.1cm]$C$}] {};
draw fourthellip node [label={[xshift=2cm, yshift=-0.9cm]$D$}] {};

draw bounding node [label=below left:$U$] {};

draw (0, 0) node [yshift=+4.4cm] {$#1$};

end{tikzpicture}
}%
makeatother
begin{document}

% xintverbosetrue

VennFromTeX{$Acap Bcap Ccap D$}

VennFromTeX{$(Acap B)cup (Ccap D)$}

VennFromTeX{$(overline{A}cupoverline{B})cap(overline{C}cupoverline{D})$}

% attention to use parentheses for disambiguating setminus

VennFromTeX{$(Acup B cup C) setminus(Bcup Ccup D)$}

VennFromTeX{$(Acup B cup C) cap (Bcup Ccup D)$}

VennFromTeX{$((Asetminus (Bcup Ccup D)) cup Bcap Ccap
D)setminus (Acap Bcap Ccap D)$}

end{document}


Be careful to read the caveat top regarding usage of setminus in input.



enter image description here



enter image description here



enter image description here



enter image description here



enter image description here



enter image description here



and finally



enter image description here






share|improve this answer























  • (+1) Thank you for your answer!
    – chishimotoji
    Dec 2 at 11:27










  • (+1) Wow, fantastic!
    – Thomas
    Dec 2 at 11:34










  • Encyclopedic answer
    – Diaa
    Dec 2 at 11:38










  • careful in first part of answer when inputting a long formula that it some parts may be cut off the page, check the parbox in second part how to work around that, and I also increased the vertical dimension.
    – jfbu
    Dec 2 at 12:46






  • 1




    @ArtificialStupidity I have to get dinner but just give me time to learn PSTricks and I can do with 4 sets afterwards...
    – jfbu
    Dec 2 at 18:39


















up vote
12
down vote













documentclass[pstricks]{standalone}
begin{document}
begin{pspicture}(-5,-5)(5,5)
pscustom[fillstyle=eofill,fillcolor=blue,linecolor=blue]{%
pscircle(1.5;90){3}
pscircle(1.5;-30){3}
pscircle(1.5;210){3}
}
end{pspicture}
end{document}


enter image description here



Some other simple example:



documentclass[pstricks]{standalone}
usepackage{pstricks}
begin{document}
begin{pspicture}(-3.2,-3.2)(3.2,3.2)
pscircle[fillstyle=solid,fillcolor=blue!40](0,0){3}
psclip{pscircle(-1,0.5){1.5}% these object(s) will clip
pscircle(1,0.5){1.5}}
pscircle[fillstyle=solid,fillcolor=red!40](0,-1){1.5}% from this object
endpsclip
pscircle(-1,0.5){1.5}% to get the clipped circle lines
pscircle(0,-1){1.5}
pscircle(1,0.5){1.5}
end{pspicture}

begin{pspicture}(-3.2,-3.2)(3.2,3.2)
pscircle[fillstyle=solid,fillcolor=blue!40](0,0){3}
psclip{pscircle(-1,0.5){1.5}}
pscircle[fillstyle=solid,fillcolor=red!40](0,-1){1.5}
pscircle[fillstyle=solid,fillcolor=red!40](1,0.5){1.5}
endpsclip
pscircle(-1,0.5){1.5}
pscircle(0,-1){1.5}
pscircle(1,0.5){1.5}
end{pspicture}

begin{pspicture}(-3.2,-3.2)(3.2,3.2)
pscircle[fillstyle=solid,fillcolor=blue!40](0,0){3}
psclip{pscircle(0,-1){1.5}}
pscircle[fillstyle=solid,fillcolor=red!40](-1,0.5){1.5}
pscircle[fillstyle=solid,fillcolor=red!40](1,0.5){1.5}
endpsclip
pscircle(-1,0.5){1.5}
pscircle(0,-1){1.5}
pscircle(1,0.5){1.5}
end{pspicture}

begin{pspicture}(-3.2,-3.2)(3.2,3.2)
pscircle[fillstyle=solid,fillcolor=blue!40](0,0){3}
psclip{pscircle(0,-1){1.5}}
pscircle[fillstyle=solid,fillcolor=red!40](1,0.5){1.5}
endpsclip
pscircle[fillstyle=solid,fillcolor=red!40](-1,0.5){1.5}
pscircle(0,-1){1.5}
pscircle(1,0.5){1.5}
end{pspicture}

end{document}


enter image description hereenter image description here






share|improve this answer



















  • 1




    I haven't known that there is a option as " fillstyle=eofill " before. It doesn't within PStrick User's Guide.
    – chishimotoji
    Nov 30 at 8:38






  • 1




    tug.org/PSTricks/main.cgi?file=Examples/Box/boxfill#2
    – Herbert
    Nov 30 at 11:20










  • I am really impressived by your code. Only with psclip,pscustom, you created some the interesting result. I have deleted more three comments before. May be my knowledge about psclip is not enough to generate several thing which I want. :((((
    – chishimotoji
    Dec 2 at 15:38








  • 2




    clipping is nothing else than taking a knife let it go along a circle or two corcles and cut everything from a given cake. psclip{the way of the knife} ... the cake .. endpsclip
    – Herbert
    Dec 2 at 15:41


















up vote
9
down vote













A TikZ solution for comparison purposes.



documentclass{article}
usepackage{tikz}
begin{document}
begin{tikzpicture}
draw[even odd rule,fill=blue](0,0)circle(3)(4,0)circle(3)(2,3)circle(3);
end{tikzpicture}
end{document}


Venn



Update: To answer @ArtificialStupidity's comment



Here is a solution with different coordinate points from those of the question asked by the OP. The centres of the circles form an equilateral triangle here.



documentclass{article}
usepackage{tikz}
begin{document}
begin{tikzpicture}
draw[even odd rule,fill=blue](0,0)circle(3)(3,0)circle(3)(60:3)circle(3);
end{tikzpicture}
end{document}


venn-2






share|improve this answer























  • @ArtificialStupidity Yes, as in the figure given as an example by the OP. I didn't change the coordinates.
    – AndréC
    Nov 30 at 12:05










  • +1 for the equilateral triangle Δ
    – stendarr
    Nov 30 at 14:03


















up vote
8
down vote













With this definitions every surface can be colored.



documentclass[pstricks]{standalone}
usepackage{pst-node}
usepackage{xparse,xintexpr}

defradiusK{xinttheiexpr[6] 2*sqrt(3)/3relax}

defKOEA{2.5,2}
defFOEA{radiusK,radiusK}

defKOEB{2,1}
defFOEB{radiusK,radiusK}

defKOEC{3,1}
defFOEC{radiusK,radiusK}

defKOEO{2.5,1.375}
defFOEO{2.5,2.5}

%uncomment the following lines to have ellipses
%defKOEA{1.9,2.2}
%defFOEA{1.4,1}
%
%defKOEB{3.3,2.2}
%defFOEB{1.2,1}
%
%defKOEC{2.75,1.4}
%defFOEC{1.4,1}
%
%defKOEO{2.5,2}
%defFOEO{2.5,2.0}

NewDocumentCommand{EreignisA}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEA)(FOEA)}{%
psellipse(KOEA)(FOEA)}%
}

NewDocumentCommand{EreignisB}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEB)(FOEB)}{%
psellipse(KOEB)(FOEB)}%
}

NewDocumentCommand{EreignisC}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEC)(FOEC)}{%
psellipse(KOEC)(FOEC)}%
}

NewDocumentCommand{EreignisOmega}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEO)(FOEO)}{%
psellipse(KOEO)(FOEO)}%
}

NewDocumentCommand{EndeEllipsen}{sm}{%
EreignisOmega%
pnodes(0.25,3.75){Omega}(0.25,0.25){A}(4.75,3.75){B}(4.75,0.25){C}(2.5,-0.5){E}
pnodes(0.7,3.36){MOmega}(0.85,1.55){MA}(4,3){MB}(3.8,0.75){MC}
EreignisA
EreignisB
EreignisC
rput[t](E){#2}%
IfBooleanF{#1}{%
rput(Omega){$Omega$}pcline[nodesepA=0.25](Omega)(MOmega)
rput(A){$A$}pcline[nodesepA=0.25](A)(MA)
rput(B){$B$}pcline[nodesepA=0.25](B)(MB)
rput(C){$C$}pcline[nodesepA=0.2](C)(MC)
}%
}

NewDocumentCommand{codeclip}{m}{%
pscustom[linestyle=none]{%
code{/clip /eoclip load def}%
psframe(-maxdimen,-maxdimen)(maxdimen,maxdimen)
#1
}%
}

NewDocumentCommand{arealI}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
}%
codeclip{%
EreignisB
}%
codeclip{%
EreignisC
}%
}%
EreignisOmega*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisB
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealIII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealIV}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisB*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealV}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisB
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealVI}{O{cyan}!O{0.8}}{%
psclip{EreignisB}
psclip{EreignisC}%
EreignisA*[#1][#2]%
endpsclip
endpsclip
}

NewDocumentCommand{arealVII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisA
}%
}%
EreignisC*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealVIII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
}%
codeclip{%
EreignisB
}%
}%
EreignisC*[#1][#2]%
endpsclip
}

begin{document}


begin{pspicture}[shift=-4](0,-1)(5,4)
arealI
EndeEllipsen*{$Asetminus C$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealVI
EndeEllipsen*{$Acap Bcap C$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealIII
arealV
arealVI
EndeEllipsen*{$Acap (Bcup C)$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealI
EreignisC*%
EndeEllipsen*{$(overline{A}cap overline{B})cup C$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealI
arealIV
arealVIII
EndeEllipsen*{$overline{A}setminus (Bcap C)$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealVIII
EndeEllipsen*{$(overline{A}setminus B)cap C$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealII
arealV
arealVI
arealVII
EndeEllipsen*{$(Asetminus B)cup (Bcap C)$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealIII
arealV
EndeEllipsen*{$bigl((Acap B)cup (Acap C)bigr)setminus(Acap Bcap C)$}
end{pspicture}


end{document}




Perhaps you want to check out this.



documentclass[pstricks]{standalone}
usepackage{pst-node}
usepackage{xparse,xintexpr}

%defradiusK{xinttheiexpr[6] 2*sqrt(3)/3relax}
%
%defKOEA{2.5,2}
%defFOEA{radiusK,radiusK}
%
%defKOEB{2,1}
%defFOEB{radiusK,radiusK}
%
%defKOEC{3,1}
%defFOEC{radiusK,radiusK}
%
%defKOEO{2.5,1.375}
%defFOEO{2.5,2.5}

%uncomment the following lines to have ellipses
defKOEA{1.9,2.2}
defFOEA{1.4,1}

defKOEB{3.3,2.2}
defFOEB{1.2,1}

defKOEC{2.75,1.4}
defFOEC{1.4,1}

defKOEO{2.5,2}
defFOEO{2.5,2.0}

NewDocumentCommand{EreignisA}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEA)(FOEA)}{%
psellipse(KOEA)(FOEA)}%
}

NewDocumentCommand{EreignisB}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEB)(FOEB)}{%
psellipse(KOEB)(FOEB)}%
}

NewDocumentCommand{EreignisC}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEC)(FOEC)}{%
psellipse(KOEC)(FOEC)}%
}

NewDocumentCommand{EreignisOmega}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEO)(FOEO)}{%
psellipse(KOEO)(FOEO)}%
}

NewDocumentCommand{EndeEllipsen}{sm}{%
EreignisOmega%
pnodes(0.25,3.75){Omega}(0.25,0.25){A}(4.75,3.75){B}(4.75,0.25){C}(2.5,-0.5){E}
pnodes(0.7,3.36){MOmega}(0.85,1.55){MA}(4,3){MB}(3.8,0.75){MC}
EreignisA
EreignisB
EreignisC
rput[t](E){#2}%
IfBooleanF{#1}{%
rput(Omega){$Omega$}pcline[nodesepA=0.25](Omega)(MOmega)
rput(A){$A$}pcline[nodesepA=0.25](A)(MA)
rput(B){$B$}pcline[nodesepA=0.25](B)(MB)
rput(C){$C$}pcline[nodesepA=0.2](C)(MC)
}%
}

NewDocumentCommand{codeclip}{m}{%
pscustom[linestyle=none]{%
code{/clip /eoclip load def}%
psframe(-maxdimen,-maxdimen)(maxdimen,maxdimen)
#1
}%
}

NewDocumentCommand{arealI}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
}%
codeclip{%
EreignisB
}%
codeclip{%
EreignisC
}%
}%
EreignisOmega*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisB
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealIII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealIV}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisB*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealV}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisB
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealVI}{O{cyan}!O{0.8}}{%
psclip{EreignisB}
psclip{EreignisC}%
EreignisA*[#1][#2]%
endpsclip
endpsclip
}

NewDocumentCommand{arealVII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisA
}%
}%
EreignisC*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealVIII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
}%
codeclip{%
EreignisB
}%
}%
EreignisC*[#1][#2]%
endpsclip
}

begin{document}


begin{pspicture}[shift=-4](0,-1)(5,4)
arealI
EndeEllipsen{$Asetminus C$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealVI
EndeEllipsen{$Acap Bcap C$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealIII
arealV
arealVI
EndeEllipsen{$Acap (Bcup C)$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealI
EreignisC*%
EndeEllipsen{$(overline{A}cap overline{B})cup C$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealI
arealIV
arealVIII
EndeEllipsen{$overline{A}setminus (Bcap C)$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealVIII
EndeEllipsen{$(overline{A}setminus B)cap C$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealII
arealV
arealVI
arealVII
EndeEllipsen{$(Asetminus B)cup (Bcap C)$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealIII
arealV
EndeEllipsen{$bigl((Acap B)cup (Acap C)bigr)setminus(Acap Bcap C)$}
end{pspicture}


end{document}




With the help of xint-package using xintFor and xintForpair you can write



VennIII{(2,red),(4,cyan),(6,magenta),(8,green)}{Text}%


so every surface becomes an own color, or you write



VennIII[blue](0.5){2,4,6,8}{Text}%


and all becomes color blue with opacity 0.5.



documentclass[pstricks]{standalone}
usepackage{pst-node}
usepackage{xparse,xintexpr}

defKOEA{1.9,2.2}
defFOEA{1.4,1}

defKOEB{3.3,2.2}
defFOEB{1.2,1}

defKOEC{2.75,1.4}
defFOEC{1.4,1}

defKOEO{2.5,2}
defFOEO{2.5,2.0}

NewDocumentCommand{EreignisA}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEA)(FOEA)}{%
psellipse(KOEA)(FOEA)}%
}

NewDocumentCommand{EreignisB}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEB)(FOEB)}{%
psellipse(KOEB)(FOEB)}%
}

NewDocumentCommand{EreignisC}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEC)(FOEC)}{%
psellipse(KOEC)(FOEC)}%
}

NewDocumentCommand{EreignisOmega}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEO)(FOEO)}{%
psellipse(KOEO)(FOEO)}%
}

NewDocumentCommand{EndeEllipsen}{sm}{%
EreignisOmega%
pnodes(0.25,3.75){Omega}(0.25,0.25){A}(4.75,3.75){B}(4.75,0.25){C}(2.5,-0.5){E}
pnodes(0.7,3.36){MOmega}(0.85,1.55){MA}(4,3){MB}(3.8,0.75){MC}
EreignisA
EreignisB
EreignisC
rput[t](E){#2}%
IfBooleanF{#1}{%
rput(Omega){$Omega$}pcline[nodesepA=0.25](Omega)(MOmega)
rput(A){$A$}pcline[nodesepA=0.25](A)(MA)
rput(B){$B$}pcline[nodesepA=0.25](B)(MB)
rput(C){$C$}pcline[nodesepA=0.2](C)(MC)
}%
}

NewDocumentCommand{codeclip}{m}{%
pscustom[linestyle=none]{%
code{/clip /eoclip load def}%
psframe(-maxdimen,-maxdimen)(maxdimen,maxdimen)
#1
}%
}

%ExplSyntaxOn
NewDocumentCommand{arealI}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
}%
codeclip{%
EreignisB
}%
codeclip{%
EreignisC
}%
}%
EreignisOmega*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisB
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealIII}{!O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealIV}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisB*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealV}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisB
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealVI}{O{cyan}!O{0.8}}{%
psclip{EreignisB}%
psclip{EreignisC}%
EreignisA*[#1][#2]%
endpsclip
endpsclip
}

NewDocumentCommand{arealVII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisA
}%
}%
EreignisC*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealVIII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
}%
codeclip{%
EreignisB
}%
}%
EreignisC*[#1][#2]%
endpsclip
}
%ExplSyntaxOff

NewDocumentCommand{VIIIarea}{O{cyan}O{0.8}m}{%
xintifboolexpr{#3=1}{arealI[#1][#2]}{}%
xintifboolexpr{#3=2}{arealII[#1][#2]}{}%
xintifboolexpr{#3=3}{arealIII[#1][#2]}{}%
xintifboolexpr{#3=4}{arealIV[#1][#2]}{}%
xintifboolexpr{#3=5}{arealV[#1][#2]}{}%
xintifboolexpr{#3=6}{arealVI[#1][#2]}{}%
xintifboolexpr{#3=7}{arealVII[#1][#2]}{}%
xintifboolexpr{#3=8}{arealVIII[#1][#2]}{}%
}

NewDocumentCommand{VennIII}{oD(){0.8}m!g}{%
IfValueTF{#1}%
{%
xintFor ##1 in {#3}do {VIIIarea[#1][#2]{##1}}%
}%
{%
xintForpair ##1##2 in {#3}do {VIIIarea[##2][#2]{##1}}%
}%
EndeEllipsen{IfValueT{#4}{#4}}%
}

begin{document}

begin{pspicture}(0,-1)(5,4)
VennIII{(2,red),(4,cyan),(6,magenta),(8,green)}{Text}%
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennIII[orange]{6}{$Acap Bcap C$}%
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennIII[cyan]{3,5,6}{$Acap (Bcup C)$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennIII[magenta](0.5){1,5,6,7}{$(overline{A}cap overline{B})cup C$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennIII[green](0.2){1,4,8}{$overline{A}setminus (Bcap C)$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennIII[cyan]{8}{$(overline{A}setminus B)cap C$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennIII(1){(2,cyan),(5,orange),(6,green),(7,magenta)}{$(Asetminus B)cup (Bcap C)$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennIII[cyan]{3,5}{$bigl((Acap B)cup (Acap C)bigr)setminus(Acap Bcap C)$}
end{pspicture}


end{document}


enter image description here






share|improve this answer























  • Hey bro, is there a shorter way? Your code seem being enormously complex.
    – chishimotoji
    Dec 1 at 10:48










  • This is because I first create all sorts of single surfaces by clipping. Then you can get any desired combination by fading in this area. This is a bit dull, but much easier to use. For example for area 2, area 4 and area 8you can use begin{pspicture}[shift=-4](0,-1)(5,4) arealI arealIV arealVIII EndeEllipsen{$overline{A}setminus (Bcap C)$} end{pspicture}
    – Thomas
    Dec 1 at 13:45












  • A answer sentence is very good.
    – chishimotoji
    Dec 2 at 0:47











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f462520%2fhow-to-draw-a-%25e2%258a%2595-b-%25e2%258a%2595-c-as-a-venn-diagram%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























5 Answers
5






active

oldest

votes








5 Answers
5






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
19
down vote



accepted










A PSTricks solution just for fun!



Answer 1



documentclass[pstricks]{standalone}
begin{document}
begin{pspicture}(-5,-5)(5,5)
pscustom[fillstyle=eofill,fillcolor=blue]
{
pscircle(1.5;90){3}
pscircle(1.5;-30){3}
pscircle(1.5;210){3}
}
end{pspicture}
end{document}


enter image description here



The stroke color is left black just for a trivial reason.



Cartesian coordinates are used in response to the request.



documentclass[pstricks]{standalone}
begin{document}
begin{pspicture}(-5,-5)(5,5)
pscustom[fillstyle=eofill,fillcolor=blue]
{
pscircle(0,1.5){3}
pscircle(1.29,-0.75){3}
pscircle(-1.29,-0.75){3}
}
end{pspicture}
end{document}


Answer 2



Non-zero winding rule:



documentclass[pstricks,border=12pt]{standalone}
begin{document}
begin{pspicture}[showgrid=t](-3,-3)(3,3)
pscustom[fillstyle=solid,fillcolor=red]
{
pscircle{1}
pscircle{2}
}
end{pspicture}
end{document}


enter image description here



Non-zero winding rule:



documentclass[pstricks,border=12pt]{standalone}
begin{document}
begin{pspicture}[showgrid=t](-3,-3)(3,3)
pscustom[fillstyle=solid,fillcolor=red]
{
psarcn(0,0){1}{360}{0}
pscircle{2}
}
end{pspicture}
end{document}


enter image description here



Even-odd rule:



documentclass[pstricks,border=12pt]{standalone}
begin{document}
begin{pspicture}[showgrid=t](-3,-3)(3,3)
pscustom[fillstyle=eofill,fillcolor=red]
{
pscircle{1}
pscircle{2}
}
end{pspicture}
end{document}


enter image description here






share|improve this answer























  • As your code, the important option is " fillstyle=eofill " . I haven't known that there is a option as " fillstyle=eofill " before. It doesn't within PStrick User's Guide.
    – chishimotoji
    Nov 30 at 8:42















up vote
19
down vote



accepted










A PSTricks solution just for fun!



Answer 1



documentclass[pstricks]{standalone}
begin{document}
begin{pspicture}(-5,-5)(5,5)
pscustom[fillstyle=eofill,fillcolor=blue]
{
pscircle(1.5;90){3}
pscircle(1.5;-30){3}
pscircle(1.5;210){3}
}
end{pspicture}
end{document}


enter image description here



The stroke color is left black just for a trivial reason.



Cartesian coordinates are used in response to the request.



documentclass[pstricks]{standalone}
begin{document}
begin{pspicture}(-5,-5)(5,5)
pscustom[fillstyle=eofill,fillcolor=blue]
{
pscircle(0,1.5){3}
pscircle(1.29,-0.75){3}
pscircle(-1.29,-0.75){3}
}
end{pspicture}
end{document}


Answer 2



Non-zero winding rule:



documentclass[pstricks,border=12pt]{standalone}
begin{document}
begin{pspicture}[showgrid=t](-3,-3)(3,3)
pscustom[fillstyle=solid,fillcolor=red]
{
pscircle{1}
pscircle{2}
}
end{pspicture}
end{document}


enter image description here



Non-zero winding rule:



documentclass[pstricks,border=12pt]{standalone}
begin{document}
begin{pspicture}[showgrid=t](-3,-3)(3,3)
pscustom[fillstyle=solid,fillcolor=red]
{
psarcn(0,0){1}{360}{0}
pscircle{2}
}
end{pspicture}
end{document}


enter image description here



Even-odd rule:



documentclass[pstricks,border=12pt]{standalone}
begin{document}
begin{pspicture}[showgrid=t](-3,-3)(3,3)
pscustom[fillstyle=eofill,fillcolor=red]
{
pscircle{1}
pscircle{2}
}
end{pspicture}
end{document}


enter image description here






share|improve this answer























  • As your code, the important option is " fillstyle=eofill " . I haven't known that there is a option as " fillstyle=eofill " before. It doesn't within PStrick User's Guide.
    – chishimotoji
    Nov 30 at 8:42













up vote
19
down vote



accepted







up vote
19
down vote



accepted






A PSTricks solution just for fun!



Answer 1



documentclass[pstricks]{standalone}
begin{document}
begin{pspicture}(-5,-5)(5,5)
pscustom[fillstyle=eofill,fillcolor=blue]
{
pscircle(1.5;90){3}
pscircle(1.5;-30){3}
pscircle(1.5;210){3}
}
end{pspicture}
end{document}


enter image description here



The stroke color is left black just for a trivial reason.



Cartesian coordinates are used in response to the request.



documentclass[pstricks]{standalone}
begin{document}
begin{pspicture}(-5,-5)(5,5)
pscustom[fillstyle=eofill,fillcolor=blue]
{
pscircle(0,1.5){3}
pscircle(1.29,-0.75){3}
pscircle(-1.29,-0.75){3}
}
end{pspicture}
end{document}


Answer 2



Non-zero winding rule:



documentclass[pstricks,border=12pt]{standalone}
begin{document}
begin{pspicture}[showgrid=t](-3,-3)(3,3)
pscustom[fillstyle=solid,fillcolor=red]
{
pscircle{1}
pscircle{2}
}
end{pspicture}
end{document}


enter image description here



Non-zero winding rule:



documentclass[pstricks,border=12pt]{standalone}
begin{document}
begin{pspicture}[showgrid=t](-3,-3)(3,3)
pscustom[fillstyle=solid,fillcolor=red]
{
psarcn(0,0){1}{360}{0}
pscircle{2}
}
end{pspicture}
end{document}


enter image description here



Even-odd rule:



documentclass[pstricks,border=12pt]{standalone}
begin{document}
begin{pspicture}[showgrid=t](-3,-3)(3,3)
pscustom[fillstyle=eofill,fillcolor=red]
{
pscircle{1}
pscircle{2}
}
end{pspicture}
end{document}


enter image description here






share|improve this answer














A PSTricks solution just for fun!



Answer 1



documentclass[pstricks]{standalone}
begin{document}
begin{pspicture}(-5,-5)(5,5)
pscustom[fillstyle=eofill,fillcolor=blue]
{
pscircle(1.5;90){3}
pscircle(1.5;-30){3}
pscircle(1.5;210){3}
}
end{pspicture}
end{document}


enter image description here



The stroke color is left black just for a trivial reason.



Cartesian coordinates are used in response to the request.



documentclass[pstricks]{standalone}
begin{document}
begin{pspicture}(-5,-5)(5,5)
pscustom[fillstyle=eofill,fillcolor=blue]
{
pscircle(0,1.5){3}
pscircle(1.29,-0.75){3}
pscircle(-1.29,-0.75){3}
}
end{pspicture}
end{document}


Answer 2



Non-zero winding rule:



documentclass[pstricks,border=12pt]{standalone}
begin{document}
begin{pspicture}[showgrid=t](-3,-3)(3,3)
pscustom[fillstyle=solid,fillcolor=red]
{
pscircle{1}
pscircle{2}
}
end{pspicture}
end{document}


enter image description here



Non-zero winding rule:



documentclass[pstricks,border=12pt]{standalone}
begin{document}
begin{pspicture}[showgrid=t](-3,-3)(3,3)
pscustom[fillstyle=solid,fillcolor=red]
{
psarcn(0,0){1}{360}{0}
pscircle{2}
}
end{pspicture}
end{document}


enter image description here



Even-odd rule:



documentclass[pstricks,border=12pt]{standalone}
begin{document}
begin{pspicture}[showgrid=t](-3,-3)(3,3)
pscustom[fillstyle=eofill,fillcolor=red]
{
pscircle{1}
pscircle{2}
}
end{pspicture}
end{document}


enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 30 at 9:06

























answered Nov 30 at 7:59









Artificial Stupidity

4,44111038




4,44111038












  • As your code, the important option is " fillstyle=eofill " . I haven't known that there is a option as " fillstyle=eofill " before. It doesn't within PStrick User's Guide.
    – chishimotoji
    Nov 30 at 8:42


















  • As your code, the important option is " fillstyle=eofill " . I haven't known that there is a option as " fillstyle=eofill " before. It doesn't within PStrick User's Guide.
    – chishimotoji
    Nov 30 at 8:42
















As your code, the important option is " fillstyle=eofill " . I haven't known that there is a option as " fillstyle=eofill " before. It doesn't within PStrick User's Guide.
– chishimotoji
Nov 30 at 8:42




As your code, the important option is " fillstyle=eofill " . I haven't known that there is a option as " fillstyle=eofill " before. It doesn't within PStrick User's Guide.
– chishimotoji
Nov 30 at 8:42










up vote
15
down vote



+500










Here is an answer based on the one by @Thomas. Differences




  • the "elementary" regions I, II, ..., VIII are not numbered the same. My numbering is that "N" is the Roman number of "n+1" where "n" in binary is "abc", and the region is intersection of A or not A with B or not B with C or not C according to a, b, c = 0 or 1. (Boolean logic)


  • the macro needs only one input: a TeX formula for the set. Please enrich the syntax by adding suitable definitions converting TeX math macros into Boolean logic notation, as understood by xintexpr


  • I have dropped all fancy customization of colors, but xparse virtuosos will add the fancy optional arguments to re-install it if needed.



Thus, the big point here is that xintexpr computes automatically from the TeX typesetting formula which regions are to be filled in diagram.




attention to setminus it must be used either with parentheses setminus (...) or without but then with only one letter setminus A
ok, setminus Acap B not ok, because the translation here to xintexpr
boolean will do naively something equivalent to and not(A) and B, not the expected and not(A and B). In short, you must treat setminus as having maximally tying precedence.




documentclass[pstricks, border=10pt]{standalone}
usepackage{pst-node}
usepackage{xparse,xintexpr}

defKOEA{1.9,2.2}
defFOEA{1.4,1}

defKOEB{3.3,2.2}
defFOEB{1.2,1}

defKOEC{2.75,1.4}
defFOEC{1.4,1}

defKOEO{2.5,2}
defFOEO{2.5,2.0}

NewDocumentCommand{EreignisA}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEA)(FOEA)}{%
psellipse(KOEA)(FOEA)}%
}

NewDocumentCommand{EreignisB}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEB)(FOEB)}{%
psellipse(KOEB)(FOEB)}%
}

NewDocumentCommand{EreignisC}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEC)(FOEC)}{%
psellipse(KOEC)(FOEC)}%
}

NewDocumentCommand{EreignisOmega}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEO)(FOEO)}{%
psellipse(KOEO)(FOEO)}%
}

NewDocumentCommand{EndeEllipsen}{sm}{%
EreignisOmega%
pnodes(0.25,3.75){Omega}(0.25,0.25){A}(4.75,3.75){B}(4.75,0.25){C}(2.5,-0.5){E}
pnodes(0.7,3.36){MOmega}(0.85,1.55){MA}(4,3){MB}(3.8,0.75){MC}
EreignisA
EreignisB
EreignisC
rput[t](E){#2}%
IfBooleanF{#1}{%
rput(Omega){$Omega$}pcline[nodesepA=0.25](Omega)(MOmega)
rput(A){$A$}pcline[nodesepA=0.25](A)(MA)
rput(B){$B$}pcline[nodesepA=0.25](B)(MB)
rput(C){$C$}pcline[nodesepA=0.2](C)(MC)
}%
}

NewDocumentCommand{codeclip}{m}{%
pscustom[linestyle=none]{%
code{/clip /eoclip load def}%
psframe(-maxdimen,-maxdimen)(maxdimen,maxdimen)
#1
}%
}

%ExplSyntaxOn
% We could use some automated macro creation but well
% 000
NewDocumentCommand{arealI}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
}%
codeclip{%
EreignisB
}%
codeclip{%
EreignisC
}%
}%
EreignisOmega*[#1][#2]%
endpsclip
}%
% 001
NewDocumentCommand{arealII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
}%
codeclip{%
EreignisB
}%
}%
EreignisC*[#1][#2]%
endpsclip
}
% 010
NewDocumentCommand{arealIII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
}%
codeclip{%
EreignisC
}%
}%
EreignisB*[#1][#2]%
endpsclip
}
% 011
NewDocumentCommand{arealIV}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisB
EreignisC
}%
codeclip{%
EreignisA
}%
}%
EreignisB*[#1][#2]%
EreignisC*[#1][#2]%
endpsclip
}
% 100
NewDocumentCommand{arealV}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisB
}%
codeclip{%
EreignisC
}%
}%
EreignisA*[#1][#2]%
endpsclip
}
% 101
NewDocumentCommand{arealVI}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisC
}%
codeclip{%
EreignisB
}%
}%
EreignisA*[#1][#2]%
EreignisC*[#1][#2]%
endpsclip
}
% 110
NewDocumentCommand{arealVII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
}%
codeclip{%
EreignisC
}%
}%
EreignisA*[#1][#2]%
EreignisB*[#1][#2]%
endpsclip
}
% 111
NewDocumentCommand{arealVIII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
}%
codeclip{%
EreignisA
EreignisC
}%
codeclip{%
EreignisB
EreignisC
}%
}%
EreignisA*[#1][#2]%
EreignisB*[#1][#2]%
EreignisC*[#1][#2]%
endpsclip
}
%ExplSyntaxOff

%xintverbosetrue
makeatletter
newcommandVennFromTeX[1]{%
VennFromTeX@main #1%
}%
defVennFromTeX@main$#1${%
begingroup
xintglobaldefstrue
defoverline##1{!(##1)}% or not(##1)
defcap{&&}% or 'and'
defcup{||}% or 'or'
defoplus{ 'xor' }%
defsetminus##1{ifx(##1&&!(else &&!(##1)fi}%
letbiglempty
letbigrempty
% ....
% (add above all needed extra definitions: letBiglempty etc...)
xintdeffunc MyBool(A, B, C) := #1;% #1 must use A, B, C only
endgroup
% we could make a loop here (using @Roman), but let's stay simple
% I trust xparse experts can wrap this up in macros allowing to customize
% the colors
% ATTENTION THAT THESE arealI...VIII ARE NOT THE SAME AS IN @THOMAS ANSWER
xintifboolexpr{MyBool(0, 0, 0)}{arealI[cyan][0.8]}{}%
xintifboolexpr{MyBool(0, 0, 1)}{arealII[cyan][0.8]}{}%
xintifboolexpr{MyBool(0, 1, 0)}{arealIII[cyan][0.8]}{}%
xintifboolexpr{MyBool(0, 1, 1)}{arealIV[cyan][0.8]}{}%
xintifboolexpr{MyBool(1, 0, 0)}{arealV[cyan][0.8]}{}%
xintifboolexpr{MyBool(1, 0, 1)}{arealVI[cyan][0.8]}{}%
xintifboolexpr{MyBool(1, 1, 0)}{arealVII[cyan][0.8]}{}%
xintifboolexpr{MyBool(1, 1, 1)}{arealVIII[cyan][0.8]}{}%
EndeEllipsen{$#1$}%
}%
makeatother

begin{document}

%testing if I, II, ..., VIII are as expected
% makeatletter
% xintFor*#1in{xintSeq{0}{7}}do{%
% begin{pspicture}(0,-1)(5,4)
% rput(2,0){thenumexpr1+#1}
% @nameuse{areal@Roman{numexpr1+#1}}[cyan][0.8]
% EndeEllipsen{}
% end{pspicture}
% }%
% end{document}


begin{pspicture}(0,-1)(5,4)
VennFromTeX{$Acap Bcap C$}%
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennFromTeX{$Acap (Bcup C)$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennFromTeX{$(overline{A}cap overline{B})cup C$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennFromTeX{$overline{A}setminus (Bcap C)$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennFromTeX{$(overline{A}setminus B)cap C$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennFromTeX{$(Asetminus B)cup (Bcap C)$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennFromTeX{$bigl((Acap B)cup (Acap C)bigr)setminus(Acap Bcap C)$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennFromTeX{$Aoplus Boplus C$}
end{pspicture}

end{document}


Produces



enter image description here



enter image description here



enter image description here



enter image description here



enter image description here



enter image description here



enter image description here



enter image description here







Here is code to generate all 256 Venn diagrams. Just insert it in body of above document and don't forget to add usepackage{xintbinhex} to preamble.



% generating all graphics

% 0<= n <= 255 has eight binary digits
% abcdefgh
% a=1 -> region VIII is included (A cap B cap C)
% b=1 -> region VII is included
% ...
% h=1 -> region I is included (overline{A}cap overline{B} cap overline{C})
% We want also to describe the region as a formula...
% We could use 8 xintFor loops #1, ..., #8, but then
% we still need to convert #1*7 to binary, #2*6, #3*5 etc...
% I thus use xintbinhex per convenience but ifodd would be enough
% As I use xintbinhex, I also use a single xintFor* loop

%defgobbleone#1{}%
defgobbletwo#1#2{}%
xintFor* #1 in {xintSeq{0}{255}}:
{%
xintDigitsOfxintDecToBin{thenumexpr256+#1relax}toRegions
% due to leading 1 there will be a shift of indexing in Regions
edefx{xintifboolexpr{Regions{thenumexpr9-0}}% 000
{unexpanded{allowbreakcup
overline{A}capoverline{B}capoverline{C}}}%
{}%
xintifboolexpr{Regions{9-1}}% 001
{unexpanded{allowbreakcup overline{A}capoverline{B}cap C}}%
{}%
xintifboolexpr{Regions{9-2}}% 010
{unexpanded{allowbreakcup overline{A}cap B capoverline{C}}}%
{}%
xintifboolexpr{Regions{9-3}}% 011
{unexpanded{allowbreakcup overline{A} cap B cap C}}%
{}%
xintifboolexpr{Regions{9-4}}% 100
{unexpanded{allowbreakcup Acap overline{B}cap overline{C}}}%
{}%
xintifboolexpr{Regions{9-5}}% 101
{unexpanded{allowbreakcup Acap overline{B}cap C}}%
{}%
xintifboolexpr{Regions{9-6}}% 110
{unexpanded{allowbreakcup Acap Bcap overline{C}}}%
{}%
xintifboolexpr{Regions{9-7}}% 111
{unexpanded{allowbreakcup Acap B cap C}}%
{}%
}%
xintifForFirst{defx{emptyset}}
{oodefx{expandaftergobbletwox}}%
begin{pspicture}(0,-2)(5,4)
% I will leave here each Region as individual call, so a color can
% be added by modifying this code
xintifboolexpr{Regions{9-0}}{arealI[cyan][0.8]}{}%
xintifboolexpr{Regions{9-1}}{arealII[cyan][0.8]}{}%
xintifboolexpr{Regions{9-2}}{arealIII[cyan][0.8]}{}%
xintifboolexpr{Regions{9-3}}{arealIV[cyan][0.8]}{}%
xintifboolexpr{Regions{9-4}}{arealV[cyan][0.8]}{}%
xintifboolexpr{Regions{9-5}}{arealVI[cyan][0.8]}{}%
xintifboolexpr{Regions{9-6}}{arealVII[cyan][0.8]}{}%
xintifboolexpr{Regions{9-7}}{arealVIII[cyan][0.8]}{}%
EndeEllipsen{parbox{4cm}{centering$x$}}%
end{pspicture}%
}%


Defect: the description of the set is as a disjoint union of atomic events. There might be some canonical shorter description but I never really thought about it. For example one of those diagram will represent $Omegasetminus A$ but this not the way it will be legended.



Here is how this example comes out (on page 16 of document with nothing else, i.e. it corresponds to #1 = 15 in the loop, 15=1111 means to keep atomic events 0=000, 1=001, 2=010, 3=011, which is complement of A in Omega.



enter image description here







Here is now with 4 sets.



This time, with TikZ code (I know neither PSTricks nor TikZ and can only survive from copying pre-existing drawing instructions; in this case I started from https://tex.stackexchange.com/a/100091/4686 by @JohnHammersley in 2013).



First I include an image of all atomic events, which are the regions to which the Atomic... macros in code next refer. (this was done for checking while preparing answer)



enter image description here



Here is the code for VennFromTeX, use it as VennFromTeX{$ set formula with A, B, C, D $}. Same instructions as above for three sets.
(one may wish to enlarge the syntax for example by allowing use of U or Omega and defining it in xintexpr to be simply 1, and similarly emptyset could be defined to be 0).



documentclass[12pt, tikz, border=10pt]{standalone}

usepackage{tikz}

usetikzlibrary{positioning,shapes.geometric}

usepackage{xintexpr}% for VennFromTeX


% For drawing
deffirstellip{(-1.6, 0) ellipse [x radius=3cm, y radius=1.5cm, rotate=-50]}
defsecondellip{(-0.3, 1cm) ellipse [x radius=3cm, y radius=1.5cm, rotate=-50]}
defthirdellip{(0.3, 1cm) ellipse [x radius=3cm, y radius=1.5cm, rotate=50]}
deffourthellip{(1.6, 0) ellipse [x radius=3cm, y radius=1.5cm, rotate=50]}

defbounding{(-5,-3) rectangle (5,4)}

% Elementary sets
% ABCD
% abcd a, b, c, d in {0, 1}
defAtomic{% 0000
begin{scope}[even odd rule]% exterior
clip firstellip (-5,-5) rectangle (5,5);
clip secondellip (-5,-5) rectangle (5,5);
clip thirdellip (-5,-5) rectangle (5,5);
clip fourthellip (-5,-5) rectangle (5,5);
fill[yellow] bounding;
end{scope}
}%
defAtomici{% 0001
begin{scope}[even odd rule]% fourth ellipse corner
clip firstellip (-5,-5) rectangle (5,5);
clip secondellip (-5,-5) rectangle (5,5);
clip thirdellip (-5,-5) rectangle (5,5);
fill[yellow] fourthellip;
end{scope}
}%
defAtomicii{% 0010
begin{scope}[even odd rule]% third ellipse corner
clip firstellip (-5,-5) rectangle (5,5);
clip secondellip (-5,-5) rectangle (5,5);
clip fourthellip (-5,-5) rectangle (5,5);
fill[yellow] thirdellip;
end{scope}
}%
defAtomiciii{% 0011
begin{scope}[even odd rule]%
clip firstellip (-5,-5) rectangle (5,5);
clip secondellip (-5,-5) rectangle (5,5);
clip fourthellip;
fill[yellow] thirdellip;
end{scope}
}%
defAtomiciv{% 0100
begin{scope}[even odd rule]% second ellipse corner
clip firstellip (-5,-5) rectangle (5,5);
clip thirdellip (-5,-5) rectangle (5,5);
clip fourthellip (-5,-5) rectangle (5,5);
fill[yellow] secondellip;
end{scope}
}%
defAtomicv{% 0101
begin{scope}[even odd rule]%
clip firstellip (-5,-5) rectangle (5,5);
clip thirdellip (-5,-5) rectangle (5,5);
clip fourthellip;
fill[yellow] secondellip;
end{scope}
}%
defAtomicvi{% 0110
begin{scope}[even odd rule]%
clip firstellip (-5,-5) rectangle (5,5);
clip thirdellip;
clip fourthellip (-5,-5) rectangle (5,5);
fill[yellow] secondellip;
end{scope}
}%
defAtomicvii{% 0111
begin{scope}[even odd rule]%
clip firstellip (-5,-5) rectangle (5,5);
clip thirdellip;
clip fourthellip;
fill[yellow] secondellip;
end{scope}
}%
defAtomicviii{% 1000
begin{scope}[even odd rule]%
clip secondellip (-5,-5) rectangle (5,5);
clip thirdellip (-5,-5) rectangle (5,5);
clip fourthellip (-5,-5) rectangle (5,5);
fill[yellow] firstellip;
end{scope}
}%
defAtomicix{% 1001
begin{scope}[even odd rule]%
clip secondellip (-5,-5) rectangle (5,5);
clip thirdellip (-5,-5) rectangle (5,5);
clip fourthellip;
fill[yellow] firstellip;
end{scope}
}%
defAtomicx{% 1010
begin{scope}[even odd rule]%
clip secondellip (-5,-5) rectangle (5,5);
clip thirdellip;
clip fourthellip (-5,-5) rectangle (5,5);
fill[yellow] firstellip;
end{scope}
}%
defAtomicxi{% 1011
begin{scope}[even odd rule]%
clip secondellip (-5,-5) rectangle (5,5);
clip thirdellip;
clip fourthellip;
fill[yellow] firstellip;
end{scope}
}%
defAtomicxii{% 1100
begin{scope}[even odd rule]%
clip secondellip;
clip thirdellip (-5,-5) rectangle (5,5);
clip fourthellip (-5,-5) rectangle (5,5);
fill[yellow] firstellip;
end{scope}
}%
defAtomicxiii{% 1101
begin{scope}[even odd rule]%
clip secondellip;
clip thirdellip (-5,-5) rectangle (5,5);
clip fourthellip;
fill[yellow] firstellip;
end{scope}
}%
defAtomicxiv{% 1110
begin{scope}[even odd rule]%
clip secondellip;
clip thirdellip;
clip fourthellip (-5,-5) rectangle (5,5);
fill[yellow] firstellip;
end{scope}
}%
defAtomicxv{% 1111
begin{scope}[even odd rule]%
clip secondellip;
clip thirdellip;
clip fourthellip;
fill[yellow] firstellip;
end{scope}
}%

makeatletter
newcommandVennFromTeX[1]{VennFromTeX@main #1}%

defVennFromTeX@main$#1${%
begingroup
xintglobaldefstrue
defoverline##1{!(##1)}% or not(##1)
defcap{&&}% or 'and'
defcup{||}% or 'or'
defoplus{ 'xor' }%
defsetminus##1{ifx(##1&&!(else &&!(##1)fi}%
letbiglempty
letbigrempty
% ....
% (add above all needed extra definitions: letBiglempty etc...)
xintdeffunc MyBool(A, B, C, D) := #1;% #1 must use A, B, C, Donly
endgroup
begin{tikzpicture}

xintFor* ##1 in {01}:
{%
xintFor* ##2 in {01}:
{%
xintFor* ##3 in {01}:
{%
xintFor* ##4 in {01}:
{%
xintifboolexpr{MyBool(##1, ##2, ##3, ##4)}
{csname
Atomicromannumeralnumexpr##1*8+##2*4+##3*2+##4endcsname}%
{}%
}%
}%
}%
}%
draw bounding;

% fill[white] firstellip;
% fill[white] secondellip;
% fill[white] thirdellip;
% fill[white] fourthellip;

draw firstellip node [label={[xshift=-2cm, yshift=-0.9cm]$A$}] {};
draw secondellip node [label={[xshift=-2.1cm, yshift=2.1cm]$B$}] {};
draw thirdellip node [label={[xshift=2.1cm, yshift=2.1cm]$C$}] {};
draw fourthellip node [label={[xshift=2cm, yshift=-0.9cm]$D$}] {};

draw bounding node [label=below left:$U$] {};

draw (0, 0) node [yshift=+4.4cm] {$#1$};

end{tikzpicture}
}%
makeatother
begin{document}

% xintverbosetrue

VennFromTeX{$Acap Bcap Ccap D$}

VennFromTeX{$(Acap B)cup (Ccap D)$}

VennFromTeX{$(overline{A}cupoverline{B})cap(overline{C}cupoverline{D})$}

% attention to use parentheses for disambiguating setminus

VennFromTeX{$(Acup B cup C) setminus(Bcup Ccup D)$}

VennFromTeX{$(Acup B cup C) cap (Bcup Ccup D)$}

VennFromTeX{$((Asetminus (Bcup Ccup D)) cup Bcap Ccap
D)setminus (Acap Bcap Ccap D)$}

end{document}


Be careful to read the caveat top regarding usage of setminus in input.



enter image description here



enter image description here



enter image description here



enter image description here



enter image description here



enter image description here



and finally



enter image description here






share|improve this answer























  • (+1) Thank you for your answer!
    – chishimotoji
    Dec 2 at 11:27










  • (+1) Wow, fantastic!
    – Thomas
    Dec 2 at 11:34










  • Encyclopedic answer
    – Diaa
    Dec 2 at 11:38










  • careful in first part of answer when inputting a long formula that it some parts may be cut off the page, check the parbox in second part how to work around that, and I also increased the vertical dimension.
    – jfbu
    Dec 2 at 12:46






  • 1




    @ArtificialStupidity I have to get dinner but just give me time to learn PSTricks and I can do with 4 sets afterwards...
    – jfbu
    Dec 2 at 18:39















up vote
15
down vote



+500










Here is an answer based on the one by @Thomas. Differences




  • the "elementary" regions I, II, ..., VIII are not numbered the same. My numbering is that "N" is the Roman number of "n+1" where "n" in binary is "abc", and the region is intersection of A or not A with B or not B with C or not C according to a, b, c = 0 or 1. (Boolean logic)


  • the macro needs only one input: a TeX formula for the set. Please enrich the syntax by adding suitable definitions converting TeX math macros into Boolean logic notation, as understood by xintexpr


  • I have dropped all fancy customization of colors, but xparse virtuosos will add the fancy optional arguments to re-install it if needed.



Thus, the big point here is that xintexpr computes automatically from the TeX typesetting formula which regions are to be filled in diagram.




attention to setminus it must be used either with parentheses setminus (...) or without but then with only one letter setminus A
ok, setminus Acap B not ok, because the translation here to xintexpr
boolean will do naively something equivalent to and not(A) and B, not the expected and not(A and B). In short, you must treat setminus as having maximally tying precedence.




documentclass[pstricks, border=10pt]{standalone}
usepackage{pst-node}
usepackage{xparse,xintexpr}

defKOEA{1.9,2.2}
defFOEA{1.4,1}

defKOEB{3.3,2.2}
defFOEB{1.2,1}

defKOEC{2.75,1.4}
defFOEC{1.4,1}

defKOEO{2.5,2}
defFOEO{2.5,2.0}

NewDocumentCommand{EreignisA}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEA)(FOEA)}{%
psellipse(KOEA)(FOEA)}%
}

NewDocumentCommand{EreignisB}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEB)(FOEB)}{%
psellipse(KOEB)(FOEB)}%
}

NewDocumentCommand{EreignisC}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEC)(FOEC)}{%
psellipse(KOEC)(FOEC)}%
}

NewDocumentCommand{EreignisOmega}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEO)(FOEO)}{%
psellipse(KOEO)(FOEO)}%
}

NewDocumentCommand{EndeEllipsen}{sm}{%
EreignisOmega%
pnodes(0.25,3.75){Omega}(0.25,0.25){A}(4.75,3.75){B}(4.75,0.25){C}(2.5,-0.5){E}
pnodes(0.7,3.36){MOmega}(0.85,1.55){MA}(4,3){MB}(3.8,0.75){MC}
EreignisA
EreignisB
EreignisC
rput[t](E){#2}%
IfBooleanF{#1}{%
rput(Omega){$Omega$}pcline[nodesepA=0.25](Omega)(MOmega)
rput(A){$A$}pcline[nodesepA=0.25](A)(MA)
rput(B){$B$}pcline[nodesepA=0.25](B)(MB)
rput(C){$C$}pcline[nodesepA=0.2](C)(MC)
}%
}

NewDocumentCommand{codeclip}{m}{%
pscustom[linestyle=none]{%
code{/clip /eoclip load def}%
psframe(-maxdimen,-maxdimen)(maxdimen,maxdimen)
#1
}%
}

%ExplSyntaxOn
% We could use some automated macro creation but well
% 000
NewDocumentCommand{arealI}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
}%
codeclip{%
EreignisB
}%
codeclip{%
EreignisC
}%
}%
EreignisOmega*[#1][#2]%
endpsclip
}%
% 001
NewDocumentCommand{arealII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
}%
codeclip{%
EreignisB
}%
}%
EreignisC*[#1][#2]%
endpsclip
}
% 010
NewDocumentCommand{arealIII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
}%
codeclip{%
EreignisC
}%
}%
EreignisB*[#1][#2]%
endpsclip
}
% 011
NewDocumentCommand{arealIV}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisB
EreignisC
}%
codeclip{%
EreignisA
}%
}%
EreignisB*[#1][#2]%
EreignisC*[#1][#2]%
endpsclip
}
% 100
NewDocumentCommand{arealV}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisB
}%
codeclip{%
EreignisC
}%
}%
EreignisA*[#1][#2]%
endpsclip
}
% 101
NewDocumentCommand{arealVI}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisC
}%
codeclip{%
EreignisB
}%
}%
EreignisA*[#1][#2]%
EreignisC*[#1][#2]%
endpsclip
}
% 110
NewDocumentCommand{arealVII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
}%
codeclip{%
EreignisC
}%
}%
EreignisA*[#1][#2]%
EreignisB*[#1][#2]%
endpsclip
}
% 111
NewDocumentCommand{arealVIII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
}%
codeclip{%
EreignisA
EreignisC
}%
codeclip{%
EreignisB
EreignisC
}%
}%
EreignisA*[#1][#2]%
EreignisB*[#1][#2]%
EreignisC*[#1][#2]%
endpsclip
}
%ExplSyntaxOff

%xintverbosetrue
makeatletter
newcommandVennFromTeX[1]{%
VennFromTeX@main #1%
}%
defVennFromTeX@main$#1${%
begingroup
xintglobaldefstrue
defoverline##1{!(##1)}% or not(##1)
defcap{&&}% or 'and'
defcup{||}% or 'or'
defoplus{ 'xor' }%
defsetminus##1{ifx(##1&&!(else &&!(##1)fi}%
letbiglempty
letbigrempty
% ....
% (add above all needed extra definitions: letBiglempty etc...)
xintdeffunc MyBool(A, B, C) := #1;% #1 must use A, B, C only
endgroup
% we could make a loop here (using @Roman), but let's stay simple
% I trust xparse experts can wrap this up in macros allowing to customize
% the colors
% ATTENTION THAT THESE arealI...VIII ARE NOT THE SAME AS IN @THOMAS ANSWER
xintifboolexpr{MyBool(0, 0, 0)}{arealI[cyan][0.8]}{}%
xintifboolexpr{MyBool(0, 0, 1)}{arealII[cyan][0.8]}{}%
xintifboolexpr{MyBool(0, 1, 0)}{arealIII[cyan][0.8]}{}%
xintifboolexpr{MyBool(0, 1, 1)}{arealIV[cyan][0.8]}{}%
xintifboolexpr{MyBool(1, 0, 0)}{arealV[cyan][0.8]}{}%
xintifboolexpr{MyBool(1, 0, 1)}{arealVI[cyan][0.8]}{}%
xintifboolexpr{MyBool(1, 1, 0)}{arealVII[cyan][0.8]}{}%
xintifboolexpr{MyBool(1, 1, 1)}{arealVIII[cyan][0.8]}{}%
EndeEllipsen{$#1$}%
}%
makeatother

begin{document}

%testing if I, II, ..., VIII are as expected
% makeatletter
% xintFor*#1in{xintSeq{0}{7}}do{%
% begin{pspicture}(0,-1)(5,4)
% rput(2,0){thenumexpr1+#1}
% @nameuse{areal@Roman{numexpr1+#1}}[cyan][0.8]
% EndeEllipsen{}
% end{pspicture}
% }%
% end{document}


begin{pspicture}(0,-1)(5,4)
VennFromTeX{$Acap Bcap C$}%
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennFromTeX{$Acap (Bcup C)$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennFromTeX{$(overline{A}cap overline{B})cup C$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennFromTeX{$overline{A}setminus (Bcap C)$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennFromTeX{$(overline{A}setminus B)cap C$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennFromTeX{$(Asetminus B)cup (Bcap C)$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennFromTeX{$bigl((Acap B)cup (Acap C)bigr)setminus(Acap Bcap C)$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennFromTeX{$Aoplus Boplus C$}
end{pspicture}

end{document}


Produces



enter image description here



enter image description here



enter image description here



enter image description here



enter image description here



enter image description here



enter image description here



enter image description here







Here is code to generate all 256 Venn diagrams. Just insert it in body of above document and don't forget to add usepackage{xintbinhex} to preamble.



% generating all graphics

% 0<= n <= 255 has eight binary digits
% abcdefgh
% a=1 -> region VIII is included (A cap B cap C)
% b=1 -> region VII is included
% ...
% h=1 -> region I is included (overline{A}cap overline{B} cap overline{C})
% We want also to describe the region as a formula...
% We could use 8 xintFor loops #1, ..., #8, but then
% we still need to convert #1*7 to binary, #2*6, #3*5 etc...
% I thus use xintbinhex per convenience but ifodd would be enough
% As I use xintbinhex, I also use a single xintFor* loop

%defgobbleone#1{}%
defgobbletwo#1#2{}%
xintFor* #1 in {xintSeq{0}{255}}:
{%
xintDigitsOfxintDecToBin{thenumexpr256+#1relax}toRegions
% due to leading 1 there will be a shift of indexing in Regions
edefx{xintifboolexpr{Regions{thenumexpr9-0}}% 000
{unexpanded{allowbreakcup
overline{A}capoverline{B}capoverline{C}}}%
{}%
xintifboolexpr{Regions{9-1}}% 001
{unexpanded{allowbreakcup overline{A}capoverline{B}cap C}}%
{}%
xintifboolexpr{Regions{9-2}}% 010
{unexpanded{allowbreakcup overline{A}cap B capoverline{C}}}%
{}%
xintifboolexpr{Regions{9-3}}% 011
{unexpanded{allowbreakcup overline{A} cap B cap C}}%
{}%
xintifboolexpr{Regions{9-4}}% 100
{unexpanded{allowbreakcup Acap overline{B}cap overline{C}}}%
{}%
xintifboolexpr{Regions{9-5}}% 101
{unexpanded{allowbreakcup Acap overline{B}cap C}}%
{}%
xintifboolexpr{Regions{9-6}}% 110
{unexpanded{allowbreakcup Acap Bcap overline{C}}}%
{}%
xintifboolexpr{Regions{9-7}}% 111
{unexpanded{allowbreakcup Acap B cap C}}%
{}%
}%
xintifForFirst{defx{emptyset}}
{oodefx{expandaftergobbletwox}}%
begin{pspicture}(0,-2)(5,4)
% I will leave here each Region as individual call, so a color can
% be added by modifying this code
xintifboolexpr{Regions{9-0}}{arealI[cyan][0.8]}{}%
xintifboolexpr{Regions{9-1}}{arealII[cyan][0.8]}{}%
xintifboolexpr{Regions{9-2}}{arealIII[cyan][0.8]}{}%
xintifboolexpr{Regions{9-3}}{arealIV[cyan][0.8]}{}%
xintifboolexpr{Regions{9-4}}{arealV[cyan][0.8]}{}%
xintifboolexpr{Regions{9-5}}{arealVI[cyan][0.8]}{}%
xintifboolexpr{Regions{9-6}}{arealVII[cyan][0.8]}{}%
xintifboolexpr{Regions{9-7}}{arealVIII[cyan][0.8]}{}%
EndeEllipsen{parbox{4cm}{centering$x$}}%
end{pspicture}%
}%


Defect: the description of the set is as a disjoint union of atomic events. There might be some canonical shorter description but I never really thought about it. For example one of those diagram will represent $Omegasetminus A$ but this not the way it will be legended.



Here is how this example comes out (on page 16 of document with nothing else, i.e. it corresponds to #1 = 15 in the loop, 15=1111 means to keep atomic events 0=000, 1=001, 2=010, 3=011, which is complement of A in Omega.



enter image description here







Here is now with 4 sets.



This time, with TikZ code (I know neither PSTricks nor TikZ and can only survive from copying pre-existing drawing instructions; in this case I started from https://tex.stackexchange.com/a/100091/4686 by @JohnHammersley in 2013).



First I include an image of all atomic events, which are the regions to which the Atomic... macros in code next refer. (this was done for checking while preparing answer)



enter image description here



Here is the code for VennFromTeX, use it as VennFromTeX{$ set formula with A, B, C, D $}. Same instructions as above for three sets.
(one may wish to enlarge the syntax for example by allowing use of U or Omega and defining it in xintexpr to be simply 1, and similarly emptyset could be defined to be 0).



documentclass[12pt, tikz, border=10pt]{standalone}

usepackage{tikz}

usetikzlibrary{positioning,shapes.geometric}

usepackage{xintexpr}% for VennFromTeX


% For drawing
deffirstellip{(-1.6, 0) ellipse [x radius=3cm, y radius=1.5cm, rotate=-50]}
defsecondellip{(-0.3, 1cm) ellipse [x radius=3cm, y radius=1.5cm, rotate=-50]}
defthirdellip{(0.3, 1cm) ellipse [x radius=3cm, y radius=1.5cm, rotate=50]}
deffourthellip{(1.6, 0) ellipse [x radius=3cm, y radius=1.5cm, rotate=50]}

defbounding{(-5,-3) rectangle (5,4)}

% Elementary sets
% ABCD
% abcd a, b, c, d in {0, 1}
defAtomic{% 0000
begin{scope}[even odd rule]% exterior
clip firstellip (-5,-5) rectangle (5,5);
clip secondellip (-5,-5) rectangle (5,5);
clip thirdellip (-5,-5) rectangle (5,5);
clip fourthellip (-5,-5) rectangle (5,5);
fill[yellow] bounding;
end{scope}
}%
defAtomici{% 0001
begin{scope}[even odd rule]% fourth ellipse corner
clip firstellip (-5,-5) rectangle (5,5);
clip secondellip (-5,-5) rectangle (5,5);
clip thirdellip (-5,-5) rectangle (5,5);
fill[yellow] fourthellip;
end{scope}
}%
defAtomicii{% 0010
begin{scope}[even odd rule]% third ellipse corner
clip firstellip (-5,-5) rectangle (5,5);
clip secondellip (-5,-5) rectangle (5,5);
clip fourthellip (-5,-5) rectangle (5,5);
fill[yellow] thirdellip;
end{scope}
}%
defAtomiciii{% 0011
begin{scope}[even odd rule]%
clip firstellip (-5,-5) rectangle (5,5);
clip secondellip (-5,-5) rectangle (5,5);
clip fourthellip;
fill[yellow] thirdellip;
end{scope}
}%
defAtomiciv{% 0100
begin{scope}[even odd rule]% second ellipse corner
clip firstellip (-5,-5) rectangle (5,5);
clip thirdellip (-5,-5) rectangle (5,5);
clip fourthellip (-5,-5) rectangle (5,5);
fill[yellow] secondellip;
end{scope}
}%
defAtomicv{% 0101
begin{scope}[even odd rule]%
clip firstellip (-5,-5) rectangle (5,5);
clip thirdellip (-5,-5) rectangle (5,5);
clip fourthellip;
fill[yellow] secondellip;
end{scope}
}%
defAtomicvi{% 0110
begin{scope}[even odd rule]%
clip firstellip (-5,-5) rectangle (5,5);
clip thirdellip;
clip fourthellip (-5,-5) rectangle (5,5);
fill[yellow] secondellip;
end{scope}
}%
defAtomicvii{% 0111
begin{scope}[even odd rule]%
clip firstellip (-5,-5) rectangle (5,5);
clip thirdellip;
clip fourthellip;
fill[yellow] secondellip;
end{scope}
}%
defAtomicviii{% 1000
begin{scope}[even odd rule]%
clip secondellip (-5,-5) rectangle (5,5);
clip thirdellip (-5,-5) rectangle (5,5);
clip fourthellip (-5,-5) rectangle (5,5);
fill[yellow] firstellip;
end{scope}
}%
defAtomicix{% 1001
begin{scope}[even odd rule]%
clip secondellip (-5,-5) rectangle (5,5);
clip thirdellip (-5,-5) rectangle (5,5);
clip fourthellip;
fill[yellow] firstellip;
end{scope}
}%
defAtomicx{% 1010
begin{scope}[even odd rule]%
clip secondellip (-5,-5) rectangle (5,5);
clip thirdellip;
clip fourthellip (-5,-5) rectangle (5,5);
fill[yellow] firstellip;
end{scope}
}%
defAtomicxi{% 1011
begin{scope}[even odd rule]%
clip secondellip (-5,-5) rectangle (5,5);
clip thirdellip;
clip fourthellip;
fill[yellow] firstellip;
end{scope}
}%
defAtomicxii{% 1100
begin{scope}[even odd rule]%
clip secondellip;
clip thirdellip (-5,-5) rectangle (5,5);
clip fourthellip (-5,-5) rectangle (5,5);
fill[yellow] firstellip;
end{scope}
}%
defAtomicxiii{% 1101
begin{scope}[even odd rule]%
clip secondellip;
clip thirdellip (-5,-5) rectangle (5,5);
clip fourthellip;
fill[yellow] firstellip;
end{scope}
}%
defAtomicxiv{% 1110
begin{scope}[even odd rule]%
clip secondellip;
clip thirdellip;
clip fourthellip (-5,-5) rectangle (5,5);
fill[yellow] firstellip;
end{scope}
}%
defAtomicxv{% 1111
begin{scope}[even odd rule]%
clip secondellip;
clip thirdellip;
clip fourthellip;
fill[yellow] firstellip;
end{scope}
}%

makeatletter
newcommandVennFromTeX[1]{VennFromTeX@main #1}%

defVennFromTeX@main$#1${%
begingroup
xintglobaldefstrue
defoverline##1{!(##1)}% or not(##1)
defcap{&&}% or 'and'
defcup{||}% or 'or'
defoplus{ 'xor' }%
defsetminus##1{ifx(##1&&!(else &&!(##1)fi}%
letbiglempty
letbigrempty
% ....
% (add above all needed extra definitions: letBiglempty etc...)
xintdeffunc MyBool(A, B, C, D) := #1;% #1 must use A, B, C, Donly
endgroup
begin{tikzpicture}

xintFor* ##1 in {01}:
{%
xintFor* ##2 in {01}:
{%
xintFor* ##3 in {01}:
{%
xintFor* ##4 in {01}:
{%
xintifboolexpr{MyBool(##1, ##2, ##3, ##4)}
{csname
Atomicromannumeralnumexpr##1*8+##2*4+##3*2+##4endcsname}%
{}%
}%
}%
}%
}%
draw bounding;

% fill[white] firstellip;
% fill[white] secondellip;
% fill[white] thirdellip;
% fill[white] fourthellip;

draw firstellip node [label={[xshift=-2cm, yshift=-0.9cm]$A$}] {};
draw secondellip node [label={[xshift=-2.1cm, yshift=2.1cm]$B$}] {};
draw thirdellip node [label={[xshift=2.1cm, yshift=2.1cm]$C$}] {};
draw fourthellip node [label={[xshift=2cm, yshift=-0.9cm]$D$}] {};

draw bounding node [label=below left:$U$] {};

draw (0, 0) node [yshift=+4.4cm] {$#1$};

end{tikzpicture}
}%
makeatother
begin{document}

% xintverbosetrue

VennFromTeX{$Acap Bcap Ccap D$}

VennFromTeX{$(Acap B)cup (Ccap D)$}

VennFromTeX{$(overline{A}cupoverline{B})cap(overline{C}cupoverline{D})$}

% attention to use parentheses for disambiguating setminus

VennFromTeX{$(Acup B cup C) setminus(Bcup Ccup D)$}

VennFromTeX{$(Acup B cup C) cap (Bcup Ccup D)$}

VennFromTeX{$((Asetminus (Bcup Ccup D)) cup Bcap Ccap
D)setminus (Acap Bcap Ccap D)$}

end{document}


Be careful to read the caveat top regarding usage of setminus in input.



enter image description here



enter image description here



enter image description here



enter image description here



enter image description here



enter image description here



and finally



enter image description here






share|improve this answer























  • (+1) Thank you for your answer!
    – chishimotoji
    Dec 2 at 11:27










  • (+1) Wow, fantastic!
    – Thomas
    Dec 2 at 11:34










  • Encyclopedic answer
    – Diaa
    Dec 2 at 11:38










  • careful in first part of answer when inputting a long formula that it some parts may be cut off the page, check the parbox in second part how to work around that, and I also increased the vertical dimension.
    – jfbu
    Dec 2 at 12:46






  • 1




    @ArtificialStupidity I have to get dinner but just give me time to learn PSTricks and I can do with 4 sets afterwards...
    – jfbu
    Dec 2 at 18:39













up vote
15
down vote



+500







up vote
15
down vote



+500




+500




Here is an answer based on the one by @Thomas. Differences




  • the "elementary" regions I, II, ..., VIII are not numbered the same. My numbering is that "N" is the Roman number of "n+1" where "n" in binary is "abc", and the region is intersection of A or not A with B or not B with C or not C according to a, b, c = 0 or 1. (Boolean logic)


  • the macro needs only one input: a TeX formula for the set. Please enrich the syntax by adding suitable definitions converting TeX math macros into Boolean logic notation, as understood by xintexpr


  • I have dropped all fancy customization of colors, but xparse virtuosos will add the fancy optional arguments to re-install it if needed.



Thus, the big point here is that xintexpr computes automatically from the TeX typesetting formula which regions are to be filled in diagram.




attention to setminus it must be used either with parentheses setminus (...) or without but then with only one letter setminus A
ok, setminus Acap B not ok, because the translation here to xintexpr
boolean will do naively something equivalent to and not(A) and B, not the expected and not(A and B). In short, you must treat setminus as having maximally tying precedence.




documentclass[pstricks, border=10pt]{standalone}
usepackage{pst-node}
usepackage{xparse,xintexpr}

defKOEA{1.9,2.2}
defFOEA{1.4,1}

defKOEB{3.3,2.2}
defFOEB{1.2,1}

defKOEC{2.75,1.4}
defFOEC{1.4,1}

defKOEO{2.5,2}
defFOEO{2.5,2.0}

NewDocumentCommand{EreignisA}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEA)(FOEA)}{%
psellipse(KOEA)(FOEA)}%
}

NewDocumentCommand{EreignisB}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEB)(FOEB)}{%
psellipse(KOEB)(FOEB)}%
}

NewDocumentCommand{EreignisC}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEC)(FOEC)}{%
psellipse(KOEC)(FOEC)}%
}

NewDocumentCommand{EreignisOmega}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEO)(FOEO)}{%
psellipse(KOEO)(FOEO)}%
}

NewDocumentCommand{EndeEllipsen}{sm}{%
EreignisOmega%
pnodes(0.25,3.75){Omega}(0.25,0.25){A}(4.75,3.75){B}(4.75,0.25){C}(2.5,-0.5){E}
pnodes(0.7,3.36){MOmega}(0.85,1.55){MA}(4,3){MB}(3.8,0.75){MC}
EreignisA
EreignisB
EreignisC
rput[t](E){#2}%
IfBooleanF{#1}{%
rput(Omega){$Omega$}pcline[nodesepA=0.25](Omega)(MOmega)
rput(A){$A$}pcline[nodesepA=0.25](A)(MA)
rput(B){$B$}pcline[nodesepA=0.25](B)(MB)
rput(C){$C$}pcline[nodesepA=0.2](C)(MC)
}%
}

NewDocumentCommand{codeclip}{m}{%
pscustom[linestyle=none]{%
code{/clip /eoclip load def}%
psframe(-maxdimen,-maxdimen)(maxdimen,maxdimen)
#1
}%
}

%ExplSyntaxOn
% We could use some automated macro creation but well
% 000
NewDocumentCommand{arealI}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
}%
codeclip{%
EreignisB
}%
codeclip{%
EreignisC
}%
}%
EreignisOmega*[#1][#2]%
endpsclip
}%
% 001
NewDocumentCommand{arealII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
}%
codeclip{%
EreignisB
}%
}%
EreignisC*[#1][#2]%
endpsclip
}
% 010
NewDocumentCommand{arealIII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
}%
codeclip{%
EreignisC
}%
}%
EreignisB*[#1][#2]%
endpsclip
}
% 011
NewDocumentCommand{arealIV}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisB
EreignisC
}%
codeclip{%
EreignisA
}%
}%
EreignisB*[#1][#2]%
EreignisC*[#1][#2]%
endpsclip
}
% 100
NewDocumentCommand{arealV}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisB
}%
codeclip{%
EreignisC
}%
}%
EreignisA*[#1][#2]%
endpsclip
}
% 101
NewDocumentCommand{arealVI}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisC
}%
codeclip{%
EreignisB
}%
}%
EreignisA*[#1][#2]%
EreignisC*[#1][#2]%
endpsclip
}
% 110
NewDocumentCommand{arealVII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
}%
codeclip{%
EreignisC
}%
}%
EreignisA*[#1][#2]%
EreignisB*[#1][#2]%
endpsclip
}
% 111
NewDocumentCommand{arealVIII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
}%
codeclip{%
EreignisA
EreignisC
}%
codeclip{%
EreignisB
EreignisC
}%
}%
EreignisA*[#1][#2]%
EreignisB*[#1][#2]%
EreignisC*[#1][#2]%
endpsclip
}
%ExplSyntaxOff

%xintverbosetrue
makeatletter
newcommandVennFromTeX[1]{%
VennFromTeX@main #1%
}%
defVennFromTeX@main$#1${%
begingroup
xintglobaldefstrue
defoverline##1{!(##1)}% or not(##1)
defcap{&&}% or 'and'
defcup{||}% or 'or'
defoplus{ 'xor' }%
defsetminus##1{ifx(##1&&!(else &&!(##1)fi}%
letbiglempty
letbigrempty
% ....
% (add above all needed extra definitions: letBiglempty etc...)
xintdeffunc MyBool(A, B, C) := #1;% #1 must use A, B, C only
endgroup
% we could make a loop here (using @Roman), but let's stay simple
% I trust xparse experts can wrap this up in macros allowing to customize
% the colors
% ATTENTION THAT THESE arealI...VIII ARE NOT THE SAME AS IN @THOMAS ANSWER
xintifboolexpr{MyBool(0, 0, 0)}{arealI[cyan][0.8]}{}%
xintifboolexpr{MyBool(0, 0, 1)}{arealII[cyan][0.8]}{}%
xintifboolexpr{MyBool(0, 1, 0)}{arealIII[cyan][0.8]}{}%
xintifboolexpr{MyBool(0, 1, 1)}{arealIV[cyan][0.8]}{}%
xintifboolexpr{MyBool(1, 0, 0)}{arealV[cyan][0.8]}{}%
xintifboolexpr{MyBool(1, 0, 1)}{arealVI[cyan][0.8]}{}%
xintifboolexpr{MyBool(1, 1, 0)}{arealVII[cyan][0.8]}{}%
xintifboolexpr{MyBool(1, 1, 1)}{arealVIII[cyan][0.8]}{}%
EndeEllipsen{$#1$}%
}%
makeatother

begin{document}

%testing if I, II, ..., VIII are as expected
% makeatletter
% xintFor*#1in{xintSeq{0}{7}}do{%
% begin{pspicture}(0,-1)(5,4)
% rput(2,0){thenumexpr1+#1}
% @nameuse{areal@Roman{numexpr1+#1}}[cyan][0.8]
% EndeEllipsen{}
% end{pspicture}
% }%
% end{document}


begin{pspicture}(0,-1)(5,4)
VennFromTeX{$Acap Bcap C$}%
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennFromTeX{$Acap (Bcup C)$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennFromTeX{$(overline{A}cap overline{B})cup C$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennFromTeX{$overline{A}setminus (Bcap C)$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennFromTeX{$(overline{A}setminus B)cap C$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennFromTeX{$(Asetminus B)cup (Bcap C)$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennFromTeX{$bigl((Acap B)cup (Acap C)bigr)setminus(Acap Bcap C)$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennFromTeX{$Aoplus Boplus C$}
end{pspicture}

end{document}


Produces



enter image description here



enter image description here



enter image description here



enter image description here



enter image description here



enter image description here



enter image description here



enter image description here







Here is code to generate all 256 Venn diagrams. Just insert it in body of above document and don't forget to add usepackage{xintbinhex} to preamble.



% generating all graphics

% 0<= n <= 255 has eight binary digits
% abcdefgh
% a=1 -> region VIII is included (A cap B cap C)
% b=1 -> region VII is included
% ...
% h=1 -> region I is included (overline{A}cap overline{B} cap overline{C})
% We want also to describe the region as a formula...
% We could use 8 xintFor loops #1, ..., #8, but then
% we still need to convert #1*7 to binary, #2*6, #3*5 etc...
% I thus use xintbinhex per convenience but ifodd would be enough
% As I use xintbinhex, I also use a single xintFor* loop

%defgobbleone#1{}%
defgobbletwo#1#2{}%
xintFor* #1 in {xintSeq{0}{255}}:
{%
xintDigitsOfxintDecToBin{thenumexpr256+#1relax}toRegions
% due to leading 1 there will be a shift of indexing in Regions
edefx{xintifboolexpr{Regions{thenumexpr9-0}}% 000
{unexpanded{allowbreakcup
overline{A}capoverline{B}capoverline{C}}}%
{}%
xintifboolexpr{Regions{9-1}}% 001
{unexpanded{allowbreakcup overline{A}capoverline{B}cap C}}%
{}%
xintifboolexpr{Regions{9-2}}% 010
{unexpanded{allowbreakcup overline{A}cap B capoverline{C}}}%
{}%
xintifboolexpr{Regions{9-3}}% 011
{unexpanded{allowbreakcup overline{A} cap B cap C}}%
{}%
xintifboolexpr{Regions{9-4}}% 100
{unexpanded{allowbreakcup Acap overline{B}cap overline{C}}}%
{}%
xintifboolexpr{Regions{9-5}}% 101
{unexpanded{allowbreakcup Acap overline{B}cap C}}%
{}%
xintifboolexpr{Regions{9-6}}% 110
{unexpanded{allowbreakcup Acap Bcap overline{C}}}%
{}%
xintifboolexpr{Regions{9-7}}% 111
{unexpanded{allowbreakcup Acap B cap C}}%
{}%
}%
xintifForFirst{defx{emptyset}}
{oodefx{expandaftergobbletwox}}%
begin{pspicture}(0,-2)(5,4)
% I will leave here each Region as individual call, so a color can
% be added by modifying this code
xintifboolexpr{Regions{9-0}}{arealI[cyan][0.8]}{}%
xintifboolexpr{Regions{9-1}}{arealII[cyan][0.8]}{}%
xintifboolexpr{Regions{9-2}}{arealIII[cyan][0.8]}{}%
xintifboolexpr{Regions{9-3}}{arealIV[cyan][0.8]}{}%
xintifboolexpr{Regions{9-4}}{arealV[cyan][0.8]}{}%
xintifboolexpr{Regions{9-5}}{arealVI[cyan][0.8]}{}%
xintifboolexpr{Regions{9-6}}{arealVII[cyan][0.8]}{}%
xintifboolexpr{Regions{9-7}}{arealVIII[cyan][0.8]}{}%
EndeEllipsen{parbox{4cm}{centering$x$}}%
end{pspicture}%
}%


Defect: the description of the set is as a disjoint union of atomic events. There might be some canonical shorter description but I never really thought about it. For example one of those diagram will represent $Omegasetminus A$ but this not the way it will be legended.



Here is how this example comes out (on page 16 of document with nothing else, i.e. it corresponds to #1 = 15 in the loop, 15=1111 means to keep atomic events 0=000, 1=001, 2=010, 3=011, which is complement of A in Omega.



enter image description here







Here is now with 4 sets.



This time, with TikZ code (I know neither PSTricks nor TikZ and can only survive from copying pre-existing drawing instructions; in this case I started from https://tex.stackexchange.com/a/100091/4686 by @JohnHammersley in 2013).



First I include an image of all atomic events, which are the regions to which the Atomic... macros in code next refer. (this was done for checking while preparing answer)



enter image description here



Here is the code for VennFromTeX, use it as VennFromTeX{$ set formula with A, B, C, D $}. Same instructions as above for three sets.
(one may wish to enlarge the syntax for example by allowing use of U or Omega and defining it in xintexpr to be simply 1, and similarly emptyset could be defined to be 0).



documentclass[12pt, tikz, border=10pt]{standalone}

usepackage{tikz}

usetikzlibrary{positioning,shapes.geometric}

usepackage{xintexpr}% for VennFromTeX


% For drawing
deffirstellip{(-1.6, 0) ellipse [x radius=3cm, y radius=1.5cm, rotate=-50]}
defsecondellip{(-0.3, 1cm) ellipse [x radius=3cm, y radius=1.5cm, rotate=-50]}
defthirdellip{(0.3, 1cm) ellipse [x radius=3cm, y radius=1.5cm, rotate=50]}
deffourthellip{(1.6, 0) ellipse [x radius=3cm, y radius=1.5cm, rotate=50]}

defbounding{(-5,-3) rectangle (5,4)}

% Elementary sets
% ABCD
% abcd a, b, c, d in {0, 1}
defAtomic{% 0000
begin{scope}[even odd rule]% exterior
clip firstellip (-5,-5) rectangle (5,5);
clip secondellip (-5,-5) rectangle (5,5);
clip thirdellip (-5,-5) rectangle (5,5);
clip fourthellip (-5,-5) rectangle (5,5);
fill[yellow] bounding;
end{scope}
}%
defAtomici{% 0001
begin{scope}[even odd rule]% fourth ellipse corner
clip firstellip (-5,-5) rectangle (5,5);
clip secondellip (-5,-5) rectangle (5,5);
clip thirdellip (-5,-5) rectangle (5,5);
fill[yellow] fourthellip;
end{scope}
}%
defAtomicii{% 0010
begin{scope}[even odd rule]% third ellipse corner
clip firstellip (-5,-5) rectangle (5,5);
clip secondellip (-5,-5) rectangle (5,5);
clip fourthellip (-5,-5) rectangle (5,5);
fill[yellow] thirdellip;
end{scope}
}%
defAtomiciii{% 0011
begin{scope}[even odd rule]%
clip firstellip (-5,-5) rectangle (5,5);
clip secondellip (-5,-5) rectangle (5,5);
clip fourthellip;
fill[yellow] thirdellip;
end{scope}
}%
defAtomiciv{% 0100
begin{scope}[even odd rule]% second ellipse corner
clip firstellip (-5,-5) rectangle (5,5);
clip thirdellip (-5,-5) rectangle (5,5);
clip fourthellip (-5,-5) rectangle (5,5);
fill[yellow] secondellip;
end{scope}
}%
defAtomicv{% 0101
begin{scope}[even odd rule]%
clip firstellip (-5,-5) rectangle (5,5);
clip thirdellip (-5,-5) rectangle (5,5);
clip fourthellip;
fill[yellow] secondellip;
end{scope}
}%
defAtomicvi{% 0110
begin{scope}[even odd rule]%
clip firstellip (-5,-5) rectangle (5,5);
clip thirdellip;
clip fourthellip (-5,-5) rectangle (5,5);
fill[yellow] secondellip;
end{scope}
}%
defAtomicvii{% 0111
begin{scope}[even odd rule]%
clip firstellip (-5,-5) rectangle (5,5);
clip thirdellip;
clip fourthellip;
fill[yellow] secondellip;
end{scope}
}%
defAtomicviii{% 1000
begin{scope}[even odd rule]%
clip secondellip (-5,-5) rectangle (5,5);
clip thirdellip (-5,-5) rectangle (5,5);
clip fourthellip (-5,-5) rectangle (5,5);
fill[yellow] firstellip;
end{scope}
}%
defAtomicix{% 1001
begin{scope}[even odd rule]%
clip secondellip (-5,-5) rectangle (5,5);
clip thirdellip (-5,-5) rectangle (5,5);
clip fourthellip;
fill[yellow] firstellip;
end{scope}
}%
defAtomicx{% 1010
begin{scope}[even odd rule]%
clip secondellip (-5,-5) rectangle (5,5);
clip thirdellip;
clip fourthellip (-5,-5) rectangle (5,5);
fill[yellow] firstellip;
end{scope}
}%
defAtomicxi{% 1011
begin{scope}[even odd rule]%
clip secondellip (-5,-5) rectangle (5,5);
clip thirdellip;
clip fourthellip;
fill[yellow] firstellip;
end{scope}
}%
defAtomicxii{% 1100
begin{scope}[even odd rule]%
clip secondellip;
clip thirdellip (-5,-5) rectangle (5,5);
clip fourthellip (-5,-5) rectangle (5,5);
fill[yellow] firstellip;
end{scope}
}%
defAtomicxiii{% 1101
begin{scope}[even odd rule]%
clip secondellip;
clip thirdellip (-5,-5) rectangle (5,5);
clip fourthellip;
fill[yellow] firstellip;
end{scope}
}%
defAtomicxiv{% 1110
begin{scope}[even odd rule]%
clip secondellip;
clip thirdellip;
clip fourthellip (-5,-5) rectangle (5,5);
fill[yellow] firstellip;
end{scope}
}%
defAtomicxv{% 1111
begin{scope}[even odd rule]%
clip secondellip;
clip thirdellip;
clip fourthellip;
fill[yellow] firstellip;
end{scope}
}%

makeatletter
newcommandVennFromTeX[1]{VennFromTeX@main #1}%

defVennFromTeX@main$#1${%
begingroup
xintglobaldefstrue
defoverline##1{!(##1)}% or not(##1)
defcap{&&}% or 'and'
defcup{||}% or 'or'
defoplus{ 'xor' }%
defsetminus##1{ifx(##1&&!(else &&!(##1)fi}%
letbiglempty
letbigrempty
% ....
% (add above all needed extra definitions: letBiglempty etc...)
xintdeffunc MyBool(A, B, C, D) := #1;% #1 must use A, B, C, Donly
endgroup
begin{tikzpicture}

xintFor* ##1 in {01}:
{%
xintFor* ##2 in {01}:
{%
xintFor* ##3 in {01}:
{%
xintFor* ##4 in {01}:
{%
xintifboolexpr{MyBool(##1, ##2, ##3, ##4)}
{csname
Atomicromannumeralnumexpr##1*8+##2*4+##3*2+##4endcsname}%
{}%
}%
}%
}%
}%
draw bounding;

% fill[white] firstellip;
% fill[white] secondellip;
% fill[white] thirdellip;
% fill[white] fourthellip;

draw firstellip node [label={[xshift=-2cm, yshift=-0.9cm]$A$}] {};
draw secondellip node [label={[xshift=-2.1cm, yshift=2.1cm]$B$}] {};
draw thirdellip node [label={[xshift=2.1cm, yshift=2.1cm]$C$}] {};
draw fourthellip node [label={[xshift=2cm, yshift=-0.9cm]$D$}] {};

draw bounding node [label=below left:$U$] {};

draw (0, 0) node [yshift=+4.4cm] {$#1$};

end{tikzpicture}
}%
makeatother
begin{document}

% xintverbosetrue

VennFromTeX{$Acap Bcap Ccap D$}

VennFromTeX{$(Acap B)cup (Ccap D)$}

VennFromTeX{$(overline{A}cupoverline{B})cap(overline{C}cupoverline{D})$}

% attention to use parentheses for disambiguating setminus

VennFromTeX{$(Acup B cup C) setminus(Bcup Ccup D)$}

VennFromTeX{$(Acup B cup C) cap (Bcup Ccup D)$}

VennFromTeX{$((Asetminus (Bcup Ccup D)) cup Bcap Ccap
D)setminus (Acap Bcap Ccap D)$}

end{document}


Be careful to read the caveat top regarding usage of setminus in input.



enter image description here



enter image description here



enter image description here



enter image description here



enter image description here



enter image description here



and finally



enter image description here






share|improve this answer














Here is an answer based on the one by @Thomas. Differences




  • the "elementary" regions I, II, ..., VIII are not numbered the same. My numbering is that "N" is the Roman number of "n+1" where "n" in binary is "abc", and the region is intersection of A or not A with B or not B with C or not C according to a, b, c = 0 or 1. (Boolean logic)


  • the macro needs only one input: a TeX formula for the set. Please enrich the syntax by adding suitable definitions converting TeX math macros into Boolean logic notation, as understood by xintexpr


  • I have dropped all fancy customization of colors, but xparse virtuosos will add the fancy optional arguments to re-install it if needed.



Thus, the big point here is that xintexpr computes automatically from the TeX typesetting formula which regions are to be filled in diagram.




attention to setminus it must be used either with parentheses setminus (...) or without but then with only one letter setminus A
ok, setminus Acap B not ok, because the translation here to xintexpr
boolean will do naively something equivalent to and not(A) and B, not the expected and not(A and B). In short, you must treat setminus as having maximally tying precedence.




documentclass[pstricks, border=10pt]{standalone}
usepackage{pst-node}
usepackage{xparse,xintexpr}

defKOEA{1.9,2.2}
defFOEA{1.4,1}

defKOEB{3.3,2.2}
defFOEB{1.2,1}

defKOEC{2.75,1.4}
defFOEC{1.4,1}

defKOEO{2.5,2}
defFOEO{2.5,2.0}

NewDocumentCommand{EreignisA}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEA)(FOEA)}{%
psellipse(KOEA)(FOEA)}%
}

NewDocumentCommand{EreignisB}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEB)(FOEB)}{%
psellipse(KOEB)(FOEB)}%
}

NewDocumentCommand{EreignisC}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEC)(FOEC)}{%
psellipse(KOEC)(FOEC)}%
}

NewDocumentCommand{EreignisOmega}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEO)(FOEO)}{%
psellipse(KOEO)(FOEO)}%
}

NewDocumentCommand{EndeEllipsen}{sm}{%
EreignisOmega%
pnodes(0.25,3.75){Omega}(0.25,0.25){A}(4.75,3.75){B}(4.75,0.25){C}(2.5,-0.5){E}
pnodes(0.7,3.36){MOmega}(0.85,1.55){MA}(4,3){MB}(3.8,0.75){MC}
EreignisA
EreignisB
EreignisC
rput[t](E){#2}%
IfBooleanF{#1}{%
rput(Omega){$Omega$}pcline[nodesepA=0.25](Omega)(MOmega)
rput(A){$A$}pcline[nodesepA=0.25](A)(MA)
rput(B){$B$}pcline[nodesepA=0.25](B)(MB)
rput(C){$C$}pcline[nodesepA=0.2](C)(MC)
}%
}

NewDocumentCommand{codeclip}{m}{%
pscustom[linestyle=none]{%
code{/clip /eoclip load def}%
psframe(-maxdimen,-maxdimen)(maxdimen,maxdimen)
#1
}%
}

%ExplSyntaxOn
% We could use some automated macro creation but well
% 000
NewDocumentCommand{arealI}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
}%
codeclip{%
EreignisB
}%
codeclip{%
EreignisC
}%
}%
EreignisOmega*[#1][#2]%
endpsclip
}%
% 001
NewDocumentCommand{arealII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
}%
codeclip{%
EreignisB
}%
}%
EreignisC*[#1][#2]%
endpsclip
}
% 010
NewDocumentCommand{arealIII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
}%
codeclip{%
EreignisC
}%
}%
EreignisB*[#1][#2]%
endpsclip
}
% 011
NewDocumentCommand{arealIV}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisB
EreignisC
}%
codeclip{%
EreignisA
}%
}%
EreignisB*[#1][#2]%
EreignisC*[#1][#2]%
endpsclip
}
% 100
NewDocumentCommand{arealV}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisB
}%
codeclip{%
EreignisC
}%
}%
EreignisA*[#1][#2]%
endpsclip
}
% 101
NewDocumentCommand{arealVI}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisC
}%
codeclip{%
EreignisB
}%
}%
EreignisA*[#1][#2]%
EreignisC*[#1][#2]%
endpsclip
}
% 110
NewDocumentCommand{arealVII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
}%
codeclip{%
EreignisC
}%
}%
EreignisA*[#1][#2]%
EreignisB*[#1][#2]%
endpsclip
}
% 111
NewDocumentCommand{arealVIII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
}%
codeclip{%
EreignisA
EreignisC
}%
codeclip{%
EreignisB
EreignisC
}%
}%
EreignisA*[#1][#2]%
EreignisB*[#1][#2]%
EreignisC*[#1][#2]%
endpsclip
}
%ExplSyntaxOff

%xintverbosetrue
makeatletter
newcommandVennFromTeX[1]{%
VennFromTeX@main #1%
}%
defVennFromTeX@main$#1${%
begingroup
xintglobaldefstrue
defoverline##1{!(##1)}% or not(##1)
defcap{&&}% or 'and'
defcup{||}% or 'or'
defoplus{ 'xor' }%
defsetminus##1{ifx(##1&&!(else &&!(##1)fi}%
letbiglempty
letbigrempty
% ....
% (add above all needed extra definitions: letBiglempty etc...)
xintdeffunc MyBool(A, B, C) := #1;% #1 must use A, B, C only
endgroup
% we could make a loop here (using @Roman), but let's stay simple
% I trust xparse experts can wrap this up in macros allowing to customize
% the colors
% ATTENTION THAT THESE arealI...VIII ARE NOT THE SAME AS IN @THOMAS ANSWER
xintifboolexpr{MyBool(0, 0, 0)}{arealI[cyan][0.8]}{}%
xintifboolexpr{MyBool(0, 0, 1)}{arealII[cyan][0.8]}{}%
xintifboolexpr{MyBool(0, 1, 0)}{arealIII[cyan][0.8]}{}%
xintifboolexpr{MyBool(0, 1, 1)}{arealIV[cyan][0.8]}{}%
xintifboolexpr{MyBool(1, 0, 0)}{arealV[cyan][0.8]}{}%
xintifboolexpr{MyBool(1, 0, 1)}{arealVI[cyan][0.8]}{}%
xintifboolexpr{MyBool(1, 1, 0)}{arealVII[cyan][0.8]}{}%
xintifboolexpr{MyBool(1, 1, 1)}{arealVIII[cyan][0.8]}{}%
EndeEllipsen{$#1$}%
}%
makeatother

begin{document}

%testing if I, II, ..., VIII are as expected
% makeatletter
% xintFor*#1in{xintSeq{0}{7}}do{%
% begin{pspicture}(0,-1)(5,4)
% rput(2,0){thenumexpr1+#1}
% @nameuse{areal@Roman{numexpr1+#1}}[cyan][0.8]
% EndeEllipsen{}
% end{pspicture}
% }%
% end{document}


begin{pspicture}(0,-1)(5,4)
VennFromTeX{$Acap Bcap C$}%
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennFromTeX{$Acap (Bcup C)$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennFromTeX{$(overline{A}cap overline{B})cup C$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennFromTeX{$overline{A}setminus (Bcap C)$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennFromTeX{$(overline{A}setminus B)cap C$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennFromTeX{$(Asetminus B)cup (Bcap C)$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennFromTeX{$bigl((Acap B)cup (Acap C)bigr)setminus(Acap Bcap C)$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennFromTeX{$Aoplus Boplus C$}
end{pspicture}

end{document}


Produces



enter image description here



enter image description here



enter image description here



enter image description here



enter image description here



enter image description here



enter image description here



enter image description here







Here is code to generate all 256 Venn diagrams. Just insert it in body of above document and don't forget to add usepackage{xintbinhex} to preamble.



% generating all graphics

% 0<= n <= 255 has eight binary digits
% abcdefgh
% a=1 -> region VIII is included (A cap B cap C)
% b=1 -> region VII is included
% ...
% h=1 -> region I is included (overline{A}cap overline{B} cap overline{C})
% We want also to describe the region as a formula...
% We could use 8 xintFor loops #1, ..., #8, but then
% we still need to convert #1*7 to binary, #2*6, #3*5 etc...
% I thus use xintbinhex per convenience but ifodd would be enough
% As I use xintbinhex, I also use a single xintFor* loop

%defgobbleone#1{}%
defgobbletwo#1#2{}%
xintFor* #1 in {xintSeq{0}{255}}:
{%
xintDigitsOfxintDecToBin{thenumexpr256+#1relax}toRegions
% due to leading 1 there will be a shift of indexing in Regions
edefx{xintifboolexpr{Regions{thenumexpr9-0}}% 000
{unexpanded{allowbreakcup
overline{A}capoverline{B}capoverline{C}}}%
{}%
xintifboolexpr{Regions{9-1}}% 001
{unexpanded{allowbreakcup overline{A}capoverline{B}cap C}}%
{}%
xintifboolexpr{Regions{9-2}}% 010
{unexpanded{allowbreakcup overline{A}cap B capoverline{C}}}%
{}%
xintifboolexpr{Regions{9-3}}% 011
{unexpanded{allowbreakcup overline{A} cap B cap C}}%
{}%
xintifboolexpr{Regions{9-4}}% 100
{unexpanded{allowbreakcup Acap overline{B}cap overline{C}}}%
{}%
xintifboolexpr{Regions{9-5}}% 101
{unexpanded{allowbreakcup Acap overline{B}cap C}}%
{}%
xintifboolexpr{Regions{9-6}}% 110
{unexpanded{allowbreakcup Acap Bcap overline{C}}}%
{}%
xintifboolexpr{Regions{9-7}}% 111
{unexpanded{allowbreakcup Acap B cap C}}%
{}%
}%
xintifForFirst{defx{emptyset}}
{oodefx{expandaftergobbletwox}}%
begin{pspicture}(0,-2)(5,4)
% I will leave here each Region as individual call, so a color can
% be added by modifying this code
xintifboolexpr{Regions{9-0}}{arealI[cyan][0.8]}{}%
xintifboolexpr{Regions{9-1}}{arealII[cyan][0.8]}{}%
xintifboolexpr{Regions{9-2}}{arealIII[cyan][0.8]}{}%
xintifboolexpr{Regions{9-3}}{arealIV[cyan][0.8]}{}%
xintifboolexpr{Regions{9-4}}{arealV[cyan][0.8]}{}%
xintifboolexpr{Regions{9-5}}{arealVI[cyan][0.8]}{}%
xintifboolexpr{Regions{9-6}}{arealVII[cyan][0.8]}{}%
xintifboolexpr{Regions{9-7}}{arealVIII[cyan][0.8]}{}%
EndeEllipsen{parbox{4cm}{centering$x$}}%
end{pspicture}%
}%


Defect: the description of the set is as a disjoint union of atomic events. There might be some canonical shorter description but I never really thought about it. For example one of those diagram will represent $Omegasetminus A$ but this not the way it will be legended.



Here is how this example comes out (on page 16 of document with nothing else, i.e. it corresponds to #1 = 15 in the loop, 15=1111 means to keep atomic events 0=000, 1=001, 2=010, 3=011, which is complement of A in Omega.



enter image description here







Here is now with 4 sets.



This time, with TikZ code (I know neither PSTricks nor TikZ and can only survive from copying pre-existing drawing instructions; in this case I started from https://tex.stackexchange.com/a/100091/4686 by @JohnHammersley in 2013).



First I include an image of all atomic events, which are the regions to which the Atomic... macros in code next refer. (this was done for checking while preparing answer)



enter image description here



Here is the code for VennFromTeX, use it as VennFromTeX{$ set formula with A, B, C, D $}. Same instructions as above for three sets.
(one may wish to enlarge the syntax for example by allowing use of U or Omega and defining it in xintexpr to be simply 1, and similarly emptyset could be defined to be 0).



documentclass[12pt, tikz, border=10pt]{standalone}

usepackage{tikz}

usetikzlibrary{positioning,shapes.geometric}

usepackage{xintexpr}% for VennFromTeX


% For drawing
deffirstellip{(-1.6, 0) ellipse [x radius=3cm, y radius=1.5cm, rotate=-50]}
defsecondellip{(-0.3, 1cm) ellipse [x radius=3cm, y radius=1.5cm, rotate=-50]}
defthirdellip{(0.3, 1cm) ellipse [x radius=3cm, y radius=1.5cm, rotate=50]}
deffourthellip{(1.6, 0) ellipse [x radius=3cm, y radius=1.5cm, rotate=50]}

defbounding{(-5,-3) rectangle (5,4)}

% Elementary sets
% ABCD
% abcd a, b, c, d in {0, 1}
defAtomic{% 0000
begin{scope}[even odd rule]% exterior
clip firstellip (-5,-5) rectangle (5,5);
clip secondellip (-5,-5) rectangle (5,5);
clip thirdellip (-5,-5) rectangle (5,5);
clip fourthellip (-5,-5) rectangle (5,5);
fill[yellow] bounding;
end{scope}
}%
defAtomici{% 0001
begin{scope}[even odd rule]% fourth ellipse corner
clip firstellip (-5,-5) rectangle (5,5);
clip secondellip (-5,-5) rectangle (5,5);
clip thirdellip (-5,-5) rectangle (5,5);
fill[yellow] fourthellip;
end{scope}
}%
defAtomicii{% 0010
begin{scope}[even odd rule]% third ellipse corner
clip firstellip (-5,-5) rectangle (5,5);
clip secondellip (-5,-5) rectangle (5,5);
clip fourthellip (-5,-5) rectangle (5,5);
fill[yellow] thirdellip;
end{scope}
}%
defAtomiciii{% 0011
begin{scope}[even odd rule]%
clip firstellip (-5,-5) rectangle (5,5);
clip secondellip (-5,-5) rectangle (5,5);
clip fourthellip;
fill[yellow] thirdellip;
end{scope}
}%
defAtomiciv{% 0100
begin{scope}[even odd rule]% second ellipse corner
clip firstellip (-5,-5) rectangle (5,5);
clip thirdellip (-5,-5) rectangle (5,5);
clip fourthellip (-5,-5) rectangle (5,5);
fill[yellow] secondellip;
end{scope}
}%
defAtomicv{% 0101
begin{scope}[even odd rule]%
clip firstellip (-5,-5) rectangle (5,5);
clip thirdellip (-5,-5) rectangle (5,5);
clip fourthellip;
fill[yellow] secondellip;
end{scope}
}%
defAtomicvi{% 0110
begin{scope}[even odd rule]%
clip firstellip (-5,-5) rectangle (5,5);
clip thirdellip;
clip fourthellip (-5,-5) rectangle (5,5);
fill[yellow] secondellip;
end{scope}
}%
defAtomicvii{% 0111
begin{scope}[even odd rule]%
clip firstellip (-5,-5) rectangle (5,5);
clip thirdellip;
clip fourthellip;
fill[yellow] secondellip;
end{scope}
}%
defAtomicviii{% 1000
begin{scope}[even odd rule]%
clip secondellip (-5,-5) rectangle (5,5);
clip thirdellip (-5,-5) rectangle (5,5);
clip fourthellip (-5,-5) rectangle (5,5);
fill[yellow] firstellip;
end{scope}
}%
defAtomicix{% 1001
begin{scope}[even odd rule]%
clip secondellip (-5,-5) rectangle (5,5);
clip thirdellip (-5,-5) rectangle (5,5);
clip fourthellip;
fill[yellow] firstellip;
end{scope}
}%
defAtomicx{% 1010
begin{scope}[even odd rule]%
clip secondellip (-5,-5) rectangle (5,5);
clip thirdellip;
clip fourthellip (-5,-5) rectangle (5,5);
fill[yellow] firstellip;
end{scope}
}%
defAtomicxi{% 1011
begin{scope}[even odd rule]%
clip secondellip (-5,-5) rectangle (5,5);
clip thirdellip;
clip fourthellip;
fill[yellow] firstellip;
end{scope}
}%
defAtomicxii{% 1100
begin{scope}[even odd rule]%
clip secondellip;
clip thirdellip (-5,-5) rectangle (5,5);
clip fourthellip (-5,-5) rectangle (5,5);
fill[yellow] firstellip;
end{scope}
}%
defAtomicxiii{% 1101
begin{scope}[even odd rule]%
clip secondellip;
clip thirdellip (-5,-5) rectangle (5,5);
clip fourthellip;
fill[yellow] firstellip;
end{scope}
}%
defAtomicxiv{% 1110
begin{scope}[even odd rule]%
clip secondellip;
clip thirdellip;
clip fourthellip (-5,-5) rectangle (5,5);
fill[yellow] firstellip;
end{scope}
}%
defAtomicxv{% 1111
begin{scope}[even odd rule]%
clip secondellip;
clip thirdellip;
clip fourthellip;
fill[yellow] firstellip;
end{scope}
}%

makeatletter
newcommandVennFromTeX[1]{VennFromTeX@main #1}%

defVennFromTeX@main$#1${%
begingroup
xintglobaldefstrue
defoverline##1{!(##1)}% or not(##1)
defcap{&&}% or 'and'
defcup{||}% or 'or'
defoplus{ 'xor' }%
defsetminus##1{ifx(##1&&!(else &&!(##1)fi}%
letbiglempty
letbigrempty
% ....
% (add above all needed extra definitions: letBiglempty etc...)
xintdeffunc MyBool(A, B, C, D) := #1;% #1 must use A, B, C, Donly
endgroup
begin{tikzpicture}

xintFor* ##1 in {01}:
{%
xintFor* ##2 in {01}:
{%
xintFor* ##3 in {01}:
{%
xintFor* ##4 in {01}:
{%
xintifboolexpr{MyBool(##1, ##2, ##3, ##4)}
{csname
Atomicromannumeralnumexpr##1*8+##2*4+##3*2+##4endcsname}%
{}%
}%
}%
}%
}%
draw bounding;

% fill[white] firstellip;
% fill[white] secondellip;
% fill[white] thirdellip;
% fill[white] fourthellip;

draw firstellip node [label={[xshift=-2cm, yshift=-0.9cm]$A$}] {};
draw secondellip node [label={[xshift=-2.1cm, yshift=2.1cm]$B$}] {};
draw thirdellip node [label={[xshift=2.1cm, yshift=2.1cm]$C$}] {};
draw fourthellip node [label={[xshift=2cm, yshift=-0.9cm]$D$}] {};

draw bounding node [label=below left:$U$] {};

draw (0, 0) node [yshift=+4.4cm] {$#1$};

end{tikzpicture}
}%
makeatother
begin{document}

% xintverbosetrue

VennFromTeX{$Acap Bcap Ccap D$}

VennFromTeX{$(Acap B)cup (Ccap D)$}

VennFromTeX{$(overline{A}cupoverline{B})cap(overline{C}cupoverline{D})$}

% attention to use parentheses for disambiguating setminus

VennFromTeX{$(Acup B cup C) setminus(Bcup Ccup D)$}

VennFromTeX{$(Acup B cup C) cap (Bcup Ccup D)$}

VennFromTeX{$((Asetminus (Bcup Ccup D)) cup Bcap Ccap
D)setminus (Acap Bcap Ccap D)$}

end{document}


Be careful to read the caveat top regarding usage of setminus in input.



enter image description here



enter image description here



enter image description here



enter image description here



enter image description here



enter image description here



and finally



enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








edited Dec 2 at 22:39

























answered Dec 2 at 11:00









jfbu

45.4k65145




45.4k65145












  • (+1) Thank you for your answer!
    – chishimotoji
    Dec 2 at 11:27










  • (+1) Wow, fantastic!
    – Thomas
    Dec 2 at 11:34










  • Encyclopedic answer
    – Diaa
    Dec 2 at 11:38










  • careful in first part of answer when inputting a long formula that it some parts may be cut off the page, check the parbox in second part how to work around that, and I also increased the vertical dimension.
    – jfbu
    Dec 2 at 12:46






  • 1




    @ArtificialStupidity I have to get dinner but just give me time to learn PSTricks and I can do with 4 sets afterwards...
    – jfbu
    Dec 2 at 18:39


















  • (+1) Thank you for your answer!
    – chishimotoji
    Dec 2 at 11:27










  • (+1) Wow, fantastic!
    – Thomas
    Dec 2 at 11:34










  • Encyclopedic answer
    – Diaa
    Dec 2 at 11:38










  • careful in first part of answer when inputting a long formula that it some parts may be cut off the page, check the parbox in second part how to work around that, and I also increased the vertical dimension.
    – jfbu
    Dec 2 at 12:46






  • 1




    @ArtificialStupidity I have to get dinner but just give me time to learn PSTricks and I can do with 4 sets afterwards...
    – jfbu
    Dec 2 at 18:39
















(+1) Thank you for your answer!
– chishimotoji
Dec 2 at 11:27




(+1) Thank you for your answer!
– chishimotoji
Dec 2 at 11:27












(+1) Wow, fantastic!
– Thomas
Dec 2 at 11:34




(+1) Wow, fantastic!
– Thomas
Dec 2 at 11:34












Encyclopedic answer
– Diaa
Dec 2 at 11:38




Encyclopedic answer
– Diaa
Dec 2 at 11:38












careful in first part of answer when inputting a long formula that it some parts may be cut off the page, check the parbox in second part how to work around that, and I also increased the vertical dimension.
– jfbu
Dec 2 at 12:46




careful in first part of answer when inputting a long formula that it some parts may be cut off the page, check the parbox in second part how to work around that, and I also increased the vertical dimension.
– jfbu
Dec 2 at 12:46




1




1




@ArtificialStupidity I have to get dinner but just give me time to learn PSTricks and I can do with 4 sets afterwards...
– jfbu
Dec 2 at 18:39




@ArtificialStupidity I have to get dinner but just give me time to learn PSTricks and I can do with 4 sets afterwards...
– jfbu
Dec 2 at 18:39










up vote
12
down vote













documentclass[pstricks]{standalone}
begin{document}
begin{pspicture}(-5,-5)(5,5)
pscustom[fillstyle=eofill,fillcolor=blue,linecolor=blue]{%
pscircle(1.5;90){3}
pscircle(1.5;-30){3}
pscircle(1.5;210){3}
}
end{pspicture}
end{document}


enter image description here



Some other simple example:



documentclass[pstricks]{standalone}
usepackage{pstricks}
begin{document}
begin{pspicture}(-3.2,-3.2)(3.2,3.2)
pscircle[fillstyle=solid,fillcolor=blue!40](0,0){3}
psclip{pscircle(-1,0.5){1.5}% these object(s) will clip
pscircle(1,0.5){1.5}}
pscircle[fillstyle=solid,fillcolor=red!40](0,-1){1.5}% from this object
endpsclip
pscircle(-1,0.5){1.5}% to get the clipped circle lines
pscircle(0,-1){1.5}
pscircle(1,0.5){1.5}
end{pspicture}

begin{pspicture}(-3.2,-3.2)(3.2,3.2)
pscircle[fillstyle=solid,fillcolor=blue!40](0,0){3}
psclip{pscircle(-1,0.5){1.5}}
pscircle[fillstyle=solid,fillcolor=red!40](0,-1){1.5}
pscircle[fillstyle=solid,fillcolor=red!40](1,0.5){1.5}
endpsclip
pscircle(-1,0.5){1.5}
pscircle(0,-1){1.5}
pscircle(1,0.5){1.5}
end{pspicture}

begin{pspicture}(-3.2,-3.2)(3.2,3.2)
pscircle[fillstyle=solid,fillcolor=blue!40](0,0){3}
psclip{pscircle(0,-1){1.5}}
pscircle[fillstyle=solid,fillcolor=red!40](-1,0.5){1.5}
pscircle[fillstyle=solid,fillcolor=red!40](1,0.5){1.5}
endpsclip
pscircle(-1,0.5){1.5}
pscircle(0,-1){1.5}
pscircle(1,0.5){1.5}
end{pspicture}

begin{pspicture}(-3.2,-3.2)(3.2,3.2)
pscircle[fillstyle=solid,fillcolor=blue!40](0,0){3}
psclip{pscircle(0,-1){1.5}}
pscircle[fillstyle=solid,fillcolor=red!40](1,0.5){1.5}
endpsclip
pscircle[fillstyle=solid,fillcolor=red!40](-1,0.5){1.5}
pscircle(0,-1){1.5}
pscircle(1,0.5){1.5}
end{pspicture}

end{document}


enter image description hereenter image description here






share|improve this answer



















  • 1




    I haven't known that there is a option as " fillstyle=eofill " before. It doesn't within PStrick User's Guide.
    – chishimotoji
    Nov 30 at 8:38






  • 1




    tug.org/PSTricks/main.cgi?file=Examples/Box/boxfill#2
    – Herbert
    Nov 30 at 11:20










  • I am really impressived by your code. Only with psclip,pscustom, you created some the interesting result. I have deleted more three comments before. May be my knowledge about psclip is not enough to generate several thing which I want. :((((
    – chishimotoji
    Dec 2 at 15:38








  • 2




    clipping is nothing else than taking a knife let it go along a circle or two corcles and cut everything from a given cake. psclip{the way of the knife} ... the cake .. endpsclip
    – Herbert
    Dec 2 at 15:41















up vote
12
down vote













documentclass[pstricks]{standalone}
begin{document}
begin{pspicture}(-5,-5)(5,5)
pscustom[fillstyle=eofill,fillcolor=blue,linecolor=blue]{%
pscircle(1.5;90){3}
pscircle(1.5;-30){3}
pscircle(1.5;210){3}
}
end{pspicture}
end{document}


enter image description here



Some other simple example:



documentclass[pstricks]{standalone}
usepackage{pstricks}
begin{document}
begin{pspicture}(-3.2,-3.2)(3.2,3.2)
pscircle[fillstyle=solid,fillcolor=blue!40](0,0){3}
psclip{pscircle(-1,0.5){1.5}% these object(s) will clip
pscircle(1,0.5){1.5}}
pscircle[fillstyle=solid,fillcolor=red!40](0,-1){1.5}% from this object
endpsclip
pscircle(-1,0.5){1.5}% to get the clipped circle lines
pscircle(0,-1){1.5}
pscircle(1,0.5){1.5}
end{pspicture}

begin{pspicture}(-3.2,-3.2)(3.2,3.2)
pscircle[fillstyle=solid,fillcolor=blue!40](0,0){3}
psclip{pscircle(-1,0.5){1.5}}
pscircle[fillstyle=solid,fillcolor=red!40](0,-1){1.5}
pscircle[fillstyle=solid,fillcolor=red!40](1,0.5){1.5}
endpsclip
pscircle(-1,0.5){1.5}
pscircle(0,-1){1.5}
pscircle(1,0.5){1.5}
end{pspicture}

begin{pspicture}(-3.2,-3.2)(3.2,3.2)
pscircle[fillstyle=solid,fillcolor=blue!40](0,0){3}
psclip{pscircle(0,-1){1.5}}
pscircle[fillstyle=solid,fillcolor=red!40](-1,0.5){1.5}
pscircle[fillstyle=solid,fillcolor=red!40](1,0.5){1.5}
endpsclip
pscircle(-1,0.5){1.5}
pscircle(0,-1){1.5}
pscircle(1,0.5){1.5}
end{pspicture}

begin{pspicture}(-3.2,-3.2)(3.2,3.2)
pscircle[fillstyle=solid,fillcolor=blue!40](0,0){3}
psclip{pscircle(0,-1){1.5}}
pscircle[fillstyle=solid,fillcolor=red!40](1,0.5){1.5}
endpsclip
pscircle[fillstyle=solid,fillcolor=red!40](-1,0.5){1.5}
pscircle(0,-1){1.5}
pscircle(1,0.5){1.5}
end{pspicture}

end{document}


enter image description hereenter image description here






share|improve this answer



















  • 1




    I haven't known that there is a option as " fillstyle=eofill " before. It doesn't within PStrick User's Guide.
    – chishimotoji
    Nov 30 at 8:38






  • 1




    tug.org/PSTricks/main.cgi?file=Examples/Box/boxfill#2
    – Herbert
    Nov 30 at 11:20










  • I am really impressived by your code. Only with psclip,pscustom, you created some the interesting result. I have deleted more three comments before. May be my knowledge about psclip is not enough to generate several thing which I want. :((((
    – chishimotoji
    Dec 2 at 15:38








  • 2




    clipping is nothing else than taking a knife let it go along a circle or two corcles and cut everything from a given cake. psclip{the way of the knife} ... the cake .. endpsclip
    – Herbert
    Dec 2 at 15:41













up vote
12
down vote










up vote
12
down vote









documentclass[pstricks]{standalone}
begin{document}
begin{pspicture}(-5,-5)(5,5)
pscustom[fillstyle=eofill,fillcolor=blue,linecolor=blue]{%
pscircle(1.5;90){3}
pscircle(1.5;-30){3}
pscircle(1.5;210){3}
}
end{pspicture}
end{document}


enter image description here



Some other simple example:



documentclass[pstricks]{standalone}
usepackage{pstricks}
begin{document}
begin{pspicture}(-3.2,-3.2)(3.2,3.2)
pscircle[fillstyle=solid,fillcolor=blue!40](0,0){3}
psclip{pscircle(-1,0.5){1.5}% these object(s) will clip
pscircle(1,0.5){1.5}}
pscircle[fillstyle=solid,fillcolor=red!40](0,-1){1.5}% from this object
endpsclip
pscircle(-1,0.5){1.5}% to get the clipped circle lines
pscircle(0,-1){1.5}
pscircle(1,0.5){1.5}
end{pspicture}

begin{pspicture}(-3.2,-3.2)(3.2,3.2)
pscircle[fillstyle=solid,fillcolor=blue!40](0,0){3}
psclip{pscircle(-1,0.5){1.5}}
pscircle[fillstyle=solid,fillcolor=red!40](0,-1){1.5}
pscircle[fillstyle=solid,fillcolor=red!40](1,0.5){1.5}
endpsclip
pscircle(-1,0.5){1.5}
pscircle(0,-1){1.5}
pscircle(1,0.5){1.5}
end{pspicture}

begin{pspicture}(-3.2,-3.2)(3.2,3.2)
pscircle[fillstyle=solid,fillcolor=blue!40](0,0){3}
psclip{pscircle(0,-1){1.5}}
pscircle[fillstyle=solid,fillcolor=red!40](-1,0.5){1.5}
pscircle[fillstyle=solid,fillcolor=red!40](1,0.5){1.5}
endpsclip
pscircle(-1,0.5){1.5}
pscircle(0,-1){1.5}
pscircle(1,0.5){1.5}
end{pspicture}

begin{pspicture}(-3.2,-3.2)(3.2,3.2)
pscircle[fillstyle=solid,fillcolor=blue!40](0,0){3}
psclip{pscircle(0,-1){1.5}}
pscircle[fillstyle=solid,fillcolor=red!40](1,0.5){1.5}
endpsclip
pscircle[fillstyle=solid,fillcolor=red!40](-1,0.5){1.5}
pscircle(0,-1){1.5}
pscircle(1,0.5){1.5}
end{pspicture}

end{document}


enter image description hereenter image description here






share|improve this answer














documentclass[pstricks]{standalone}
begin{document}
begin{pspicture}(-5,-5)(5,5)
pscustom[fillstyle=eofill,fillcolor=blue,linecolor=blue]{%
pscircle(1.5;90){3}
pscircle(1.5;-30){3}
pscircle(1.5;210){3}
}
end{pspicture}
end{document}


enter image description here



Some other simple example:



documentclass[pstricks]{standalone}
usepackage{pstricks}
begin{document}
begin{pspicture}(-3.2,-3.2)(3.2,3.2)
pscircle[fillstyle=solid,fillcolor=blue!40](0,0){3}
psclip{pscircle(-1,0.5){1.5}% these object(s) will clip
pscircle(1,0.5){1.5}}
pscircle[fillstyle=solid,fillcolor=red!40](0,-1){1.5}% from this object
endpsclip
pscircle(-1,0.5){1.5}% to get the clipped circle lines
pscircle(0,-1){1.5}
pscircle(1,0.5){1.5}
end{pspicture}

begin{pspicture}(-3.2,-3.2)(3.2,3.2)
pscircle[fillstyle=solid,fillcolor=blue!40](0,0){3}
psclip{pscircle(-1,0.5){1.5}}
pscircle[fillstyle=solid,fillcolor=red!40](0,-1){1.5}
pscircle[fillstyle=solid,fillcolor=red!40](1,0.5){1.5}
endpsclip
pscircle(-1,0.5){1.5}
pscircle(0,-1){1.5}
pscircle(1,0.5){1.5}
end{pspicture}

begin{pspicture}(-3.2,-3.2)(3.2,3.2)
pscircle[fillstyle=solid,fillcolor=blue!40](0,0){3}
psclip{pscircle(0,-1){1.5}}
pscircle[fillstyle=solid,fillcolor=red!40](-1,0.5){1.5}
pscircle[fillstyle=solid,fillcolor=red!40](1,0.5){1.5}
endpsclip
pscircle(-1,0.5){1.5}
pscircle(0,-1){1.5}
pscircle(1,0.5){1.5}
end{pspicture}

begin{pspicture}(-3.2,-3.2)(3.2,3.2)
pscircle[fillstyle=solid,fillcolor=blue!40](0,0){3}
psclip{pscircle(0,-1){1.5}}
pscircle[fillstyle=solid,fillcolor=red!40](1,0.5){1.5}
endpsclip
pscircle[fillstyle=solid,fillcolor=red!40](-1,0.5){1.5}
pscircle(0,-1){1.5}
pscircle(1,0.5){1.5}
end{pspicture}

end{document}


enter image description hereenter image description here







share|improve this answer














share|improve this answer



share|improve this answer








edited Dec 2 at 15:19

























answered Nov 30 at 8:09









Herbert

267k23406716




267k23406716








  • 1




    I haven't known that there is a option as " fillstyle=eofill " before. It doesn't within PStrick User's Guide.
    – chishimotoji
    Nov 30 at 8:38






  • 1




    tug.org/PSTricks/main.cgi?file=Examples/Box/boxfill#2
    – Herbert
    Nov 30 at 11:20










  • I am really impressived by your code. Only with psclip,pscustom, you created some the interesting result. I have deleted more three comments before. May be my knowledge about psclip is not enough to generate several thing which I want. :((((
    – chishimotoji
    Dec 2 at 15:38








  • 2




    clipping is nothing else than taking a knife let it go along a circle or two corcles and cut everything from a given cake. psclip{the way of the knife} ... the cake .. endpsclip
    – Herbert
    Dec 2 at 15:41














  • 1




    I haven't known that there is a option as " fillstyle=eofill " before. It doesn't within PStrick User's Guide.
    – chishimotoji
    Nov 30 at 8:38






  • 1




    tug.org/PSTricks/main.cgi?file=Examples/Box/boxfill#2
    – Herbert
    Nov 30 at 11:20










  • I am really impressived by your code. Only with psclip,pscustom, you created some the interesting result. I have deleted more three comments before. May be my knowledge about psclip is not enough to generate several thing which I want. :((((
    – chishimotoji
    Dec 2 at 15:38








  • 2




    clipping is nothing else than taking a knife let it go along a circle or two corcles and cut everything from a given cake. psclip{the way of the knife} ... the cake .. endpsclip
    – Herbert
    Dec 2 at 15:41








1




1




I haven't known that there is a option as " fillstyle=eofill " before. It doesn't within PStrick User's Guide.
– chishimotoji
Nov 30 at 8:38




I haven't known that there is a option as " fillstyle=eofill " before. It doesn't within PStrick User's Guide.
– chishimotoji
Nov 30 at 8:38




1




1




tug.org/PSTricks/main.cgi?file=Examples/Box/boxfill#2
– Herbert
Nov 30 at 11:20




tug.org/PSTricks/main.cgi?file=Examples/Box/boxfill#2
– Herbert
Nov 30 at 11:20












I am really impressived by your code. Only with psclip,pscustom, you created some the interesting result. I have deleted more three comments before. May be my knowledge about psclip is not enough to generate several thing which I want. :((((
– chishimotoji
Dec 2 at 15:38






I am really impressived by your code. Only with psclip,pscustom, you created some the interesting result. I have deleted more three comments before. May be my knowledge about psclip is not enough to generate several thing which I want. :((((
– chishimotoji
Dec 2 at 15:38






2




2




clipping is nothing else than taking a knife let it go along a circle or two corcles and cut everything from a given cake. psclip{the way of the knife} ... the cake .. endpsclip
– Herbert
Dec 2 at 15:41




clipping is nothing else than taking a knife let it go along a circle or two corcles and cut everything from a given cake. psclip{the way of the knife} ... the cake .. endpsclip
– Herbert
Dec 2 at 15:41










up vote
9
down vote













A TikZ solution for comparison purposes.



documentclass{article}
usepackage{tikz}
begin{document}
begin{tikzpicture}
draw[even odd rule,fill=blue](0,0)circle(3)(4,0)circle(3)(2,3)circle(3);
end{tikzpicture}
end{document}


Venn



Update: To answer @ArtificialStupidity's comment



Here is a solution with different coordinate points from those of the question asked by the OP. The centres of the circles form an equilateral triangle here.



documentclass{article}
usepackage{tikz}
begin{document}
begin{tikzpicture}
draw[even odd rule,fill=blue](0,0)circle(3)(3,0)circle(3)(60:3)circle(3);
end{tikzpicture}
end{document}


venn-2






share|improve this answer























  • @ArtificialStupidity Yes, as in the figure given as an example by the OP. I didn't change the coordinates.
    – AndréC
    Nov 30 at 12:05










  • +1 for the equilateral triangle Δ
    – stendarr
    Nov 30 at 14:03















up vote
9
down vote













A TikZ solution for comparison purposes.



documentclass{article}
usepackage{tikz}
begin{document}
begin{tikzpicture}
draw[even odd rule,fill=blue](0,0)circle(3)(4,0)circle(3)(2,3)circle(3);
end{tikzpicture}
end{document}


Venn



Update: To answer @ArtificialStupidity's comment



Here is a solution with different coordinate points from those of the question asked by the OP. The centres of the circles form an equilateral triangle here.



documentclass{article}
usepackage{tikz}
begin{document}
begin{tikzpicture}
draw[even odd rule,fill=blue](0,0)circle(3)(3,0)circle(3)(60:3)circle(3);
end{tikzpicture}
end{document}


venn-2






share|improve this answer























  • @ArtificialStupidity Yes, as in the figure given as an example by the OP. I didn't change the coordinates.
    – AndréC
    Nov 30 at 12:05










  • +1 for the equilateral triangle Δ
    – stendarr
    Nov 30 at 14:03













up vote
9
down vote










up vote
9
down vote









A TikZ solution for comparison purposes.



documentclass{article}
usepackage{tikz}
begin{document}
begin{tikzpicture}
draw[even odd rule,fill=blue](0,0)circle(3)(4,0)circle(3)(2,3)circle(3);
end{tikzpicture}
end{document}


Venn



Update: To answer @ArtificialStupidity's comment



Here is a solution with different coordinate points from those of the question asked by the OP. The centres of the circles form an equilateral triangle here.



documentclass{article}
usepackage{tikz}
begin{document}
begin{tikzpicture}
draw[even odd rule,fill=blue](0,0)circle(3)(3,0)circle(3)(60:3)circle(3);
end{tikzpicture}
end{document}


venn-2






share|improve this answer














A TikZ solution for comparison purposes.



documentclass{article}
usepackage{tikz}
begin{document}
begin{tikzpicture}
draw[even odd rule,fill=blue](0,0)circle(3)(4,0)circle(3)(2,3)circle(3);
end{tikzpicture}
end{document}


Venn



Update: To answer @ArtificialStupidity's comment



Here is a solution with different coordinate points from those of the question asked by the OP. The centres of the circles form an equilateral triangle here.



documentclass{article}
usepackage{tikz}
begin{document}
begin{tikzpicture}
draw[even odd rule,fill=blue](0,0)circle(3)(3,0)circle(3)(60:3)circle(3);
end{tikzpicture}
end{document}


venn-2







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 30 at 12:11

























answered Nov 30 at 11:05









AndréC

6,77211140




6,77211140












  • @ArtificialStupidity Yes, as in the figure given as an example by the OP. I didn't change the coordinates.
    – AndréC
    Nov 30 at 12:05










  • +1 for the equilateral triangle Δ
    – stendarr
    Nov 30 at 14:03


















  • @ArtificialStupidity Yes, as in the figure given as an example by the OP. I didn't change the coordinates.
    – AndréC
    Nov 30 at 12:05










  • +1 for the equilateral triangle Δ
    – stendarr
    Nov 30 at 14:03
















@ArtificialStupidity Yes, as in the figure given as an example by the OP. I didn't change the coordinates.
– AndréC
Nov 30 at 12:05




@ArtificialStupidity Yes, as in the figure given as an example by the OP. I didn't change the coordinates.
– AndréC
Nov 30 at 12:05












+1 for the equilateral triangle Δ
– stendarr
Nov 30 at 14:03




+1 for the equilateral triangle Δ
– stendarr
Nov 30 at 14:03










up vote
8
down vote













With this definitions every surface can be colored.



documentclass[pstricks]{standalone}
usepackage{pst-node}
usepackage{xparse,xintexpr}

defradiusK{xinttheiexpr[6] 2*sqrt(3)/3relax}

defKOEA{2.5,2}
defFOEA{radiusK,radiusK}

defKOEB{2,1}
defFOEB{radiusK,radiusK}

defKOEC{3,1}
defFOEC{radiusK,radiusK}

defKOEO{2.5,1.375}
defFOEO{2.5,2.5}

%uncomment the following lines to have ellipses
%defKOEA{1.9,2.2}
%defFOEA{1.4,1}
%
%defKOEB{3.3,2.2}
%defFOEB{1.2,1}
%
%defKOEC{2.75,1.4}
%defFOEC{1.4,1}
%
%defKOEO{2.5,2}
%defFOEO{2.5,2.0}

NewDocumentCommand{EreignisA}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEA)(FOEA)}{%
psellipse(KOEA)(FOEA)}%
}

NewDocumentCommand{EreignisB}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEB)(FOEB)}{%
psellipse(KOEB)(FOEB)}%
}

NewDocumentCommand{EreignisC}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEC)(FOEC)}{%
psellipse(KOEC)(FOEC)}%
}

NewDocumentCommand{EreignisOmega}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEO)(FOEO)}{%
psellipse(KOEO)(FOEO)}%
}

NewDocumentCommand{EndeEllipsen}{sm}{%
EreignisOmega%
pnodes(0.25,3.75){Omega}(0.25,0.25){A}(4.75,3.75){B}(4.75,0.25){C}(2.5,-0.5){E}
pnodes(0.7,3.36){MOmega}(0.85,1.55){MA}(4,3){MB}(3.8,0.75){MC}
EreignisA
EreignisB
EreignisC
rput[t](E){#2}%
IfBooleanF{#1}{%
rput(Omega){$Omega$}pcline[nodesepA=0.25](Omega)(MOmega)
rput(A){$A$}pcline[nodesepA=0.25](A)(MA)
rput(B){$B$}pcline[nodesepA=0.25](B)(MB)
rput(C){$C$}pcline[nodesepA=0.2](C)(MC)
}%
}

NewDocumentCommand{codeclip}{m}{%
pscustom[linestyle=none]{%
code{/clip /eoclip load def}%
psframe(-maxdimen,-maxdimen)(maxdimen,maxdimen)
#1
}%
}

NewDocumentCommand{arealI}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
}%
codeclip{%
EreignisB
}%
codeclip{%
EreignisC
}%
}%
EreignisOmega*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisB
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealIII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealIV}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisB*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealV}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisB
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealVI}{O{cyan}!O{0.8}}{%
psclip{EreignisB}
psclip{EreignisC}%
EreignisA*[#1][#2]%
endpsclip
endpsclip
}

NewDocumentCommand{arealVII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisA
}%
}%
EreignisC*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealVIII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
}%
codeclip{%
EreignisB
}%
}%
EreignisC*[#1][#2]%
endpsclip
}

begin{document}


begin{pspicture}[shift=-4](0,-1)(5,4)
arealI
EndeEllipsen*{$Asetminus C$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealVI
EndeEllipsen*{$Acap Bcap C$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealIII
arealV
arealVI
EndeEllipsen*{$Acap (Bcup C)$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealI
EreignisC*%
EndeEllipsen*{$(overline{A}cap overline{B})cup C$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealI
arealIV
arealVIII
EndeEllipsen*{$overline{A}setminus (Bcap C)$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealVIII
EndeEllipsen*{$(overline{A}setminus B)cap C$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealII
arealV
arealVI
arealVII
EndeEllipsen*{$(Asetminus B)cup (Bcap C)$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealIII
arealV
EndeEllipsen*{$bigl((Acap B)cup (Acap C)bigr)setminus(Acap Bcap C)$}
end{pspicture}


end{document}




Perhaps you want to check out this.



documentclass[pstricks]{standalone}
usepackage{pst-node}
usepackage{xparse,xintexpr}

%defradiusK{xinttheiexpr[6] 2*sqrt(3)/3relax}
%
%defKOEA{2.5,2}
%defFOEA{radiusK,radiusK}
%
%defKOEB{2,1}
%defFOEB{radiusK,radiusK}
%
%defKOEC{3,1}
%defFOEC{radiusK,radiusK}
%
%defKOEO{2.5,1.375}
%defFOEO{2.5,2.5}

%uncomment the following lines to have ellipses
defKOEA{1.9,2.2}
defFOEA{1.4,1}

defKOEB{3.3,2.2}
defFOEB{1.2,1}

defKOEC{2.75,1.4}
defFOEC{1.4,1}

defKOEO{2.5,2}
defFOEO{2.5,2.0}

NewDocumentCommand{EreignisA}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEA)(FOEA)}{%
psellipse(KOEA)(FOEA)}%
}

NewDocumentCommand{EreignisB}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEB)(FOEB)}{%
psellipse(KOEB)(FOEB)}%
}

NewDocumentCommand{EreignisC}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEC)(FOEC)}{%
psellipse(KOEC)(FOEC)}%
}

NewDocumentCommand{EreignisOmega}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEO)(FOEO)}{%
psellipse(KOEO)(FOEO)}%
}

NewDocumentCommand{EndeEllipsen}{sm}{%
EreignisOmega%
pnodes(0.25,3.75){Omega}(0.25,0.25){A}(4.75,3.75){B}(4.75,0.25){C}(2.5,-0.5){E}
pnodes(0.7,3.36){MOmega}(0.85,1.55){MA}(4,3){MB}(3.8,0.75){MC}
EreignisA
EreignisB
EreignisC
rput[t](E){#2}%
IfBooleanF{#1}{%
rput(Omega){$Omega$}pcline[nodesepA=0.25](Omega)(MOmega)
rput(A){$A$}pcline[nodesepA=0.25](A)(MA)
rput(B){$B$}pcline[nodesepA=0.25](B)(MB)
rput(C){$C$}pcline[nodesepA=0.2](C)(MC)
}%
}

NewDocumentCommand{codeclip}{m}{%
pscustom[linestyle=none]{%
code{/clip /eoclip load def}%
psframe(-maxdimen,-maxdimen)(maxdimen,maxdimen)
#1
}%
}

NewDocumentCommand{arealI}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
}%
codeclip{%
EreignisB
}%
codeclip{%
EreignisC
}%
}%
EreignisOmega*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisB
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealIII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealIV}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisB*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealV}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisB
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealVI}{O{cyan}!O{0.8}}{%
psclip{EreignisB}
psclip{EreignisC}%
EreignisA*[#1][#2]%
endpsclip
endpsclip
}

NewDocumentCommand{arealVII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisA
}%
}%
EreignisC*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealVIII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
}%
codeclip{%
EreignisB
}%
}%
EreignisC*[#1][#2]%
endpsclip
}

begin{document}


begin{pspicture}[shift=-4](0,-1)(5,4)
arealI
EndeEllipsen{$Asetminus C$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealVI
EndeEllipsen{$Acap Bcap C$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealIII
arealV
arealVI
EndeEllipsen{$Acap (Bcup C)$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealI
EreignisC*%
EndeEllipsen{$(overline{A}cap overline{B})cup C$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealI
arealIV
arealVIII
EndeEllipsen{$overline{A}setminus (Bcap C)$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealVIII
EndeEllipsen{$(overline{A}setminus B)cap C$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealII
arealV
arealVI
arealVII
EndeEllipsen{$(Asetminus B)cup (Bcap C)$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealIII
arealV
EndeEllipsen{$bigl((Acap B)cup (Acap C)bigr)setminus(Acap Bcap C)$}
end{pspicture}


end{document}




With the help of xint-package using xintFor and xintForpair you can write



VennIII{(2,red),(4,cyan),(6,magenta),(8,green)}{Text}%


so every surface becomes an own color, or you write



VennIII[blue](0.5){2,4,6,8}{Text}%


and all becomes color blue with opacity 0.5.



documentclass[pstricks]{standalone}
usepackage{pst-node}
usepackage{xparse,xintexpr}

defKOEA{1.9,2.2}
defFOEA{1.4,1}

defKOEB{3.3,2.2}
defFOEB{1.2,1}

defKOEC{2.75,1.4}
defFOEC{1.4,1}

defKOEO{2.5,2}
defFOEO{2.5,2.0}

NewDocumentCommand{EreignisA}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEA)(FOEA)}{%
psellipse(KOEA)(FOEA)}%
}

NewDocumentCommand{EreignisB}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEB)(FOEB)}{%
psellipse(KOEB)(FOEB)}%
}

NewDocumentCommand{EreignisC}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEC)(FOEC)}{%
psellipse(KOEC)(FOEC)}%
}

NewDocumentCommand{EreignisOmega}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEO)(FOEO)}{%
psellipse(KOEO)(FOEO)}%
}

NewDocumentCommand{EndeEllipsen}{sm}{%
EreignisOmega%
pnodes(0.25,3.75){Omega}(0.25,0.25){A}(4.75,3.75){B}(4.75,0.25){C}(2.5,-0.5){E}
pnodes(0.7,3.36){MOmega}(0.85,1.55){MA}(4,3){MB}(3.8,0.75){MC}
EreignisA
EreignisB
EreignisC
rput[t](E){#2}%
IfBooleanF{#1}{%
rput(Omega){$Omega$}pcline[nodesepA=0.25](Omega)(MOmega)
rput(A){$A$}pcline[nodesepA=0.25](A)(MA)
rput(B){$B$}pcline[nodesepA=0.25](B)(MB)
rput(C){$C$}pcline[nodesepA=0.2](C)(MC)
}%
}

NewDocumentCommand{codeclip}{m}{%
pscustom[linestyle=none]{%
code{/clip /eoclip load def}%
psframe(-maxdimen,-maxdimen)(maxdimen,maxdimen)
#1
}%
}

%ExplSyntaxOn
NewDocumentCommand{arealI}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
}%
codeclip{%
EreignisB
}%
codeclip{%
EreignisC
}%
}%
EreignisOmega*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisB
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealIII}{!O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealIV}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisB*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealV}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisB
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealVI}{O{cyan}!O{0.8}}{%
psclip{EreignisB}%
psclip{EreignisC}%
EreignisA*[#1][#2]%
endpsclip
endpsclip
}

NewDocumentCommand{arealVII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisA
}%
}%
EreignisC*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealVIII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
}%
codeclip{%
EreignisB
}%
}%
EreignisC*[#1][#2]%
endpsclip
}
%ExplSyntaxOff

NewDocumentCommand{VIIIarea}{O{cyan}O{0.8}m}{%
xintifboolexpr{#3=1}{arealI[#1][#2]}{}%
xintifboolexpr{#3=2}{arealII[#1][#2]}{}%
xintifboolexpr{#3=3}{arealIII[#1][#2]}{}%
xintifboolexpr{#3=4}{arealIV[#1][#2]}{}%
xintifboolexpr{#3=5}{arealV[#1][#2]}{}%
xintifboolexpr{#3=6}{arealVI[#1][#2]}{}%
xintifboolexpr{#3=7}{arealVII[#1][#2]}{}%
xintifboolexpr{#3=8}{arealVIII[#1][#2]}{}%
}

NewDocumentCommand{VennIII}{oD(){0.8}m!g}{%
IfValueTF{#1}%
{%
xintFor ##1 in {#3}do {VIIIarea[#1][#2]{##1}}%
}%
{%
xintForpair ##1##2 in {#3}do {VIIIarea[##2][#2]{##1}}%
}%
EndeEllipsen{IfValueT{#4}{#4}}%
}

begin{document}

begin{pspicture}(0,-1)(5,4)
VennIII{(2,red),(4,cyan),(6,magenta),(8,green)}{Text}%
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennIII[orange]{6}{$Acap Bcap C$}%
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennIII[cyan]{3,5,6}{$Acap (Bcup C)$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennIII[magenta](0.5){1,5,6,7}{$(overline{A}cap overline{B})cup C$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennIII[green](0.2){1,4,8}{$overline{A}setminus (Bcap C)$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennIII[cyan]{8}{$(overline{A}setminus B)cap C$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennIII(1){(2,cyan),(5,orange),(6,green),(7,magenta)}{$(Asetminus B)cup (Bcap C)$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennIII[cyan]{3,5}{$bigl((Acap B)cup (Acap C)bigr)setminus(Acap Bcap C)$}
end{pspicture}


end{document}


enter image description here






share|improve this answer























  • Hey bro, is there a shorter way? Your code seem being enormously complex.
    – chishimotoji
    Dec 1 at 10:48










  • This is because I first create all sorts of single surfaces by clipping. Then you can get any desired combination by fading in this area. This is a bit dull, but much easier to use. For example for area 2, area 4 and area 8you can use begin{pspicture}[shift=-4](0,-1)(5,4) arealI arealIV arealVIII EndeEllipsen{$overline{A}setminus (Bcap C)$} end{pspicture}
    – Thomas
    Dec 1 at 13:45












  • A answer sentence is very good.
    – chishimotoji
    Dec 2 at 0:47















up vote
8
down vote













With this definitions every surface can be colored.



documentclass[pstricks]{standalone}
usepackage{pst-node}
usepackage{xparse,xintexpr}

defradiusK{xinttheiexpr[6] 2*sqrt(3)/3relax}

defKOEA{2.5,2}
defFOEA{radiusK,radiusK}

defKOEB{2,1}
defFOEB{radiusK,radiusK}

defKOEC{3,1}
defFOEC{radiusK,radiusK}

defKOEO{2.5,1.375}
defFOEO{2.5,2.5}

%uncomment the following lines to have ellipses
%defKOEA{1.9,2.2}
%defFOEA{1.4,1}
%
%defKOEB{3.3,2.2}
%defFOEB{1.2,1}
%
%defKOEC{2.75,1.4}
%defFOEC{1.4,1}
%
%defKOEO{2.5,2}
%defFOEO{2.5,2.0}

NewDocumentCommand{EreignisA}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEA)(FOEA)}{%
psellipse(KOEA)(FOEA)}%
}

NewDocumentCommand{EreignisB}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEB)(FOEB)}{%
psellipse(KOEB)(FOEB)}%
}

NewDocumentCommand{EreignisC}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEC)(FOEC)}{%
psellipse(KOEC)(FOEC)}%
}

NewDocumentCommand{EreignisOmega}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEO)(FOEO)}{%
psellipse(KOEO)(FOEO)}%
}

NewDocumentCommand{EndeEllipsen}{sm}{%
EreignisOmega%
pnodes(0.25,3.75){Omega}(0.25,0.25){A}(4.75,3.75){B}(4.75,0.25){C}(2.5,-0.5){E}
pnodes(0.7,3.36){MOmega}(0.85,1.55){MA}(4,3){MB}(3.8,0.75){MC}
EreignisA
EreignisB
EreignisC
rput[t](E){#2}%
IfBooleanF{#1}{%
rput(Omega){$Omega$}pcline[nodesepA=0.25](Omega)(MOmega)
rput(A){$A$}pcline[nodesepA=0.25](A)(MA)
rput(B){$B$}pcline[nodesepA=0.25](B)(MB)
rput(C){$C$}pcline[nodesepA=0.2](C)(MC)
}%
}

NewDocumentCommand{codeclip}{m}{%
pscustom[linestyle=none]{%
code{/clip /eoclip load def}%
psframe(-maxdimen,-maxdimen)(maxdimen,maxdimen)
#1
}%
}

NewDocumentCommand{arealI}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
}%
codeclip{%
EreignisB
}%
codeclip{%
EreignisC
}%
}%
EreignisOmega*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisB
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealIII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealIV}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisB*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealV}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisB
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealVI}{O{cyan}!O{0.8}}{%
psclip{EreignisB}
psclip{EreignisC}%
EreignisA*[#1][#2]%
endpsclip
endpsclip
}

NewDocumentCommand{arealVII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisA
}%
}%
EreignisC*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealVIII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
}%
codeclip{%
EreignisB
}%
}%
EreignisC*[#1][#2]%
endpsclip
}

begin{document}


begin{pspicture}[shift=-4](0,-1)(5,4)
arealI
EndeEllipsen*{$Asetminus C$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealVI
EndeEllipsen*{$Acap Bcap C$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealIII
arealV
arealVI
EndeEllipsen*{$Acap (Bcup C)$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealI
EreignisC*%
EndeEllipsen*{$(overline{A}cap overline{B})cup C$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealI
arealIV
arealVIII
EndeEllipsen*{$overline{A}setminus (Bcap C)$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealVIII
EndeEllipsen*{$(overline{A}setminus B)cap C$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealII
arealV
arealVI
arealVII
EndeEllipsen*{$(Asetminus B)cup (Bcap C)$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealIII
arealV
EndeEllipsen*{$bigl((Acap B)cup (Acap C)bigr)setminus(Acap Bcap C)$}
end{pspicture}


end{document}




Perhaps you want to check out this.



documentclass[pstricks]{standalone}
usepackage{pst-node}
usepackage{xparse,xintexpr}

%defradiusK{xinttheiexpr[6] 2*sqrt(3)/3relax}
%
%defKOEA{2.5,2}
%defFOEA{radiusK,radiusK}
%
%defKOEB{2,1}
%defFOEB{radiusK,radiusK}
%
%defKOEC{3,1}
%defFOEC{radiusK,radiusK}
%
%defKOEO{2.5,1.375}
%defFOEO{2.5,2.5}

%uncomment the following lines to have ellipses
defKOEA{1.9,2.2}
defFOEA{1.4,1}

defKOEB{3.3,2.2}
defFOEB{1.2,1}

defKOEC{2.75,1.4}
defFOEC{1.4,1}

defKOEO{2.5,2}
defFOEO{2.5,2.0}

NewDocumentCommand{EreignisA}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEA)(FOEA)}{%
psellipse(KOEA)(FOEA)}%
}

NewDocumentCommand{EreignisB}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEB)(FOEB)}{%
psellipse(KOEB)(FOEB)}%
}

NewDocumentCommand{EreignisC}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEC)(FOEC)}{%
psellipse(KOEC)(FOEC)}%
}

NewDocumentCommand{EreignisOmega}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEO)(FOEO)}{%
psellipse(KOEO)(FOEO)}%
}

NewDocumentCommand{EndeEllipsen}{sm}{%
EreignisOmega%
pnodes(0.25,3.75){Omega}(0.25,0.25){A}(4.75,3.75){B}(4.75,0.25){C}(2.5,-0.5){E}
pnodes(0.7,3.36){MOmega}(0.85,1.55){MA}(4,3){MB}(3.8,0.75){MC}
EreignisA
EreignisB
EreignisC
rput[t](E){#2}%
IfBooleanF{#1}{%
rput(Omega){$Omega$}pcline[nodesepA=0.25](Omega)(MOmega)
rput(A){$A$}pcline[nodesepA=0.25](A)(MA)
rput(B){$B$}pcline[nodesepA=0.25](B)(MB)
rput(C){$C$}pcline[nodesepA=0.2](C)(MC)
}%
}

NewDocumentCommand{codeclip}{m}{%
pscustom[linestyle=none]{%
code{/clip /eoclip load def}%
psframe(-maxdimen,-maxdimen)(maxdimen,maxdimen)
#1
}%
}

NewDocumentCommand{arealI}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
}%
codeclip{%
EreignisB
}%
codeclip{%
EreignisC
}%
}%
EreignisOmega*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisB
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealIII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealIV}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisB*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealV}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisB
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealVI}{O{cyan}!O{0.8}}{%
psclip{EreignisB}
psclip{EreignisC}%
EreignisA*[#1][#2]%
endpsclip
endpsclip
}

NewDocumentCommand{arealVII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisA
}%
}%
EreignisC*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealVIII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
}%
codeclip{%
EreignisB
}%
}%
EreignisC*[#1][#2]%
endpsclip
}

begin{document}


begin{pspicture}[shift=-4](0,-1)(5,4)
arealI
EndeEllipsen{$Asetminus C$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealVI
EndeEllipsen{$Acap Bcap C$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealIII
arealV
arealVI
EndeEllipsen{$Acap (Bcup C)$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealI
EreignisC*%
EndeEllipsen{$(overline{A}cap overline{B})cup C$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealI
arealIV
arealVIII
EndeEllipsen{$overline{A}setminus (Bcap C)$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealVIII
EndeEllipsen{$(overline{A}setminus B)cap C$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealII
arealV
arealVI
arealVII
EndeEllipsen{$(Asetminus B)cup (Bcap C)$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealIII
arealV
EndeEllipsen{$bigl((Acap B)cup (Acap C)bigr)setminus(Acap Bcap C)$}
end{pspicture}


end{document}




With the help of xint-package using xintFor and xintForpair you can write



VennIII{(2,red),(4,cyan),(6,magenta),(8,green)}{Text}%


so every surface becomes an own color, or you write



VennIII[blue](0.5){2,4,6,8}{Text}%


and all becomes color blue with opacity 0.5.



documentclass[pstricks]{standalone}
usepackage{pst-node}
usepackage{xparse,xintexpr}

defKOEA{1.9,2.2}
defFOEA{1.4,1}

defKOEB{3.3,2.2}
defFOEB{1.2,1}

defKOEC{2.75,1.4}
defFOEC{1.4,1}

defKOEO{2.5,2}
defFOEO{2.5,2.0}

NewDocumentCommand{EreignisA}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEA)(FOEA)}{%
psellipse(KOEA)(FOEA)}%
}

NewDocumentCommand{EreignisB}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEB)(FOEB)}{%
psellipse(KOEB)(FOEB)}%
}

NewDocumentCommand{EreignisC}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEC)(FOEC)}{%
psellipse(KOEC)(FOEC)}%
}

NewDocumentCommand{EreignisOmega}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEO)(FOEO)}{%
psellipse(KOEO)(FOEO)}%
}

NewDocumentCommand{EndeEllipsen}{sm}{%
EreignisOmega%
pnodes(0.25,3.75){Omega}(0.25,0.25){A}(4.75,3.75){B}(4.75,0.25){C}(2.5,-0.5){E}
pnodes(0.7,3.36){MOmega}(0.85,1.55){MA}(4,3){MB}(3.8,0.75){MC}
EreignisA
EreignisB
EreignisC
rput[t](E){#2}%
IfBooleanF{#1}{%
rput(Omega){$Omega$}pcline[nodesepA=0.25](Omega)(MOmega)
rput(A){$A$}pcline[nodesepA=0.25](A)(MA)
rput(B){$B$}pcline[nodesepA=0.25](B)(MB)
rput(C){$C$}pcline[nodesepA=0.2](C)(MC)
}%
}

NewDocumentCommand{codeclip}{m}{%
pscustom[linestyle=none]{%
code{/clip /eoclip load def}%
psframe(-maxdimen,-maxdimen)(maxdimen,maxdimen)
#1
}%
}

%ExplSyntaxOn
NewDocumentCommand{arealI}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
}%
codeclip{%
EreignisB
}%
codeclip{%
EreignisC
}%
}%
EreignisOmega*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisB
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealIII}{!O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealIV}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisB*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealV}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisB
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealVI}{O{cyan}!O{0.8}}{%
psclip{EreignisB}%
psclip{EreignisC}%
EreignisA*[#1][#2]%
endpsclip
endpsclip
}

NewDocumentCommand{arealVII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisA
}%
}%
EreignisC*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealVIII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
}%
codeclip{%
EreignisB
}%
}%
EreignisC*[#1][#2]%
endpsclip
}
%ExplSyntaxOff

NewDocumentCommand{VIIIarea}{O{cyan}O{0.8}m}{%
xintifboolexpr{#3=1}{arealI[#1][#2]}{}%
xintifboolexpr{#3=2}{arealII[#1][#2]}{}%
xintifboolexpr{#3=3}{arealIII[#1][#2]}{}%
xintifboolexpr{#3=4}{arealIV[#1][#2]}{}%
xintifboolexpr{#3=5}{arealV[#1][#2]}{}%
xintifboolexpr{#3=6}{arealVI[#1][#2]}{}%
xintifboolexpr{#3=7}{arealVII[#1][#2]}{}%
xintifboolexpr{#3=8}{arealVIII[#1][#2]}{}%
}

NewDocumentCommand{VennIII}{oD(){0.8}m!g}{%
IfValueTF{#1}%
{%
xintFor ##1 in {#3}do {VIIIarea[#1][#2]{##1}}%
}%
{%
xintForpair ##1##2 in {#3}do {VIIIarea[##2][#2]{##1}}%
}%
EndeEllipsen{IfValueT{#4}{#4}}%
}

begin{document}

begin{pspicture}(0,-1)(5,4)
VennIII{(2,red),(4,cyan),(6,magenta),(8,green)}{Text}%
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennIII[orange]{6}{$Acap Bcap C$}%
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennIII[cyan]{3,5,6}{$Acap (Bcup C)$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennIII[magenta](0.5){1,5,6,7}{$(overline{A}cap overline{B})cup C$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennIII[green](0.2){1,4,8}{$overline{A}setminus (Bcap C)$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennIII[cyan]{8}{$(overline{A}setminus B)cap C$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennIII(1){(2,cyan),(5,orange),(6,green),(7,magenta)}{$(Asetminus B)cup (Bcap C)$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennIII[cyan]{3,5}{$bigl((Acap B)cup (Acap C)bigr)setminus(Acap Bcap C)$}
end{pspicture}


end{document}


enter image description here






share|improve this answer























  • Hey bro, is there a shorter way? Your code seem being enormously complex.
    – chishimotoji
    Dec 1 at 10:48










  • This is because I first create all sorts of single surfaces by clipping. Then you can get any desired combination by fading in this area. This is a bit dull, but much easier to use. For example for area 2, area 4 and area 8you can use begin{pspicture}[shift=-4](0,-1)(5,4) arealI arealIV arealVIII EndeEllipsen{$overline{A}setminus (Bcap C)$} end{pspicture}
    – Thomas
    Dec 1 at 13:45












  • A answer sentence is very good.
    – chishimotoji
    Dec 2 at 0:47













up vote
8
down vote










up vote
8
down vote









With this definitions every surface can be colored.



documentclass[pstricks]{standalone}
usepackage{pst-node}
usepackage{xparse,xintexpr}

defradiusK{xinttheiexpr[6] 2*sqrt(3)/3relax}

defKOEA{2.5,2}
defFOEA{radiusK,radiusK}

defKOEB{2,1}
defFOEB{radiusK,radiusK}

defKOEC{3,1}
defFOEC{radiusK,radiusK}

defKOEO{2.5,1.375}
defFOEO{2.5,2.5}

%uncomment the following lines to have ellipses
%defKOEA{1.9,2.2}
%defFOEA{1.4,1}
%
%defKOEB{3.3,2.2}
%defFOEB{1.2,1}
%
%defKOEC{2.75,1.4}
%defFOEC{1.4,1}
%
%defKOEO{2.5,2}
%defFOEO{2.5,2.0}

NewDocumentCommand{EreignisA}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEA)(FOEA)}{%
psellipse(KOEA)(FOEA)}%
}

NewDocumentCommand{EreignisB}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEB)(FOEB)}{%
psellipse(KOEB)(FOEB)}%
}

NewDocumentCommand{EreignisC}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEC)(FOEC)}{%
psellipse(KOEC)(FOEC)}%
}

NewDocumentCommand{EreignisOmega}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEO)(FOEO)}{%
psellipse(KOEO)(FOEO)}%
}

NewDocumentCommand{EndeEllipsen}{sm}{%
EreignisOmega%
pnodes(0.25,3.75){Omega}(0.25,0.25){A}(4.75,3.75){B}(4.75,0.25){C}(2.5,-0.5){E}
pnodes(0.7,3.36){MOmega}(0.85,1.55){MA}(4,3){MB}(3.8,0.75){MC}
EreignisA
EreignisB
EreignisC
rput[t](E){#2}%
IfBooleanF{#1}{%
rput(Omega){$Omega$}pcline[nodesepA=0.25](Omega)(MOmega)
rput(A){$A$}pcline[nodesepA=0.25](A)(MA)
rput(B){$B$}pcline[nodesepA=0.25](B)(MB)
rput(C){$C$}pcline[nodesepA=0.2](C)(MC)
}%
}

NewDocumentCommand{codeclip}{m}{%
pscustom[linestyle=none]{%
code{/clip /eoclip load def}%
psframe(-maxdimen,-maxdimen)(maxdimen,maxdimen)
#1
}%
}

NewDocumentCommand{arealI}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
}%
codeclip{%
EreignisB
}%
codeclip{%
EreignisC
}%
}%
EreignisOmega*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisB
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealIII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealIV}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisB*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealV}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisB
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealVI}{O{cyan}!O{0.8}}{%
psclip{EreignisB}
psclip{EreignisC}%
EreignisA*[#1][#2]%
endpsclip
endpsclip
}

NewDocumentCommand{arealVII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisA
}%
}%
EreignisC*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealVIII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
}%
codeclip{%
EreignisB
}%
}%
EreignisC*[#1][#2]%
endpsclip
}

begin{document}


begin{pspicture}[shift=-4](0,-1)(5,4)
arealI
EndeEllipsen*{$Asetminus C$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealVI
EndeEllipsen*{$Acap Bcap C$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealIII
arealV
arealVI
EndeEllipsen*{$Acap (Bcup C)$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealI
EreignisC*%
EndeEllipsen*{$(overline{A}cap overline{B})cup C$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealI
arealIV
arealVIII
EndeEllipsen*{$overline{A}setminus (Bcap C)$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealVIII
EndeEllipsen*{$(overline{A}setminus B)cap C$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealII
arealV
arealVI
arealVII
EndeEllipsen*{$(Asetminus B)cup (Bcap C)$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealIII
arealV
EndeEllipsen*{$bigl((Acap B)cup (Acap C)bigr)setminus(Acap Bcap C)$}
end{pspicture}


end{document}




Perhaps you want to check out this.



documentclass[pstricks]{standalone}
usepackage{pst-node}
usepackage{xparse,xintexpr}

%defradiusK{xinttheiexpr[6] 2*sqrt(3)/3relax}
%
%defKOEA{2.5,2}
%defFOEA{radiusK,radiusK}
%
%defKOEB{2,1}
%defFOEB{radiusK,radiusK}
%
%defKOEC{3,1}
%defFOEC{radiusK,radiusK}
%
%defKOEO{2.5,1.375}
%defFOEO{2.5,2.5}

%uncomment the following lines to have ellipses
defKOEA{1.9,2.2}
defFOEA{1.4,1}

defKOEB{3.3,2.2}
defFOEB{1.2,1}

defKOEC{2.75,1.4}
defFOEC{1.4,1}

defKOEO{2.5,2}
defFOEO{2.5,2.0}

NewDocumentCommand{EreignisA}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEA)(FOEA)}{%
psellipse(KOEA)(FOEA)}%
}

NewDocumentCommand{EreignisB}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEB)(FOEB)}{%
psellipse(KOEB)(FOEB)}%
}

NewDocumentCommand{EreignisC}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEC)(FOEC)}{%
psellipse(KOEC)(FOEC)}%
}

NewDocumentCommand{EreignisOmega}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEO)(FOEO)}{%
psellipse(KOEO)(FOEO)}%
}

NewDocumentCommand{EndeEllipsen}{sm}{%
EreignisOmega%
pnodes(0.25,3.75){Omega}(0.25,0.25){A}(4.75,3.75){B}(4.75,0.25){C}(2.5,-0.5){E}
pnodes(0.7,3.36){MOmega}(0.85,1.55){MA}(4,3){MB}(3.8,0.75){MC}
EreignisA
EreignisB
EreignisC
rput[t](E){#2}%
IfBooleanF{#1}{%
rput(Omega){$Omega$}pcline[nodesepA=0.25](Omega)(MOmega)
rput(A){$A$}pcline[nodesepA=0.25](A)(MA)
rput(B){$B$}pcline[nodesepA=0.25](B)(MB)
rput(C){$C$}pcline[nodesepA=0.2](C)(MC)
}%
}

NewDocumentCommand{codeclip}{m}{%
pscustom[linestyle=none]{%
code{/clip /eoclip load def}%
psframe(-maxdimen,-maxdimen)(maxdimen,maxdimen)
#1
}%
}

NewDocumentCommand{arealI}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
}%
codeclip{%
EreignisB
}%
codeclip{%
EreignisC
}%
}%
EreignisOmega*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisB
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealIII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealIV}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisB*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealV}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisB
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealVI}{O{cyan}!O{0.8}}{%
psclip{EreignisB}
psclip{EreignisC}%
EreignisA*[#1][#2]%
endpsclip
endpsclip
}

NewDocumentCommand{arealVII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisA
}%
}%
EreignisC*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealVIII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
}%
codeclip{%
EreignisB
}%
}%
EreignisC*[#1][#2]%
endpsclip
}

begin{document}


begin{pspicture}[shift=-4](0,-1)(5,4)
arealI
EndeEllipsen{$Asetminus C$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealVI
EndeEllipsen{$Acap Bcap C$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealIII
arealV
arealVI
EndeEllipsen{$Acap (Bcup C)$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealI
EreignisC*%
EndeEllipsen{$(overline{A}cap overline{B})cup C$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealI
arealIV
arealVIII
EndeEllipsen{$overline{A}setminus (Bcap C)$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealVIII
EndeEllipsen{$(overline{A}setminus B)cap C$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealII
arealV
arealVI
arealVII
EndeEllipsen{$(Asetminus B)cup (Bcap C)$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealIII
arealV
EndeEllipsen{$bigl((Acap B)cup (Acap C)bigr)setminus(Acap Bcap C)$}
end{pspicture}


end{document}




With the help of xint-package using xintFor and xintForpair you can write



VennIII{(2,red),(4,cyan),(6,magenta),(8,green)}{Text}%


so every surface becomes an own color, or you write



VennIII[blue](0.5){2,4,6,8}{Text}%


and all becomes color blue with opacity 0.5.



documentclass[pstricks]{standalone}
usepackage{pst-node}
usepackage{xparse,xintexpr}

defKOEA{1.9,2.2}
defFOEA{1.4,1}

defKOEB{3.3,2.2}
defFOEB{1.2,1}

defKOEC{2.75,1.4}
defFOEC{1.4,1}

defKOEO{2.5,2}
defFOEO{2.5,2.0}

NewDocumentCommand{EreignisA}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEA)(FOEA)}{%
psellipse(KOEA)(FOEA)}%
}

NewDocumentCommand{EreignisB}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEB)(FOEB)}{%
psellipse(KOEB)(FOEB)}%
}

NewDocumentCommand{EreignisC}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEC)(FOEC)}{%
psellipse(KOEC)(FOEC)}%
}

NewDocumentCommand{EreignisOmega}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEO)(FOEO)}{%
psellipse(KOEO)(FOEO)}%
}

NewDocumentCommand{EndeEllipsen}{sm}{%
EreignisOmega%
pnodes(0.25,3.75){Omega}(0.25,0.25){A}(4.75,3.75){B}(4.75,0.25){C}(2.5,-0.5){E}
pnodes(0.7,3.36){MOmega}(0.85,1.55){MA}(4,3){MB}(3.8,0.75){MC}
EreignisA
EreignisB
EreignisC
rput[t](E){#2}%
IfBooleanF{#1}{%
rput(Omega){$Omega$}pcline[nodesepA=0.25](Omega)(MOmega)
rput(A){$A$}pcline[nodesepA=0.25](A)(MA)
rput(B){$B$}pcline[nodesepA=0.25](B)(MB)
rput(C){$C$}pcline[nodesepA=0.2](C)(MC)
}%
}

NewDocumentCommand{codeclip}{m}{%
pscustom[linestyle=none]{%
code{/clip /eoclip load def}%
psframe(-maxdimen,-maxdimen)(maxdimen,maxdimen)
#1
}%
}

%ExplSyntaxOn
NewDocumentCommand{arealI}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
}%
codeclip{%
EreignisB
}%
codeclip{%
EreignisC
}%
}%
EreignisOmega*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisB
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealIII}{!O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealIV}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisB*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealV}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisB
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealVI}{O{cyan}!O{0.8}}{%
psclip{EreignisB}%
psclip{EreignisC}%
EreignisA*[#1][#2]%
endpsclip
endpsclip
}

NewDocumentCommand{arealVII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisA
}%
}%
EreignisC*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealVIII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
}%
codeclip{%
EreignisB
}%
}%
EreignisC*[#1][#2]%
endpsclip
}
%ExplSyntaxOff

NewDocumentCommand{VIIIarea}{O{cyan}O{0.8}m}{%
xintifboolexpr{#3=1}{arealI[#1][#2]}{}%
xintifboolexpr{#3=2}{arealII[#1][#2]}{}%
xintifboolexpr{#3=3}{arealIII[#1][#2]}{}%
xintifboolexpr{#3=4}{arealIV[#1][#2]}{}%
xintifboolexpr{#3=5}{arealV[#1][#2]}{}%
xintifboolexpr{#3=6}{arealVI[#1][#2]}{}%
xintifboolexpr{#3=7}{arealVII[#1][#2]}{}%
xintifboolexpr{#3=8}{arealVIII[#1][#2]}{}%
}

NewDocumentCommand{VennIII}{oD(){0.8}m!g}{%
IfValueTF{#1}%
{%
xintFor ##1 in {#3}do {VIIIarea[#1][#2]{##1}}%
}%
{%
xintForpair ##1##2 in {#3}do {VIIIarea[##2][#2]{##1}}%
}%
EndeEllipsen{IfValueT{#4}{#4}}%
}

begin{document}

begin{pspicture}(0,-1)(5,4)
VennIII{(2,red),(4,cyan),(6,magenta),(8,green)}{Text}%
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennIII[orange]{6}{$Acap Bcap C$}%
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennIII[cyan]{3,5,6}{$Acap (Bcup C)$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennIII[magenta](0.5){1,5,6,7}{$(overline{A}cap overline{B})cup C$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennIII[green](0.2){1,4,8}{$overline{A}setminus (Bcap C)$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennIII[cyan]{8}{$(overline{A}setminus B)cap C$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennIII(1){(2,cyan),(5,orange),(6,green),(7,magenta)}{$(Asetminus B)cup (Bcap C)$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennIII[cyan]{3,5}{$bigl((Acap B)cup (Acap C)bigr)setminus(Acap Bcap C)$}
end{pspicture}


end{document}


enter image description here






share|improve this answer














With this definitions every surface can be colored.



documentclass[pstricks]{standalone}
usepackage{pst-node}
usepackage{xparse,xintexpr}

defradiusK{xinttheiexpr[6] 2*sqrt(3)/3relax}

defKOEA{2.5,2}
defFOEA{radiusK,radiusK}

defKOEB{2,1}
defFOEB{radiusK,radiusK}

defKOEC{3,1}
defFOEC{radiusK,radiusK}

defKOEO{2.5,1.375}
defFOEO{2.5,2.5}

%uncomment the following lines to have ellipses
%defKOEA{1.9,2.2}
%defFOEA{1.4,1}
%
%defKOEB{3.3,2.2}
%defFOEB{1.2,1}
%
%defKOEC{2.75,1.4}
%defFOEC{1.4,1}
%
%defKOEO{2.5,2}
%defFOEO{2.5,2.0}

NewDocumentCommand{EreignisA}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEA)(FOEA)}{%
psellipse(KOEA)(FOEA)}%
}

NewDocumentCommand{EreignisB}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEB)(FOEB)}{%
psellipse(KOEB)(FOEB)}%
}

NewDocumentCommand{EreignisC}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEC)(FOEC)}{%
psellipse(KOEC)(FOEC)}%
}

NewDocumentCommand{EreignisOmega}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEO)(FOEO)}{%
psellipse(KOEO)(FOEO)}%
}

NewDocumentCommand{EndeEllipsen}{sm}{%
EreignisOmega%
pnodes(0.25,3.75){Omega}(0.25,0.25){A}(4.75,3.75){B}(4.75,0.25){C}(2.5,-0.5){E}
pnodes(0.7,3.36){MOmega}(0.85,1.55){MA}(4,3){MB}(3.8,0.75){MC}
EreignisA
EreignisB
EreignisC
rput[t](E){#2}%
IfBooleanF{#1}{%
rput(Omega){$Omega$}pcline[nodesepA=0.25](Omega)(MOmega)
rput(A){$A$}pcline[nodesepA=0.25](A)(MA)
rput(B){$B$}pcline[nodesepA=0.25](B)(MB)
rput(C){$C$}pcline[nodesepA=0.2](C)(MC)
}%
}

NewDocumentCommand{codeclip}{m}{%
pscustom[linestyle=none]{%
code{/clip /eoclip load def}%
psframe(-maxdimen,-maxdimen)(maxdimen,maxdimen)
#1
}%
}

NewDocumentCommand{arealI}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
}%
codeclip{%
EreignisB
}%
codeclip{%
EreignisC
}%
}%
EreignisOmega*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisB
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealIII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealIV}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisB*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealV}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisB
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealVI}{O{cyan}!O{0.8}}{%
psclip{EreignisB}
psclip{EreignisC}%
EreignisA*[#1][#2]%
endpsclip
endpsclip
}

NewDocumentCommand{arealVII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisA
}%
}%
EreignisC*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealVIII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
}%
codeclip{%
EreignisB
}%
}%
EreignisC*[#1][#2]%
endpsclip
}

begin{document}


begin{pspicture}[shift=-4](0,-1)(5,4)
arealI
EndeEllipsen*{$Asetminus C$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealVI
EndeEllipsen*{$Acap Bcap C$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealIII
arealV
arealVI
EndeEllipsen*{$Acap (Bcup C)$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealI
EreignisC*%
EndeEllipsen*{$(overline{A}cap overline{B})cup C$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealI
arealIV
arealVIII
EndeEllipsen*{$overline{A}setminus (Bcap C)$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealVIII
EndeEllipsen*{$(overline{A}setminus B)cap C$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealII
arealV
arealVI
arealVII
EndeEllipsen*{$(Asetminus B)cup (Bcap C)$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealIII
arealV
EndeEllipsen*{$bigl((Acap B)cup (Acap C)bigr)setminus(Acap Bcap C)$}
end{pspicture}


end{document}




Perhaps you want to check out this.



documentclass[pstricks]{standalone}
usepackage{pst-node}
usepackage{xparse,xintexpr}

%defradiusK{xinttheiexpr[6] 2*sqrt(3)/3relax}
%
%defKOEA{2.5,2}
%defFOEA{radiusK,radiusK}
%
%defKOEB{2,1}
%defFOEB{radiusK,radiusK}
%
%defKOEC{3,1}
%defFOEC{radiusK,radiusK}
%
%defKOEO{2.5,1.375}
%defFOEO{2.5,2.5}

%uncomment the following lines to have ellipses
defKOEA{1.9,2.2}
defFOEA{1.4,1}

defKOEB{3.3,2.2}
defFOEB{1.2,1}

defKOEC{2.75,1.4}
defFOEC{1.4,1}

defKOEO{2.5,2}
defFOEO{2.5,2.0}

NewDocumentCommand{EreignisA}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEA)(FOEA)}{%
psellipse(KOEA)(FOEA)}%
}

NewDocumentCommand{EreignisB}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEB)(FOEB)}{%
psellipse(KOEB)(FOEB)}%
}

NewDocumentCommand{EreignisC}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEC)(FOEC)}{%
psellipse(KOEC)(FOEC)}%
}

NewDocumentCommand{EreignisOmega}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEO)(FOEO)}{%
psellipse(KOEO)(FOEO)}%
}

NewDocumentCommand{EndeEllipsen}{sm}{%
EreignisOmega%
pnodes(0.25,3.75){Omega}(0.25,0.25){A}(4.75,3.75){B}(4.75,0.25){C}(2.5,-0.5){E}
pnodes(0.7,3.36){MOmega}(0.85,1.55){MA}(4,3){MB}(3.8,0.75){MC}
EreignisA
EreignisB
EreignisC
rput[t](E){#2}%
IfBooleanF{#1}{%
rput(Omega){$Omega$}pcline[nodesepA=0.25](Omega)(MOmega)
rput(A){$A$}pcline[nodesepA=0.25](A)(MA)
rput(B){$B$}pcline[nodesepA=0.25](B)(MB)
rput(C){$C$}pcline[nodesepA=0.2](C)(MC)
}%
}

NewDocumentCommand{codeclip}{m}{%
pscustom[linestyle=none]{%
code{/clip /eoclip load def}%
psframe(-maxdimen,-maxdimen)(maxdimen,maxdimen)
#1
}%
}

NewDocumentCommand{arealI}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
}%
codeclip{%
EreignisB
}%
codeclip{%
EreignisC
}%
}%
EreignisOmega*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisB
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealIII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealIV}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisB*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealV}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisB
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealVI}{O{cyan}!O{0.8}}{%
psclip{EreignisB}
psclip{EreignisC}%
EreignisA*[#1][#2]%
endpsclip
endpsclip
}

NewDocumentCommand{arealVII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisA
}%
}%
EreignisC*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealVIII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
}%
codeclip{%
EreignisB
}%
}%
EreignisC*[#1][#2]%
endpsclip
}

begin{document}


begin{pspicture}[shift=-4](0,-1)(5,4)
arealI
EndeEllipsen{$Asetminus C$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealVI
EndeEllipsen{$Acap Bcap C$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealIII
arealV
arealVI
EndeEllipsen{$Acap (Bcup C)$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealI
EreignisC*%
EndeEllipsen{$(overline{A}cap overline{B})cup C$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealI
arealIV
arealVIII
EndeEllipsen{$overline{A}setminus (Bcap C)$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealVIII
EndeEllipsen{$(overline{A}setminus B)cap C$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealII
arealV
arealVI
arealVII
EndeEllipsen{$(Asetminus B)cup (Bcap C)$}
end{pspicture}

begin{pspicture}[shift=-4](0,-1)(5,4)
arealIII
arealV
EndeEllipsen{$bigl((Acap B)cup (Acap C)bigr)setminus(Acap Bcap C)$}
end{pspicture}


end{document}




With the help of xint-package using xintFor and xintForpair you can write



VennIII{(2,red),(4,cyan),(6,magenta),(8,green)}{Text}%


so every surface becomes an own color, or you write



VennIII[blue](0.5){2,4,6,8}{Text}%


and all becomes color blue with opacity 0.5.



documentclass[pstricks]{standalone}
usepackage{pst-node}
usepackage{xparse,xintexpr}

defKOEA{1.9,2.2}
defFOEA{1.4,1}

defKOEB{3.3,2.2}
defFOEB{1.2,1}

defKOEC{2.75,1.4}
defFOEC{1.4,1}

defKOEO{2.5,2}
defFOEO{2.5,2.0}

NewDocumentCommand{EreignisA}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEA)(FOEA)}{%
psellipse(KOEA)(FOEA)}%
}

NewDocumentCommand{EreignisB}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEB)(FOEB)}{%
psellipse(KOEB)(FOEB)}%
}

NewDocumentCommand{EreignisC}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEC)(FOEC)}{%
psellipse(KOEC)(FOEC)}%
}

NewDocumentCommand{EreignisOmega}{sO{cyan}!O{0.8}}{%
IfBooleanTF{#1}{%
psellipse[fillstyle=solid,fillcolor=#2,opacity=#3](KOEO)(FOEO)}{%
psellipse(KOEO)(FOEO)}%
}

NewDocumentCommand{EndeEllipsen}{sm}{%
EreignisOmega%
pnodes(0.25,3.75){Omega}(0.25,0.25){A}(4.75,3.75){B}(4.75,0.25){C}(2.5,-0.5){E}
pnodes(0.7,3.36){MOmega}(0.85,1.55){MA}(4,3){MB}(3.8,0.75){MC}
EreignisA
EreignisB
EreignisC
rput[t](E){#2}%
IfBooleanF{#1}{%
rput(Omega){$Omega$}pcline[nodesepA=0.25](Omega)(MOmega)
rput(A){$A$}pcline[nodesepA=0.25](A)(MA)
rput(B){$B$}pcline[nodesepA=0.25](B)(MB)
rput(C){$C$}pcline[nodesepA=0.2](C)(MC)
}%
}

NewDocumentCommand{codeclip}{m}{%
pscustom[linestyle=none]{%
code{/clip /eoclip load def}%
psframe(-maxdimen,-maxdimen)(maxdimen,maxdimen)
#1
}%
}

%ExplSyntaxOn
NewDocumentCommand{arealI}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
}%
codeclip{%
EreignisB
}%
codeclip{%
EreignisC
}%
}%
EreignisOmega*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisB
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealIII}{!O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealIV}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisC
}%
codeclip{%
EreignisC
}%
}%
EreignisB*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealV}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisB
}%
}%
EreignisA*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealVI}{O{cyan}!O{0.8}}{%
psclip{EreignisB}%
psclip{EreignisC}%
EreignisA*[#1][#2]%
endpsclip
endpsclip
}

NewDocumentCommand{arealVII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
EreignisC
}%
codeclip{%
EreignisA
}%
}%
EreignisC*[#1][#2]%
endpsclip
}

NewDocumentCommand{arealVIII}{O{cyan}!O{0.8}}{%
psclip{%
codeclip{%
EreignisA
EreignisB
}%
codeclip{%
EreignisB
}%
}%
EreignisC*[#1][#2]%
endpsclip
}
%ExplSyntaxOff

NewDocumentCommand{VIIIarea}{O{cyan}O{0.8}m}{%
xintifboolexpr{#3=1}{arealI[#1][#2]}{}%
xintifboolexpr{#3=2}{arealII[#1][#2]}{}%
xintifboolexpr{#3=3}{arealIII[#1][#2]}{}%
xintifboolexpr{#3=4}{arealIV[#1][#2]}{}%
xintifboolexpr{#3=5}{arealV[#1][#2]}{}%
xintifboolexpr{#3=6}{arealVI[#1][#2]}{}%
xintifboolexpr{#3=7}{arealVII[#1][#2]}{}%
xintifboolexpr{#3=8}{arealVIII[#1][#2]}{}%
}

NewDocumentCommand{VennIII}{oD(){0.8}m!g}{%
IfValueTF{#1}%
{%
xintFor ##1 in {#3}do {VIIIarea[#1][#2]{##1}}%
}%
{%
xintForpair ##1##2 in {#3}do {VIIIarea[##2][#2]{##1}}%
}%
EndeEllipsen{IfValueT{#4}{#4}}%
}

begin{document}

begin{pspicture}(0,-1)(5,4)
VennIII{(2,red),(4,cyan),(6,magenta),(8,green)}{Text}%
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennIII[orange]{6}{$Acap Bcap C$}%
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennIII[cyan]{3,5,6}{$Acap (Bcup C)$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennIII[magenta](0.5){1,5,6,7}{$(overline{A}cap overline{B})cup C$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennIII[green](0.2){1,4,8}{$overline{A}setminus (Bcap C)$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennIII[cyan]{8}{$(overline{A}setminus B)cap C$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennIII(1){(2,cyan),(5,orange),(6,green),(7,magenta)}{$(Asetminus B)cup (Bcap C)$}
end{pspicture}

begin{pspicture}(0,-1)(5,4)
VennIII[cyan]{3,5}{$bigl((Acap B)cup (Acap C)bigr)setminus(Acap Bcap C)$}
end{pspicture}


end{document}


enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








edited Dec 1 at 22:36

























answered Dec 1 at 7:23









Thomas

664212




664212












  • Hey bro, is there a shorter way? Your code seem being enormously complex.
    – chishimotoji
    Dec 1 at 10:48










  • This is because I first create all sorts of single surfaces by clipping. Then you can get any desired combination by fading in this area. This is a bit dull, but much easier to use. For example for area 2, area 4 and area 8you can use begin{pspicture}[shift=-4](0,-1)(5,4) arealI arealIV arealVIII EndeEllipsen{$overline{A}setminus (Bcap C)$} end{pspicture}
    – Thomas
    Dec 1 at 13:45












  • A answer sentence is very good.
    – chishimotoji
    Dec 2 at 0:47


















  • Hey bro, is there a shorter way? Your code seem being enormously complex.
    – chishimotoji
    Dec 1 at 10:48










  • This is because I first create all sorts of single surfaces by clipping. Then you can get any desired combination by fading in this area. This is a bit dull, but much easier to use. For example for area 2, area 4 and area 8you can use begin{pspicture}[shift=-4](0,-1)(5,4) arealI arealIV arealVIII EndeEllipsen{$overline{A}setminus (Bcap C)$} end{pspicture}
    – Thomas
    Dec 1 at 13:45












  • A answer sentence is very good.
    – chishimotoji
    Dec 2 at 0:47
















Hey bro, is there a shorter way? Your code seem being enormously complex.
– chishimotoji
Dec 1 at 10:48




Hey bro, is there a shorter way? Your code seem being enormously complex.
– chishimotoji
Dec 1 at 10:48












This is because I first create all sorts of single surfaces by clipping. Then you can get any desired combination by fading in this area. This is a bit dull, but much easier to use. For example for area 2, area 4 and area 8you can use begin{pspicture}[shift=-4](0,-1)(5,4) arealI arealIV arealVIII EndeEllipsen{$overline{A}setminus (Bcap C)$} end{pspicture}
– Thomas
Dec 1 at 13:45






This is because I first create all sorts of single surfaces by clipping. Then you can get any desired combination by fading in this area. This is a bit dull, but much easier to use. For example for area 2, area 4 and area 8you can use begin{pspicture}[shift=-4](0,-1)(5,4) arealI arealIV arealVIII EndeEllipsen{$overline{A}setminus (Bcap C)$} end{pspicture}
– Thomas
Dec 1 at 13:45














A answer sentence is very good.
– chishimotoji
Dec 2 at 0:47




A answer sentence is very good.
– chishimotoji
Dec 2 at 0:47


















draft saved

draft discarded




















































Thanks for contributing an answer to TeX - LaTeX Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f462520%2fhow-to-draw-a-%25e2%258a%2595-b-%25e2%258a%2595-c-as-a-venn-diagram%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

數位音樂下載

When can things happen in Etherscan, such as the picture below?

格利澤436b