19

This question led to a new package:

pst-venn

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.

  • Wonderful package! – JouleV Dec 6 '18 at 10:15
  • Exactly........................! – Trong Vuong Dec 6 '18 at 10:20
20

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

17
+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 A\cap 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}

\def\KOEA{1.9,2.2}
\def\FOEA{1.4,1}

\def\KOEB{3.3,2.2}
\def\FOEB{1.2,1}

\def\KOEC{2.75,1.4}
\def\FOEC{1.4,1}

\def\KOEO{2.5,2}
\def\FOEO{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
\newcommand\VennFromTeX[1]{%
    \VennFromTeX@main #1%
}%
\def\VennFromTeX@main$#1${%
    \begingroup
        \xintglobaldefstrue
        \def\overline##1{!(##1)}% or not(##1)
        \def\cap{&&}% or 'and'
        \def\cup{||}% or 'or'
        \def\oplus{ 'xor' }%
        \def\setminus##1{\ifx(##1&&!(\else &&!(##1)\fi}%
        \let\bigl\empty
        \let\bigr\empty
        % ....
        % (add above all needed extra definitions: \let\Bigl\empty 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){\the\numexpr1+#1}
% \@nameuse{areal\@Roman{\numexpr1+#1}}[cyan][0.8]
% \EndeEllipsen{}
% \end{pspicture}
% }%
% \end{document}


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

\begin{pspicture}(0,-1)(5,4)
\VennFromTeX{$A\cap (B\cup 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 (B\cap 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{$(A\setminus B)\cup (B\cap C)$}
\end{pspicture}

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

\begin{pspicture}(0,-1)(5,4)
\VennFromTeX{$A\oplus B\oplus 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

%\def\gobbleone#1{}%
\def\gobbletwo#1#2{}%
\xintFor* #1 in {\xintSeq{0}{255}}:
{%
   \xintDigitsOf\xintDecToBin{\the\numexpr256+#1\relax}\to\Regions
   % due to leading 1 there will be a shift of indexing in \Regions
   \edef\x{\xintifboolexpr{\Regions{\the\numexpr9-0}}% 000
              {\unexpanded{\allowbreak\cup
                           \overline{A}\cap\overline{B}\cap\overline{C}}}%
              {}%
           \xintifboolexpr{\Regions{9-1}}%  001
              {\unexpanded{\allowbreak\cup \overline{A}\cap\overline{B}\cap C}}%
              {}%
           \xintifboolexpr{\Regions{9-2}}%  010
              {\unexpanded{\allowbreak\cup \overline{A}\cap B \cap\overline{C}}}%
              {}%
           \xintifboolexpr{\Regions{9-3}}% 011
              {\unexpanded{\allowbreak\cup \overline{A} \cap B \cap C}}%
              {}%
           \xintifboolexpr{\Regions{9-4}}% 100
              {\unexpanded{\allowbreak\cup A\cap \overline{B}\cap \overline{C}}}%
              {}%
           \xintifboolexpr{\Regions{9-5}}% 101
              {\unexpanded{\allowbreak\cup A\cap \overline{B}\cap C}}%
              {}%
           \xintifboolexpr{\Regions{9-6}}% 110
              {\unexpanded{\allowbreak\cup A\cap B\cap \overline{C}}}%
              {}%
           \xintifboolexpr{\Regions{9-7}}% 111
              {\unexpanded{\allowbreak\cup A\cap B \cap C}}%
              {}%
    }%
   \xintifForFirst{\def\x{\emptyset}}
                  {\oodef\x{\expandafter\gobbletwo\x}}%
   \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 $\Omega\setminus 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
\def\firstellip{(-1.6, 0) ellipse [x radius=3cm, y radius=1.5cm, rotate=-50]}
\def\secondellip{(-0.3, 1cm) ellipse [x radius=3cm, y radius=1.5cm, rotate=-50]}
\def\thirdellip{(0.3, 1cm) ellipse [x radius=3cm, y radius=1.5cm, rotate=50]}
\def\fourthellip{(1.6, 0) ellipse [x radius=3cm, y radius=1.5cm, rotate=50]}

\def\bounding{(-5,-3) rectangle (5,4)}

% Elementary sets
% ABCD
% abcd a, b, c, d in {0, 1}
\def\Atomic{% 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}
}%
\def\Atomici{% 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}
}%
\def\Atomicii{% 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}
}%
\def\Atomiciii{% 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}
}%
\def\Atomiciv{% 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}
}%
\def\Atomicv{% 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}
}%
\def\Atomicvi{% 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}
}%
\def\Atomicvii{% 0111
        \begin{scope}[even odd rule]%
            \clip \firstellip (-5,-5) rectangle (5,5);
            \clip \thirdellip;
            \clip \fourthellip;
        \fill[yellow] \secondellip;
        \end{scope}
}%
\def\Atomicviii{% 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}
}%
\def\Atomicix{% 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}
}%
\def\Atomicx{% 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}
}%
\def\Atomicxi{% 1011
        \begin{scope}[even odd rule]%
            \clip \secondellip (-5,-5) rectangle (5,5);
            \clip \thirdellip;
            \clip \fourthellip;
        \fill[yellow] \firstellip;
        \end{scope}
}%
\def\Atomicxii{% 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}
}%
\def\Atomicxiii{% 1101
        \begin{scope}[even odd rule]%
            \clip \secondellip;
            \clip \thirdellip (-5,-5) rectangle (5,5);
            \clip \fourthellip;
        \fill[yellow] \firstellip;
        \end{scope}
}%
\def\Atomicxiv{% 1110
        \begin{scope}[even odd rule]%
            \clip \secondellip;
            \clip \thirdellip;
            \clip \fourthellip (-5,-5) rectangle (5,5);
        \fill[yellow] \firstellip;
        \end{scope}
}%
\def\Atomicxv{% 1111
        \begin{scope}[even odd rule]%
            \clip \secondellip;
            \clip \thirdellip;
            \clip \fourthellip;
        \fill[yellow] \firstellip;
        \end{scope}
}%

