How to set comments to italic fonts in Neovim - configuration

I want to set my Neovim config to use an italic font for comments. I use the following code at the end of my init.lua:
local function update_hl( group, tbl )
local old_hl = vim.api.nvim_get_hl_by_name( group, true )
local new_hl = vim.tbl_extend( 'force', old_hl, tbl )
vim.api.nvim_set_hl( 0, group, new_hl )
end
update_hl( 'Comment', { italic = true } )
When I run Neovim (v0.8.0) all comments are shown in the regular font. But if I source the init.lua with :luafile % the comments change to the desired italic font. So there seems to be no problem inside the code itself but why isn't it loaded on startup?

Your specific highlight is cleared by loading of colorscheme and plugins (particularly if you use TreeSitter for syntax highlighting).
Call your function to set italic font for comments after loading of colorscheme.

Related

Set font color on only one table row rather than entire document

import docx
from docx.api import Document
from docx.shared import RGBColor
if condition:
paragraph = row[2].add_paragraph('Different Text') # Not Blue
else:
blue_paragraph = row[2].add_paragraph('X')
font = blue_paragraph.style.font
font.color.rgb = RGBColor(0x42, 0x24, 0xE9)
The above code is not only making my entire row[2] blue, it is making the entire document blue. How can I set only the 'X' text blue?
In this line:
font = blue_paragraph.style.font
You're selecting the font of what is probably the Normal style, and then setting it to blue in the following line. This explains why the whole document is turning blue; Normal is the default style for all paragraphs in the document.
You either need to create a new style that is blue and apply that to the paragraphs in question, or set the font of the runs of the target text directly.
So something like this would work, but be less optimal in some ways than using a style:
blue_paragraph = row[2].add_paragraph("X")
for run in blue_paragraph.runs:
run.font.color.rgb = RGBColor(0x42, 0x24, 0xE9)
This page in the python-docx documentation describes Word styles in a way you might find helpful.
https://python-docx.readthedocs.io/en/latest/user/styles-understanding.html

How can I put an image on a Matlab uicontrol button?

I have Matlab 2019b, GUI Layout Toolbox 2.3.4 and t all runs on MacOs 14 Mojave.
I want to create button in in a UI that have icons/images instead of text. I have seen here:
https://undocumentedmatlab.com/blog/html-support-in-matlab-uicomponents/
that it is supposed to be possible to use HTML to render the button contents.
So - I try this sample code:
figure('MenuBar','none','Name','GUI-TEST','NumberTitle','off','Position',[200,200,140,90]);
push_btn = uicontrol('Style','PushButton','String','Push','Position',[30,60,80,20],...
'CallBack','disp(''You are pressed a push button'')');
close_btn = uicontrol('Style','PushButton','String','Close','Position',[30,5,80,50],...
'CallBack','close');
icon_file = fullfile(pwd, 'close.png')
str = ['<html><img src="file://' icon_file '"></html>']
set(close_btn,'String',str);
but it leaves me with an empty button.
If I deliberately use a filename that does not correspond to an existing file, I see a broken image icon:
So I am reasonably sure that the basic syntax and file path stuff is correct but the image does not get rendered in the button.
Is there something else I need to do to make this work or is it all just part of Matlab's overwhelming strangeness?
The easiest way to put an image on a uicontrol (and specifically a button), is to use the CData property,
im_orig = imread(icon_file); % Needs to be true color, i.e. MxNx3
im_sized = imresize(im_orig,[80,50]); % size of the button
% str = ['<html><img src="file://' icon_file '"></html>'];
% set(close_btn,'String',str);
set(close_btn,'CData',im_sized);

Special character not showing in html2pdf

I'm using html2pdf and trying to display in a pdf a checkmark, checkbox(checked), a tick mark...anything that resembles check sigh.
I've tried all the codes I could find :
☑✔ ✓ but all I'm seeing is '?'
$html2pdf = new HTML2PDF('P', 'A4', 'fr', true, 'UTF-8', 0);
There was a problem with the font not being able to show those symbols
What I've done is I've added 2 different fonts, Arial as default and dejavusans for symbols.
<style>span{font-family: dejavusans;}</style>
<span>☑</span>
$html2pdf->setDefaultFont('arial');
$html2pdf->AddFont('dejavusans');

Japanese text in TextField with embedded font

In my ActionScript 3 project I use TextField with embedded font set to true and isHTML set to true. Everything works fine when I display latin characters.
But when I want to display Japanese characters they do not appear. Actually it is expected to be like this because Japanese font is not embedded.
Is there is a way to fall back to system font if embedded font doesn't have glyphs for certain characters?
Try to use hasGlyphs("..."); on a Font instance. I had some problems with it but in general it works alright, hopefully it works for Japanese too. Then you can simply use _sans if there is no japanese glyphs.
Edit:
I have no way to test this now but I assume something like this would work:
import flash.text.Font;
var myFont:Font = new MyFont(); // Embedded font in library, linkage set to 'MyFont'
if(myFont.hasGlyphs("Hello!")) {
field.embedFonts = true; // Not sure whether this is necessary in case of HTML text
field.htmlText = "<p><font color='#ff0000' face='" + myFont.fontName + "'>Hello!</font></p>";
}
else {
field.embedFonts = false;
field.htmlText = "<p><font color='#ff0000' face='_sans'>Hello!</font></p>";
}

MATLAB: displaying markup (HTML or other format)

I'd like to display a table from a script in MATLAB. I can easily generate the <td> and other HTML elements, but as far as I know, I can only write them to a file.
Is there a way to display HTML (or some other markup) from MATLAB? Or am I stuck writing to a file and opening a browser?
You can display the HTML text in a PopupPanel as explained here: http://UndocumentedMatlab.com/blog/customizing-help-popup-contents/
Or in an integrated browser control that points to your HTML file or HTML text as explained here: http://UndocumentedMatlab.com/blog/gui-integrated-browser-control/
Use the Java Swing component inside a MATLAB figure, precisely JEditorPane using MATLAB's javacomponent() function. JEditorPane supports a good subset of HTML.
Here is a code sample:
mytext = '<html><body><table border="1"><tr><th>Month</th><th>Savings</th></tr><tr><td>January</td><td>$100</td></tr></table></body></html>';
hfig = figure();
je = javax.swing.JEditorPane( 'text/html', mytext );
jp = javax.swing.JScrollPane( je );
[hcomponent, hcontainer] = javacomponent( jp, [], hfig );
set( hcontainer, 'units', 'normalized', 'position', [0,0,1,1] );
%# Turn anti-aliasing on ( R2006a, java 5.0 )
java.lang.System.setProperty( 'awt.useSystemAAFontSettings', 'on' );
je.putClientProperty( javax.swing.JEditorPane.HONOR_DISPLAY_PROPERTIES, true );
je.putClientProperty( com.sun.java.swing.SwingUtilities2.AA_TEXT_PROPERTY_KEY, true );
je.setFont( java.awt.Font( 'Arial', java.awt.Font.PLAIN, 13 ) );
EDIT: see the discussion of this solution here,
One alternative is to display the table in a graphics window using the UITABLE control.
EDIT: Even though this is only an alternative (not a solution) to the problem in the question, I thought I'd include a sample for anyone who may be interested in this option:
hFigure = figure('Position',[100 100 300 220]);
hTable = uitable(hFigure,'Data',rand(10,3),...
'ColumnName',{'X' 'Y' 'Z'},...
'Position',[20 20 260 180]);
I ended up doing what I didn't quite want to do, namely to write HTML to a file. It requires me to open it in a browser and refresh every time I run my script, but that's not too bad for what I needed in the short term.