Replace '\t' with the correct amount of spaces inside a text object - matlab

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(...).

Related

How to add a vector notation above a variable name composed of multiple characters?

In Julia it is possible to add Unicode characters with LaTeX like syntax. All allowed unicode characters can be found here. For example, it is possible to add a right arrow over a character with this simple code
F\vec[TAB]
and it produces the following character
But I couldn't find a syntax to add the same right arrow over a whole word as \vec seems to always add the arrow over the previous character and does not allow to group them. For example
force\vec[TAB]
produces
Does the syntax for this feature exists ?

VSCode custom font ligatures, display two symbols as one?

I would like to display list.emptyqm() as list.empty?() in function names for specific language. So, two symbols qm if they are at the end of the function name should be displayed as ? (possibly some unicode symbol looking similar to question mark).
Is that possible in VSCode?
The VSCode already knows that piece of text is string, or function-name/keyword/variable-name (as it highlights it properly), so the ligature should be displayed only if qm are the last
characters of function-name/keyword/variable-name. It shouldn't be displayed in the middle of the function name, like aqma() shouldn't be displayed as a?a().
You seem to misunderstand what a ligature is. A ligature describes how two individual letters can be combined to form a visual pleasing appearance. A ligature never changes the syntax of a text. Hence, converting qm to ? is a completely different thing.
Replacing text in vscode is of course possible, for instance as part of the format command. You can register your own formatter and determine the text edit actions that you want to be applied, including the transformation of these character sequences.

How to escape '|" character into an org-mode table

I am building some tables in org-mode and I need to enter "||" into the table (for the logical OR command) and nothing I try turns the two characters off as table constructors.
I've tried single quotes, double quotes, backticks and prefacing them with '\'. I've also tried every permutation of using ':=' to get a literal string and they don't work.
// Tony Williams
Depending on what you want to do with the output of the table, you could use alternative unicode characters that look like vertical pipes (or double vertical pipes). Examples:
This is the pipe character written twice (as for logical OR):
||
Those are similar (or not too different) looking unicode characters
‖ - ¦¦ - ❘❘
Of course, this won't work for you if you are not just interested in the looks (but escaping pipes would not work either).
See here more unicode characters you might like better than those 3 above
It turns out that you can use HTML entities in org-mode tables for output via pandoc.
\vert{} doesn't work but I went to the table pointed to by MrSpock and tried the HTML entity and the output when run through pandoc was perfect. || gives me '||'. I also tested a few other HTML entities and they also worked fine.
Well, if the goal is to export your notes, then
$\lvert\mathbb{N}\rvert$
would be an equivalent of
$|\mathbb{N}|$
Character is: \vert
Example: a \vert\ b -> a | b

Finding the format of arbitrary delimited text file in MATLAB

I have a file that looks like this in notepad++
I can easily see the spaces (being the orange dots), and tabs (being the orange arrows). I can also right click this in MATLAB and import it in a variety of ways. The problem is firstly the delimiters are not consistent. It seems to go TAB then some spaces to make sure the total field equals 6 characters...
The only way I understand reading a file in is if you already know how it is delimited. But in this case I would like to parse each line so MATLAB has some 'token' of what goes where eg:
Line1: Text Space Text Space Text Tab Space Space Text NEWLINE
(Notepad++ seems to know just fine so surely MATLAB can get this info too?).
Is this possible? Then it would be nice to use this information to save the imported data back out to a file with exactly the same formatting.
The data is below. For some reason copying this into notepad++ does not preserve its delimiting, you will need to add the tabs in yourself so it looks like the file in the screenshot.
Average Counts : 56.2
Time : 120
Thanks
If you use textscan, the default behaviour should probably suit your needs:
Within each row of data, the default field delimiter is white space. White space can be any combination of space (' '), backspace ('\b'), or tab ('\t') characters. If you do not specify a delimiter, textscan interprets repeated white-space characters as a single delimiter.
The output is a cell array, where each column is saved as a cell. So C{1} would contain the strings, C{2} the colons, and C{2} the values.

pandoc-generated docx misses italic variables in equations

I have the following segment of Markdown with embedded LaTeX equations:
# Fisher's linear discriminant
\newcommand{\cov}{\mathrm{cov}}
\newcommand{\A}{\mathrm{A}}
\renewcommand{\B}{\mathrm{B}}
\renewcommand{\T}{^\top}
The first method to find an optimal linear discriminant was proposed by Fisher
(1936), using the ratio of the between-class variance to the within-class variance
of the projected data, $d(\vec x)$, as a criterion. Expressed in terms of the
sample properties, the $p$-dimensional centroids $\bar {\vec x}_\A$ and
$\bar {\vec x}_\B$ and the $p \times p$ covariance matrices
$S_A = \cov_i ( \vec x_{\A i} )$ and $S_B = \cov_i ( \vec x_{\B i} )$, the
optimal direction is given by
$$
\vec w = \left ( \frac{ S_A + S_B }{2} \right ) ^{-1}
~ ( \bar {\vec x}_\B - \bar {\vec x}_\A ).
$$
When I convert it with pandoc to LaTeX and compile it with xelatex, I get the expected text with nicely rendered math. When I convert it with pandoc to MS Word using
pandoc test.text -o test.docx
and open it in MS Office Word 2007, I get the following:
Only those parts of the equations that are symbols or upright text get rendered correctly, while variable names in italics are replaced by a question mark in a box.
How can I make this work?
In Word 2007, I see a result similar to yours, except that here, I don't see the "question marks in boxes" characters, just space.
If I then take one of the expressions, and use your trick of going to linear display and back, the characters reappear for that expression.
If I save and re-open, the other expressions still do not display correctly, but if I save and look at the XML, I notice that
the Math font has been changed to Cambria Math
additional run parameter (w:rPr) XML specifying the Cambria Math
font has been inserted in many of the runs (w:r) inside the oMath
elements, even in the oMath expressions that do not display
correctly. However, in the oMath expression that now displays
correctly, this extra XML has been applied to every run. In the
others, it has only been applied to some runs (I think I can see the
pattern but I'm running out of time here right now...)
If I manually add the XML to the other runs and re-open the
document, the expressions appear correctly. Or at least, they do in
the one case I have tried.
Since Word 2010 displays the resuls correctly, I can only assume that it does not rely on these explicit font settings, whereas Word 2007 does. This doesn't really help you yet, because altering all those w:r elements would be even harder than what you are already doing. But it is possible that a default style/font needs to be set, either somewhere higher in the XML hierarchy, or perhaps elsewhere in the .zip (perhaps in fontTable.xml or styles.xml). I'm not familiar enough with Word's XML structures to guess what, if anything might be missing, but may be able to have a look tomorrow.
I suppose another possibility is that you just have to have all these extra rPr elements for this to work in Word 2007, which would suggest that pandoc may have been written for Word 2010, not 2007. (I don't know anything about the tool).
As an example, where you have
<m:r>
<m:t>(</m:t>
</m:r>
what you need is
<m:r>
<w:rPr>
<w:rFonts w:ascii="Cambria Math" w:hAnsi="Cambria Math" />
</w:rPr>
<m:t>(</m:t>
</m:r>
I did the following to get rid of the font issue:
Create a new empty word document.
Copy all content to the new document.
Choose Match Source Format.
As discussed above, Windows doesn't have the font Lucida Grande, so substituting the Math Font with Cambria Math should work.
Rename the test.docx to test.zip
vim test.zip and select test/word/settings.xml
find and change Lucida Grande to Cambria Math
save and rename zip to docx. This results in something like this docx.
You can then also supply that file as a sort of docx template to pandoc with the --reference-docx option.