\makeatletter
\newcommand\VennFromTeX[1]{\VennFromTeX@main #1}%

\def\VennFromTeX@main$#1${%
    \begingroup
        \xintglobaldefstrue
        \def\overline##1{!(##1)}% or not(##1)
        \def\cap{&&}% or 'and'
        \def\cup{||}% or 'or'
        \def\oplus{ 'xor' }%
        \def\setminus##1{\ifx(##1&&!(\else &&!(##1)\fi}%
        \let\bigl\empty
        \let\bigr\empty
        % ....
        % (add above all needed extra definitions: \let\Bigl\empty 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
               Atomic\romannumeral\numexpr##1*8+##2*4+##3*2+##4\endcsname}%
             {}%
           }%
         }%
       }%
    }%
    \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{$A\cap B\cap C\cap D$}

\VennFromTeX{$(A\cap B)\cup (C\cap D)$}

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

% attention to use parentheses for disambiguating \setminus 

\VennFromTeX{$(A\cup B \cup C) \setminus(B\cup C\cup D)$}

\VennFromTeX{$(A\cup B \cup C) \cap (B\cup C\cup D)$}

\VennFromTeX{$((A\setminus (B\cup C\cup D)) \cup B\cap C\cap
  D)\setminus (A\cap B\cap C\cap 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

  • (+1) Thank you for your answer! – Trong Vuong Dec 2 '18 at 11:27
  • (+1) Wow, fantastic! – user139826 Dec 2 '18 at 11:34
  • 1
    Encyclopedic answer – Diaa Dec 2 '18 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. – user4686 Dec 2 '18 at 12:46
  • 2
    @ArtificialStupidity I have to get dinner but just give me time to learn PSTricks and I can do with 4 sets afterwards... – user4686 Dec 2 '18 at 18:39
13
\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 here enter image description here

  • 1
    I haven't known that there is a option as " fillstyle=eofill " before. It doesn't within PStrick User's Guide. – Trong Vuong Nov 30 '18 at 8:38
  • 1
    tug.org/PSTricks/main.cgi?file=Examples/Box/boxfill#2 – user2478 Nov 30 '18 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. :(((( – Trong Vuong Dec 2 '18 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 – user2478 Dec 2 '18 at 15:41
10

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

  • @ArtificialStupidity Yes, as in the figure given as an example by the OP. I didn't change the coordinates. – AndréC Nov 30 '18 at 12:05
  • +1 for the equilateral triangle Δ – technical_difficulty Nov 30 '18 at 14:03
7

With this definitions every surface can be colored.

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

\def\radiusK{\xinttheiexpr[6] 2*sqrt(3)/3\relax}

\def\KOEA{2.5,2}
\def\FOEA{\radiusK,\radiusK}

\def\KOEB{2,1}
\def\FOEB{\radiusK,\radiusK}

\def\KOEC{3,1}
\def\FOEC{\radiusK,\radiusK}

\def\KOEO{2.5,1.375}
\def\FOEO{2.5,2.5}

%uncomment the following lines to have ellipses
%\def\KOEA{1.9,2.2}
%\def\FOEA{1.4,1}
%
%\def\KOEB{3.3,2.2}
%\def\FOEB{1.2,1}
%
%\def\KOEC{2.75,1.4}
%\def\FOEC{1.4,1}
%
%\def\KOEO{2.5,2}
%\def\FOEO{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*{$A\setminus C$}
\end{pspicture}

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

\begin{pspicture}[shift=-4](0,-1)(5,4)
\arealIII
\arealV
\arealVI
\EndeEllipsen*{$A\cap (B\cup 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 (B\cap 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*{$(A\setminus B)\cup (B\cap C)$}
\end{pspicture}

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


\end{document} 

Perhaps you want to check out this.

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

%\def\radiusK{\xinttheiexpr[6] 2*sqrt(3)/3\relax}
%
%\def\KOEA{2.5,2}
%\def\FOEA{\radiusK,\radiusK}
%
%\def\KOEB{2,1}
%\def\FOEB{\radiusK,\radiusK}
%
%\def\KOEC{3,1}
%\def\FOEC{\radiusK,\radiusK}
%
%\def\KOEO{2.5,1.375}
%\def\FOEO{2.5,2.5}

%uncomment the following lines to have ellipses
\def\KOEA{1.9,2.2}
\def\FOEA{1.4,1}

\def\KOEB{3.3,2.2}
\def\FOEB{1.2,1}

\def\KOEC{2.75,1.4}
\def\FOEC{1.4,1}

\def\KOEO{2.5,2}
\def\FOEO{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{$A\setminus C$}
\end{pspicture}

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

\begin{pspicture}[shift=-4](0,-1)(5,4)
\arealIII
\arealV
\arealVI
\EndeEllipsen{$A\cap (B\cup 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 (B\cap 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{$(A\setminus B)\cup (B\cap C)$}
\end{pspicture}

\begin{pspicture}[shift=-4](0,-1)(5,4)
\arealIII
\arealV
\EndeEllipsen{$\bigl((A\cap B)\cup (A\cap C)\bigr)\setminus(A\cap B\cap 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}

\def\KOEA{1.9,2.2}
\def\FOEA{1.4,1}

\def\KOEB{3.3,2.2}
\def\FOEB{1.2,1}

\def\KOEC{2.75,1.4}
\def\FOEC{1.4,1}

\def\KOEO{2.5,2}
\def\FOEO{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}{$A\cap B\cap C$}%
\end{pspicture}

\begin{pspicture}(0,-1)(5,4)
\VennIII[cyan]{3,5,6}{$A\cap (B\cup 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 (B\cap 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)}{$(A\setminus B)\cup (B\cap C)$}
\end{pspicture}

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


\end{document} 

enter image description here

  • Hey bro, is there a shorter way? Your code seem being enormously complex. – Trong Vuong Dec 1 '18 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 (B\cap C)$} \end{pspicture} – user139826 Dec 1 '18 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.