-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
using optex color definitions in minim - not an issue - but help needed, thanks #2
Comments
Hello! optex-minim in this repository is more or less obsolete - I should maybe archive the repository. It is not needed at all, as it has been integrated into OpTeX itself - i.e. there are minim
Actually I don't know that one. Where does it come from? Anyways, unfortunately I wouldn't even call myself a Metapost novice, since I have hardly used it (funnily enough, since I integrated it with optex through minim), but I think I can fill some details for you. My impression from the Metapost manual and a tugboat article is, that So either of this rows is a basic metapost expression, that may be interpreted as a color:
In fact I vaguely remember, that since Metapost has just pairs for 2D coordinates, people abuse RGB colors for 3D coordinates, since they are essentially triplets built into Metapost. And it seems that Metapost really handles colors specially only after it has been instructed to handle a triplet or quadruplet or number as a color - only then it actually "clamps" the components to the range 0 - 1. But maybe there are more details that I haven't yet come by. With these essentially normal tuples or number we can form expressions, just like for pairs or ordinary numbers:
I.e. what works for points works for mixing colors as well. Even linear equations with variables. But since I am no Metapost expert, I restrained myself to these, since these seem good for basic color mixing. Of course it would be a bit inconvenient to only use raw numbers everywhere, so Metapost defines this:
So it seems that these "names" are not that special, and defining new ones in Metapost is not a problem. Our problem is then how to make something defined in OpTeX as:
expand in Metapost to:
This is just a matter of separaating the numbers by whitespace, anad inserting commas between them. Minim conveniently recently introduced a way to add definitions before and after each \fontfam[lm]
\load[minim-mp]
\_let\_optex_rgb=\_setrgbcolor
\_let\_optex_cmyk=\_setcmykcolor
\_let\_optex_grey=\_setgreycolor
\_def\_mp_rgb #1 #2 #3 ;{(#1, #2, #3)\_space}
\_def\_mp_cmyk #1 #2 #3 #4 ;{(#1, #2, #3, #4)\_space}
\_def\_mp_grey #1 ;{#1\_space}
\expandafter\toksapp\everymp0{pre}{tex}{
\_def\_setrgbcolor#1{\_mp_rgb #1 ;}%
\_def\_setcmykcolor#1{\_mp_cmyk #1 ;}%
\_def\_setgreycolor#1{\_mp_grey #1 ;}%
}
\expandafter\toksapp\everymp0{post}{tex}{
\_let\_setrgbcolor=\_optex_rgb
\_let\_setcmykcolor=\_optex_cmyk
\_let\_setgreycolor=\_optex_grey
}
{\Red before in red}
\directmetapost{
beginfig(1)
draw fullcircle scaled 10mm shifted (0mm, 0) withcolor \Green;
draw fullcircle scaled 20mm shifted (15mm,0) withcolor .1\Green;
draw fullcircle scaled 5mm shifted (30mm,0) withcolor .8[\Red,\Blue];
endfig;
}
{\Blue after in blue}
\bye I set I can then use OpTeX colors inside Unfortunately, mixing colors has some subtle problems. E.g. the following fails:
This is because I am trying to do an arithmetic on white (which in OpTeX is defined as grey color) and red (which in OpTeX is defined as CMYK color), and Metapost doesn't know how to do arithmetic on CMYK and number:
Also, metapost definitions like There is probably a better solution for handling colors, so I will probably post an issue to the OpTeX repository asking for feedback, and possibilities on what to do with colors. By the way, this works:
just as well as this: \def\mycolor{.625red + .1blue}
[...]
draw fullcircle scaled 20mm shifted (55mm,0) withcolor \mycolor; Metapost sees only the first text in both cases. The macro
Where the spaces sometimes are and sometimes aren't significant - the good old weird TeX. And yes indeed, you are right that this deserves a case in examples after I figure out a good way to implement usage of OpTeX colors in minim Metapost - the above is just a rough idea (though you can probably use it in the mean time, since from above you know the limitations). |
Hi, and many thanks for your detailed answers (this one: #2 - and some bits were my bad, I think, like e.g. and yes: I am using minim as integrated with optex (will continue again: I will have to do this (work through this) step by step - and then will hopefully have some more detailed remarks - anyway: enough food to think about for now - thanks again! |
OK - sorry for the delay: i was side tracked, but am back to optex/metapost/minim now - i.e. I am experimenting... And the color arithemtic is easy enough to understand (thanks again for your detailed explanations). Likewise the simple macros: Now, when I try the
I assume, that's because
which shows that I have optex 1.13 from Nov 2023 I see there is a more recent texlive-luatex pkg in the works: i.e. in experimental already: https://packages.debian.org/experimental/texlive-luatex It would be nice, of course, to have these more recent packages - and I could install this one from experimental (with apt pinning) - and have done so for other packages in the past - or I could try to install optex by hand (...) - but usually these efforts are not worth it: just waiting some time is easier usually, and safer (in the worst case they could break my system in some way - it's called experimental for a reason). so, I guess, I will for now help myself with some simple number arithmetic (having some color tuples directly in my metapost code), and then get back to these everymp bits later (there is enough for me to learn still from traditional plain tex) I guess, I will see: if I have more optex questions (and issues possibly): then it makes sense of course, to have a more recent version installed (so that I don't have to bother you with my outdated package questions). Thanks again. |
Temporary hot fix for vlasakm/optex-minim#2
Yes, this seems right. Though while with TeX Live 2024 (2024.20240401-1) you will get new OpTeX (https://git.texlive.info/texlive/tree/Master/texmf-dist/tex/optex/base/optex.ini?h=tags/texlive-2024.0 says 1.14), the minim-mp version with
You can try mmtex, my attempt to make a TeX distribution (i.e. an "alternative" to TeX Live) that is "minimal and modern" (i.e. omits most of the things, and includes only OpTeX as a minimal and modern TeX format). It should be possible to install it on Debian through the Open build service, which contains prebuilt packages in the I just realesed an overdue version updating all the included packages (not much - mostly just OpTeX + dependencies and goodies like PGF/TikZ and minim) to the most recent versions. The advantage of If you are interested, try it, and let me know if it works for you - I used to test new releases on Debian, but no longer do so regularly. |
Forgot to mention that I actually included the |
Thanks again for your kind support - and your mmtex package certainly sounds interesting (I and shall give it a try some time - and if not immediately, then because I am busy with other bits). On a different - but related - matter: I have suggested to Petr some time ago to create an optex mailing list - and while he doesn't want to do it (he needs no help with optex, obviously), he did suggest that someone else may do it - and (having his consent thus - and having somehow taken my mouth full) I told him that I may set up it indeed, when I have some time. - Now I am looking around, considering options: I don't really want to pay (for an account with sourcehut e.g. - just to set up a mailing list i.e.) - nor do I necessarily want to set up a google group. - I don't really know, who would be willing to host this (tugboat https://tug.org/mailman/listinfo maybe?). - Maybe you have some idea? (And if so, you can reach me at my private email address: rx at a-rx dot info) Thanks, Andreas |
Hi, thanks for creating optex-minim - I am doing my first baby steps with optex + minim (your optex-minim i.e.) + metapost (while also looking at the context docs) etc. - having some experience with latex/context, but less so with plain tex - i.e. I am learning all these at the same time - so bear with me, please.
I can (partly) set the background of some pages in optex with metapost in color, like so:
i.e. I want to use slightly more complicated colors - than the usual red/green/blue...
Now, ideally I would use my optex color definitions - there are various ways to do them:
(with
\setrgbcolor
,\setHEXcolor
etc. - you know the optex docs)etc. - now, I am having a hard time accessing / using such definitions in metapost
(and I am not sure: do I need to write a macro to do so? Can I directly access
optex definitions within minim - the minim docs seem to suggest so:
there is a mention of
\mpcolor
- well for latex, not optex - and then: a (very general)section "running tex from within metapost" - but there are not really any examples given.
note that this works (but sets only a certain red level):
I don't really know: maybe this is general TeX knowledge - but I am not aware: where does this syntax come from:
{.625red}
- and more importantly: how to use it a little more generally:this does not work
maybe I need a comma in between red and blue, maybe
+
- I think I have tried everything.maybe I can just use
\mpcolor{\CornerDarkGreen}
in the metapost above - I think I have tried this, without success!Maybe you could provide some hints - or ideally even add an example (to your examples directory)? Thanks!
The text was updated successfully, but these errors were encountered: