0

In Paul Taylor's diagrams package, is it possible to set the color of specific elements in a diagram? If so, how?

I have tried using \color{a_color}. It changes the color of part of the diagram, but I never succeed in coloring specific elements of the graph.

For instance, in the following diagram,

    \begin{diagram}
            \bullet     &                       &   \bullet \\
            \dLink      &   \rdLink             &            \\
            \bullet     &                       &   \bullet
    \end{diagram}

I would like to color only the diagonal link \rdlink in red. I have tried

\begin{diagram}
            \bullet     &                                     &   \bullet \\
            \dLink      &  \color{red}  \rdLink \color{black} &            \\
            \bullet     &                                     & \bullet
\end{diagram}

but this leaves the graph uncolored. I have also tried

\begin{diagram}
            \bullet     &                                     &   \bullet \\
            \dLink      &  \color{red}  \rdLink               &            \\
            \bullet     &                                     & \bullet
\end{diagram}

which yields

enter image description here

beside making all the following diagram red too. Other combination of \color{red} and \color{black} yields similar somewhat erratic outcomes.

It looks like using \color{a_color} sets the color of the whole line, as well as the color of the later lines (in further diagrams too).

Any idea how I could color a single element (say a link) of a single line?

  • 1
    Have you considered one of the TikZ-based packages for drawing these kinds of diagrams? (Or PSTricks probably has packages, too.) – cfr Jun 27 '15 at 16:30
  • I don't think the package supports color; since the code is obfuscated, it's impossible to try and make it honor color choices. – egreg Jun 27 '15 at 21:46
  • 1
    Using a package with obfuscated code "maintained" by someone who expressly claims he has little to no time to devote to (La)TeX seems unwise.... – jon Jun 28 '15 at 4:44
4

I'd suggest you to switch to the powerful tikz-cd package which was built upon TikZ specifically for commutative diagrams. You can easily control the attributes for every element of yout diagrams:

\documentclass{article}
\usepackage{tikz-cd}

\begin{document}

\begin{tikzcd}
\bullet\ar[d,dash]\ar[dr,red,dash] & \bullet \\
\bullet & \bullet 
\end{tikzcd}

\end{document}

The result:

enter image description here

  • Given the above comments on why I should try alternatives to "diagrams", I'll accept this answer. – Martin Van der Linden Jun 28 '15 at 6:56
2

The package file diagrams.sty, found on the webpage, does not define \*Link commands, therefore I have used \*Line instead (\dLine and \rdLine).

Analyzing the package is a very time consuming task, because the author obfuscated the internal macros.

But it seems that the approach of package luacolor works here. It does not insert specials, but sets the color via LuaTeX's attributes. Therefore the package requires LuaLaTeX:

\documentclass{article}
\usepackage{diagrams}
\usepackage{luacolor}

\begin{document}
  \begin{diagram}
    \bullet     &                       &   \bullet \\   
    \dLine      &  \color{red}\rdLine   &           \\
    \bullet     &                       &   \bullet
  \end{diagram}
\end{document}

Result

1

For those who do not want to use tikz-cd, psmatrix from the pst-node package works fine.

An example :

\documentclass{article}
\usepackage{pst-node}
\usepackage{wasysym}

\begin{document}

$$
\begin{psmatrix}[nodesep = 10pt, colsep=3cm, rowsep=3cm]
        % % % %
         \CIRCLE & \CIRCLE\\
        \CIRCLE & \CIRCLE 
        % % % %
        \psset{linecolor = red}
        \ncline{-}{1,1}{2,2}
        \psset{linecolor = black}
        \ncline{-}{1,1}{2,1}
    \end{psmatrix}
$$

\end{document}

The result :

enter image description here

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.