Latex color box inline with text - latex

I'm trying to put together a LaTeX color box. The xcolor package \fcolorbox seem to be what I want, but I can't get the rendering quite correct. When I use
\fcolorbox{black}{red}{}
it renders a small box sunken to the bottom of the text line. The best I've managed to do is to fake it with a similar text color:
\fcolorbox{black}{red}{\textcolor{red}{--}}
However, I'm worried that this won't render correctly in all situations with defined colors. Is there a way I can declare an empty text box with full in-line text height? Is there another solution?
I'm basically looking for the code that produces the color boxes all through the document at ftp://ftp.dante.de/pub/tex/macros/latex/contrib/xcolor/xcolor.pdf. The boxes I'm referring to are used throughout, but the first instance is on page 4. Thanks.

The xcolor.dtx file in the same directory as the pdf contains the source for the package and the source for the documentation. The relevant bits from the source for the documentation:
\def\testclr#1#{\#testclr{#1}}
\def\#testclr#1#2{{\fboxsep\z#\fbox{\colorbox#1{#2}{\phantom{XX}}}}}
...
(Answer: 40\% \testclr{green} $+$ 60\% \testclr{yellow} $=$ \testclr{green!40!yellow}, e.g., |\color{green!40!yellow}|)
Basically, use \phantom{} on the contents of your color box, and make sure that at least one of the phantom characters is full-height.
Also, https://tex.stackexchange.com/

Related

How do I change text in a python-fu gimp script without changing the font?

I have a master image which I edit in gimp to get the look and feel wanted. I then want to use a python script to produce a bunch of new images with the text (on several different layers) changed. I would like to leave the font, size, italicized or not, etc. alone.
I've successfully changed the text in my batch script with this function:
pdb.gimp_text_layer_set_text(layer, text)
The problem is this also overwrites the font and other text parameters that I had picked out in the master file. Is there a way to change just the text and leave the font alone?
Alternately, a more clunky way would be to try and save everything important about the font before the change and try to reapply it. This is what I've tried:
# Find the text layer
text1_layer = filter(lambda x: x.name == 'text1', im.layers)[0]
# Save the font
font = pdb.gimp_text_layer_get_font(text1_layer)
font_size, font_unit = pdb.gimp_text_layer_get_font_size(text1_layer)
# Set the text
pdb.gimp_text_layer_set_text(text1_layer, tex1_text)
# Restore the font
pdb.gimp_text_layer_set_font(text1_layer, font)
pdb.gimp_text_layer_set_font_size(text1_layer, font_size, font_unit)
Unfortunately, that doesn't seem to work consistently. It looks like the get_font and get_font_size commands retrieve the right font for one of the layers, but not for the others. It doesn't seem to preserve italics etc., and I wouldn't expect it to preserve whether or not text is underlined.
A third option would be to hard code in the font. I would need to go through all the text fields, figure out what the font parameters are and hard code them in for each one. Then, if I redesign the master file (which I will do a lot), I have to repeat the process. This shouldn't be necessary.
I've done a bit more research and found a solution that works for me in gimp, however, it sounds like you should probably be using something other than gimp, such as imagemagick, if you're doing much text editing from a script.
The solution is, when you change text in the gimp editor you need to change the font in the tool dialog box, so it's set as a property of the layer, instead of just selecting the text and changing the font in the floating font box that shows up - that changes the font of the text you selected, but leaves the base font of the text layer unchanged.
In turns out that gimp text functionality is pretty poor, and there are lots of complaints surrounding issues like this online. There is some hope for the future. Apparently gimp supports a markup language for text. You can get the markup for your text this way:
pdb.gimp_text_layer_get_markup(layer)
Unfortunately, there is no set_markup function - even though it's been commented on and requested for 3-5 years now, so don't hold your breath. If such a function existed, then the get_markup and set_markup functions would give a script complete control over text. It doesn't exist, however, so if you want to change pieces of text (eg. to add italics to a word), you have to create separate layers. If all your text is to be formatted the same, you can edit it via script or editor, and as long as you set it in the text layer properties (done via the tool box in the editor, and the only way you can change font in a script), then the set_text function in a script will maintain font, etc.
https://bugzilla.gnome.org/show_bug.cgi?id=724101
http://gimpchat.com/viewtopic.php?f=9&t=10101&p=132782&hilit=change+text+markup#p132782
Not really a satisfactory answer, but too big to post as a comment.
Yes, the text layer API wasn't updated to follow the new capabilities. Actually all the info is in a gimp-text-layer "parasite":
parasites=layer.parasite_list()
if parasites and 'gimp-text-layer' in parasites:
data=layer.parasite_find('gimp-text-layer').data
pdb.gimp_message('Text layer "%s": %s' % (layer.name,data))
This parasite doesn't seem to exist until the image has been saved at least once.
However, even though you can replace the parasite data, it doesn't change the text layer, and to make it worse, it seems that Gimp detects the change, assumes that the layer text data is corrupt, and makes the layer a plain bitmap when saving the image.
Now, poring over the source code, there are mentions of a GDynText plugin that you can find on SourceForge and that advertizes itself as:
GIMP Dynamic Text is a GIMP plug-in that works like the text tool but allows you writing multi-line text and made you able of modifying it later as you want (text/font/font size/color/...).
So you could be lucky, or not...

