Answer is a resounding YES unless I am making a mistake. The following string:
$\begin{array}{ccc}' 'a & b & c \ ' 'd & e & f \' 'g & h & i ' '\end{array}$
produces different outputs in the livescript input and output panes as this screenshot shows:
Input pane has apostrophes and output pane does not. I think this is just the bugginess of Matlab with LATEX. Perhaps unsurprising as LATEX support is still evolving. Or maybe I am doing something wrong.
"The best questions are those who answer themselves"
As you may notice, MatLab relies on different interpreters on different figure and text contexts. It is possible to setup interpreters
latex -- Supports the full LATEX markup language.
tex -- Supports a subset of plain TEX markup language. See the String property for a list of supported TEX instructions.
none -- Displays literal characters.
Source: http://matlab.izmiran.ru/help/techdoc/ref/text_props.html
str is a horizontally concatenated character vector, so the actual variable contains
str = '$\begin{array}{ccc}a & b & c \\ d & e & f \\g & h & i \end{array}$'
but when you copy the code you gave ($\begin{array}{ccc}' 'a & b & c \\ ' 'd & e & f \\' 'g & h & i ' '\end{array}$) into the popup under Insert -> Equation you enter single quotes into the string, that are displayed by LaTeX. So MATLAB just does as you tell it to do (if my assumptions of your workflow are correct)
For the future please don't paste screenshots of code, just the code itself in a properly formatted block.
Related
I have a text box in my GUI, into which I want to write a tabbed text.
As you may or may not know, the \t modifier does not work in a tex-interpreted text strings.
What I ask is if there's an elegant solution to emulate the tab modifier with the CORRECT amount of spaces, also taking into account the fact that different characters might have different widths?
Result should be like this:
[tabText('Try\tThis') ; tabText(Tryy\tThis)]
ans =
Try This
Tryy This
Thanks.
'\t' in matlab is interpreted as it is: two characters \ and t, not the tabulation.
To obtain the tabulation character, you'll have to go through sprintf:
> 'Try\tThis'
Try\tThis
> sprintf('Try\tThis')
Try This
Or with char(9) (ASCII code):
> ['Try' char(9) 'This']
Try This
Looking at the relevant part of the MATLAB documentation for text (at the time of writing, this points to the R2016b docs) one can see the TeX "subset" that is supported by MATLAB, and it does not include any tab-like character. Thus it seems that there's no proper way to do this with the tex interpreter.
You have several options:
If using uifigures is an option, text labels there allow MathML to be used. Which is very customizable...
If you switch to the 'latex' interpreter, you could use \quad, \qquad etc.
figure();
text(.5,.5,{'$$This \quad text$$','$$is \quad properly$$','$$tabbed, \quad Right?$$'},...
'Interpreter','latex');
What O'Neil suggested.
Regarding the unequal character width - you might be able to overcome this by changing the font, using the 'FontName' argument to text(...).
I've got an existing DOORS module which happens to have some rich text entries; these entries have some symbols in them such as 'curly' quotes. I'm trying to upgrade a DXL macro which exports a LaTeX source file, and the problem is that these high-number symbols are not considered "standard UTF-8" by TexMaker's import function (and in any case probably won't be processed by Xelatex or other converters) . I can't simply use the UnicodeString functions in DXL because those break the rest of the rich text, and apparently the character identifier charOf(decimal_number_code) only works over the basic set of characters, i.e. less than some numeric code value. For example, charOf(8217) should create a right-curly single quote, but when I tried code along the lines of
if (charOf(8217) == one_char)
I never get a match. I did copy the curly quote from the DOORS module and verified via an online unicode analyzer that it was definitely Unicode decimal value 8217 .
So, what am I missing here? I just want to be able to detect any symbol character, identify it correctly, and then replace it with ,e.g., \textquoteright in the output stream.
My overall setup works for lower-count chars, since this works:
( c is a single character pulled from a string)
thedeg = charOf(176)
if( thedeg == c )
{
temp += "$\\degree$"
}
Got some help from DXL coding experts over at IBM forums.
Quoting the important stuff (there's some useful code snippets there as well):
Hey, you are right it seems intOf(char) and charOf(int) both do some
modulo 256 and therefore cut anything above that off. Try:
int i=8217;
char c = addr_(i);
print c;
Which then allows comparison of c with any input char.
I have a long Unicode string saved in Unicode encoding from notepad, in this form
ChrW$ (&H410) & " " & ChrW$(&H430) & vbNewLine & ChrW$(&H42F)
etc, to end of file
If I assign the above code as the value of an Ink Edit box in code, it displays the correct Unicode chars, which is what I wanted.
But for some reason I can't find the right way to open the text file and get that to display the Unicode chars. This is probably very simple, but I've got totally confused.
What is a simple way of achieving this? Thanks
Assuming your file has the Unicode text and not VB expressions as you showed... not much to it:
Dim F As Integer
Dim Text() As Byte
F = FreeFile(0)
Open "SomeUnicode.txt" For Binary Access Read As #F
'File is UTF-16LE, so we'll skip the BOM:
ReDim Text(LOF(F) - 3)
Get #F, 3, Text
Close #F
InkEd.Text = Text
Otherwise you'll need an expression evaluator, and you could use the Microsoft Script Control to process such expressions if you drop the $ type decorators.
I am forming an specific string using several strcat and displaying it into console. This string contains characters such as: 1,2,3,4,5,6,7,8,9,0,#,*,E and am using fprintf('%s') for this purpose.
For instance:
2E4137E65922#
is a possible outcome of the code.
Is there anyway I could make letter E to stand out in my output? Like making it red?
Unfortunatedly, there is no official way of doing this. However, you could use Yari Altman's cprintf(). It abuses of undocumented features of Matlab to do exactly what you want.
You can read more in the famous Undocumented Matlab blog he runs.
The example image in FEX looks like this:
EDIT: Theoretically, if cprintf would work as expected, the following should work:
C=strsplit(s,'E');
cprintf('black',C{1});
for ii=2:size(C,2)
cprintf('err','E');
cprintf('black',C{ii});
end
cprintf('black','\n');
However, in Matlab 2014b it doesnt give good results. I found out that of it doesnt work properly when there is a single character to format.
If you substitute 'E' by 'EE' works....
EDIT2: I left a comment to Yari Altman. Hopefully he will, if he can, fix the thing.
You can use the HTML tags <strong>, </strong> to type specific letters in bold:
str = '2E4137E65922#'; %// input string
letter = 'E'; %// letter that should be made bold
strBold = regexprep(str, letter, ['<strong>' letter '</strong>']); %// output string
disp(str)
disp(strBold)
Thanks #Dev -iL for this information!
While it seems that cprinf() from my other answer does not work for single characters, if there is a single color that one wants to use, and that color is orange, then this trick used for warning in cprintf can be used:
disp(['this is [' 8 'orange]' 8 ' text'])
Read more at: http://undocumentedmatlab.com/blog/another-command-window-text-color-hack
Thus, your code would look like:
s='2E4137E65922#';
C=strsplit(s,'E');
str=C{1};
for ii=2:size(C,2)
str=[str ['[' 8 'E]' 8 ]];
str=[str C{ii}];
end
disp(str);
I'm working on a MATLAB program with a gui. I want to have text labels and buttons in french, but it doesn't work. For example, the word 'Paramètres' in the code becomes Paramètres on the gui.
I checked the file encoding and it's utf-8. What can I do to fix that?
Here's a simple example of one command that I used in the code:
tab2 = uitab('v0', hTabGroup, 'title','Paramètres des canaux');
Thanks.
How about using HTML?:
figure
hTabGroup = uitabgroup;
drawnow;
tab2 = uitab('v0',hTabGroup,'title','<html>Paramètres des canaux</html>');
See here for a list of HTML character codes.
To add an accent aigu use
title('{Param\''etres des canaux}','interpreter','latex')
To add an accent grave use
title('{Param\`etres des canaux}','interpreter','latex')
I found the answer on this stackoverflow page. Basically, I just have to set MATLABencoding to UTF-8 before creating the GUI. The command is simply:
feature('DefaultCharacterSet','UTF-8');
and that's it!
I was having difficulty copy-pasting the string from SO to MATLAB, as the "è" showed up as char(65533) (instead of the correct char(232)) for some reason...
Anyway, I threw together a small conversion utility to convert strings or cellstrings to their Unicode-in-HTML equivalent, to complement horchler's answer:
function html = toHTML(strings)
%% Initialize
% Basic IO check
if ~iscellstr(strings) && ~ischar(strings)
error(...
'toHTML:invalid_input',...
['Invalid input class: ''%s''.\n',...
'Supported input types are ''char'' or a ''cell'' containing ''char''.'], class(strings));
end
% Provide support for
% - Single and multiline line char arrays
% - Cellstrings
wasChar = ischar(strings);
if wasChar
if size(strings,1) > 1
strings(:, end+1) = char(10);
end
strings = {strings};
end
%% Convert all strings to their unicode representation in HTML
% Just for abbreviation
uf = {'UniformOutput',false};
% Convert all characters to their HTML unicode representation
html = cellfun(#transpose, strings, uf{:});
html = cellfun(#(x) cellstr(num2str(x(:)+0)), html, uf{:});
html = cellfun(#(x) cellfun(#(y) ['&#' strtrim(y) ';'],x, uf{:}), html, uf{:});
% Include HTML tags
html = cellfun(#(x) ['<html>' [x{:}] '</html>'], html, uf{:});
% Take care of newlining
html = regexprep(html, '
', '<br>');
html = regexprep(html, '<br></html>$', '</html>');
% Make output type consistent with input type
if wasChar
html = [html{:}];
end
end
I'm currently submitting this to the FEX as well. If anyone knows whether such a thing exists already, please let me know.
I've fixed this problem with this technique.
Write this in your terminal :
export LC_CTYPE="en_US.ISO-8859-1"
Then, launch Matlab and try :
title('été');
if that works, you only need to create a script that will execute the export command before launching Matlab. Either in your .bashrc file, a custom script launching Matlab, etc...
My workaround is simply to create a custom script (i.e. "mat" in my /home/username/bin directory) :
#!/bin/bash
cd /home/username/Matlab
export LC_CTYPE="en_US.ISO-8859-1"
/path/to/matlab/matlab
Then, I created an alias in the .bashrc file of the /home/username directory to launch the script "mat"
alias m="/home/proy/bin/mat &"
If it's inside a matlab script you store your string with accentuated characters, try to change the encoding of your matlab script to ANSI (eg, with Notepad++ or SublimeText).