How do you rotate a text

There is a video on how to rotate an object around a point but I fail to select the text.
I wanted to do the same thing and saw your question before figuring this out.
1. The "Geogebra Way"
In the Algebra Perspective enter the following RotateText commands in the Input box at the bottom:
RotateText["Rotated text using degrees.", 45°]
RotateText["Rotated text using radians.", 0.785398]
In the Construction Protocol view, this is represented by
"rotatebox{45}{ \text{Rotated text using degrees.} }"
"rotatebox{44.9999999}{ \text{Rotated text using radians.} }"
Note that the radian form of the RotateText command is converted to degrees in the construction step. So this creates an graphical object that renders the text in a LaTeX "rotatebox". It's rather strange that the system doesn't have a tool to create rotateable text.
You can attach the text to an object via the object's Properties->Position->Starting Point. Only certain types of objects can be used, and the text can only be placed/moved underneath the object, which is odd. You can get around this by creating a line segment, attaching the rotateable text object to a desired end-point on the line segment above the location you want the final text, and then hiding the line segment.
2. A better, "undocumented" Geogebra method!
One can actually use LaTeX in captions of objects. Here's how you would enter the text:
$\rotatebox{45}{ \text{Rotated text using standard text box!} }$
A nice thing about this is the caption can be easily placed above the object. Notice that LaTeX commands are surrounded by the dollar sign. Also notice that there is a backslash as part of the \rotatebox command.
Also, one can use the standard text tool to do the same thing. This has the advantage that the text can be dynamic! Create some text anywhere. Then edit it's properties on the Text tab. Check the LaTeX checkbox, and enter the following for the text:
$\rotatebox{45}{ \text{} }$
Then inside the \text{} brackets, select an object. The text will be updated with the object's value. Or a combined form:
$\rotatebox{45}{ \text{"The value is:" + SliderObject} }$
I've tried to put an object in the "degreees" field, but could not get that to work.
Use the RotateText command like this:
RotateText("What ever text you want", angle)

Core Text: Drop caps + paragraph styles: Incompatible?

I'm attempting to draw a richly laid out text view on iPhone that features:
Custom paragraph spacing (kCTParagraphStyleSpecifierParagraphSpacing)
Custom paragraph first-line indentation (kCTParagraphStyleSpecifierFirstLineHeadIndent)
Justified alignment (kCTParagraphStyleSpecifierAlignment)
Finally, a drop cap on my first paragraph
I'm using OHAttributedLabel. The first three points I achieved without much trouble by just setting some paragraph style attributes on my NSAttributedString.
The drop cap I managed to implement by hacking OHAttributedLabel:
Cut out a rectangular region out of the main paragraph's CGMutablePathRef the size of the drop cap by adding an extra CGPathAddRect, as detailed in this excellent blog post.
Drawing the large character in this region with an extra CTFrameDraw call.
My problem: The paragraph styles and the custom text path are incompatible. When I cut a rectangular chunk out of the main text's path, all the paragraph styles seem to get thrown away.
Does anyone know a way to make them work together? Or can anyone think of another way to implement drop caps? (Short of using a UIWebView + CSS, which I'd rather not have the overhead of!)
Thanks!
You can use straight Core Text to achieve this, in the following post I explain the use of 2 framesetters to lay out text with drop caps in a UIView. In the code example (there's also a link to a github repo) you'll be able to see where the paragraph styles are created and applied to the main text view.
https://stackoverflow.com/a/14639864/1218605

Latex font color

I'm trying to typeset a document I'm working on.
Currently I'm trying to format a piece of text such that the text consists of two colors: a fill color and a line color. In this way the header should pop out more.
I found \psset with options such as linecolor and fillcolor, but I can't get it to work. Can someone provide an example of how I could do this?
Just providing a color using the color-package is no problem, but also not what I want because using this package I can only provide a single color for a piece of text.
Maybe this is what you're looking for: Contour package. Here's the doc containing examples.

BiDi text in Delphi - How do you select text to edit by language like this pic?

I saw this picture and now wondering if/how you can do this in Delphi. The highlighted/selected text shows two forms of formatting, i.e. highlight color and hash lines.
http://img9.imageshack.us/img9/4121/easilyselecttextofonela.jpg
I've done something very similar recently in a bible application, also done in Delphi.
The user can select a single verse and single words of the selected verses. (But this feature is not released yet, so don't bother looking for it)
I used the web browser control from Microsoft and added my own kind of selection handling.
I've done the formatting by enclosing the relevant parts with span elements and changing their CSS style. When the selection gets removed, I also remove the enclosing elements.
The hard part was backing the "visual" selections with a selection data structure and handling all the selection events (clicking, shift-clicking, shift-ctrl-clicking, ...)
Embedding IE seems to be an easier way to do this as DR says, but you can also do this manually by drawing it all on a canvas, an easy way would be to create two bitmaps (one without a selection and another selected (could be as complicated as you like - dashed, colored, ... )), and you need to know the positions/rects of all your characters which would be somewhat difficult for long texts.
You basically show the unselected bitmap, and overlap the selected parts by portions of the second image.
You would also need to handle the selection manually by OnMouseDown, OnMouseMove, OnMouseUp...

Resources