flutter TexView - Insert values to raw strings - flutter

I'm trying to get the flutter package flutter_tex (Link) working.
It renders fine, but I am not able to put my own values into the formula.
Example (factorB is the variables name):
String second = r"<br> $$x={\sqrt{factorB}}$$";
Result:
I also tried the $-operator before the variable like in a dart string, but because a raw string is needed, this doesn't work.
Is there a way to implement variable values in a raw string with this package?

It is not strictly necessary to use a raw string. Doing so just makes it more convenient to type all the back slashs and brackets required in LaTeX code.
You could always work with regular string, this just makes it more incovenient to produce correct LaTeX. Instead, I would suggest manually replacing the placeholder:
int number = 42;
String latex = r"<br> $$x={\sqrt{factorB}}$$";
latex = latex.replaceAll("factorB", number.toString());
If you would like to support more advanced interpolation via expressions,
I would recommend placing all of that logic inside the replace method. This here is an example
int factorB = 17;
int factorB = 1;
String latex = r"exprA(x${exprB}$exprC)²exprD";
latex = latex.replaceAll("exprA", 42);
latex = latex.replaceAll("exprB", factorB >= 0 ? "+" : "");
latex = latex.replaceAll("exprC", factorC >= 0 ? "+" : "");
latex = latex.replaceAll("exprD", 33);

Related

How to get upper str this case

I want to get upper"T"..
how to get upper string!
str = "Test Version"
print(str.upper())
print(str[3])
It's not clear what you are asking.
But from context I am guessing you would like to make the second non-capitalised "t" in the string uppercase. I'm also going to assume you are using python 3 given your use of upper().
If you just want to get the "t" (and not change the string itself):
upper_T = str[3].upper()
If you want to create a string from the original you may be running into the fact that strings in python are immutable. You therefore must create a new string.
One way do this:
str2 = list(str)
str2[3] = str[3].upper()
str2 = ''.join(str2)

Need code for removing all unicode characters in vb6

I need code for removing all unicode characters in a vb6 string.
If this is UTF-16 text (as normal VB6 String values all are) and you can ignore the issue of surrogate pairs, then this is fairly quick and reasonably concise:
Private Sub DeleteNonAscii(ByRef Text As String)
Dim I As Long
Dim J As Long
Dim Char As String
I = 1
For J = 1 To Len(Text)
Char = Mid$(Text, J, 1)
If (AscW(Char) And &HFFFF&) <= &H7F& Then
Mid$(Text, I, 1) = Char
I = I + 1
End If
Next
Text = Left$(Text, I - 1)
End Sub
This has the workaround for the unfortunate choice VB6 had to make in returning a signed 16-bit integer from the AscW() function. It should have been a Long for symmatry with ChrW$() but it is what it is.
It should beat the pants off any regular expression library in clarity, maintainability, and performance. If better performance is required for truly massive amounts of text then SAFEARRAY or CopyMemory stunts could be used.
Public Shared Function StripUnicodeCharactersFromString(ByVal inputValue As String) As String
Return Regex.Replace(inputValue, "[^\u0000-\u007F]", String.Empty)
End Function
Vb6 - not sure will
sRTF = "\u" & CStr(AscW(char))
work? - You could do this for all char values above 127
StrConv is the command for converting strings.
StrConv Function
Returns a Variant (String) converted as specified.
Syntax
StrConv(string, conversion, LCID)
The StrConv function syntax has these named arguments:
Part Description
string Required. String expression to be converted.
conversion Required. Integer. The sum of values specifying the type of conversion to perform. `128` is Unicode to local code page (or whatever the optional LCID is)
LCID Optional. The LocaleID, if different than the system LocaleID. (The system LocaleID is the default.)

double.parse(str) result is off by orders of magnitude

I have a weird problem in converting a string to double in .NET 3.5. Here is my code:
dbl = double.Parse(str);
When str is string with a simple double like "5.67" the result for dbl is 567.0.
I'd guess this is localisation issues and you need to use the overload that specifies a format provider.
The issue is likely that it is expecting , as a decimal separator and . as a thousand separator (and thus ignoring it in effect).
Example to reproduce possible issue:
string input = "5.67";
Console.WriteLine(Double.Parse(input, new CultureInfo("en-gb")));
Console.WriteLine(Double.Parse(input, new CultureInfo("de-de")));
This outputs:
5.67
567
I'm just editing Chris's answer:
value = "5.67";
double out;
style = NumberStyles.Number | NumberStyles.AllowCurrencySymbol;
culture = CultureInfo.CreateSpecificCulture("en-GB");
Console.WriteLine(Double.TryParse(value, style, culture, out number)?number:0);

Translate VBA syntax to Matlab for Activex control of Word document

I am a newbie to using activex controls in matlab. Am trying to control a word document. I need help translating between VBA syntax and Matlab, I think. How would one code the following in matlab?
Sub macro()
With CaptionLabels("Table")
.NumberStyle = wdCaptionNumberStyleArabic
.IncludeChapterNumber = True
.ChapterStyleLevel = 1
.Separator = wdSeparatorHyphen
End With
Selection.InsertCaption Label:="Table", TitleAutoText:="", Title:="", _
Position:=wdCaptionPositionAbove, ExcludeLabel:=0
End Sub
Thanks, I looked at the help and the source but I am still feeling dense. I want to be able to control caption numbering and caption text in an automated report. Am using Tables and figures. I just can't quite get my head around how to code the addition of the captions.
The following code gets me part way there. But I don't have control over numbering style, etc,. I have tried to figure out the activex structure but I can't make sense of it. In particular, In particular the first bit the VB subroutine above.
% Start an ActiveX session with Word
hdlActiveX = actxserver('Word.Application');
hdlActiveX.Visible = true;
hdlWordDoc = invoke(hdlActiveX.Documents, 'Add');
hdlActiveX.Selection.InsertCaption('Table',captiontext);
After some fiddling, I think I got it to work:
%# open Word
Word = actxserver('Word.Application');
Word.Visible = true;
%# create new document
doc = Word.Documents.Add;
%# set caption style for tables
t = Word.CaptionLabels.Item(2); %# 1:Figure, 2:Table, 3:Equation
t.NumberStyle = 0; %# wdCaptionNumberStyleArabic
t.IncludeChapterNumber = false;
t.ChapterStyleLevel = 1;
t.Separator = 0; %# wdSeparatorHyphen
%# insert table caption for current selection
Word.Selection.InsertCaption('Table', '', '', 0, false) %# wdCaptionPositionAbove
%# save document, then close
doc.SaveAs2( fullfile(pwd,'file.docx') )
doc.Close(false)
%# quit and cleanup
Word.Quit
Word.delete
Refer to the MSDN documentation to learn how to use this API. For example, the order of arguments of the InsertCaption function used above.
Note that I had to set IncludeChapterNumber to false, otherwise Word was printing "Error! No text of specified style in document" inside the caption text...
Finally, to find out the integer values of the wd* enums, I am using the ILDASM tool to disassemble the Office Interop assemblies (as this solution suggested). Simply dump the whole thing to text file, and search for the strings you are looking for.
Have a look at the help for actxserver and the source code for xlsread.m in the base MATLAB toolbox. If you're still stuck, then update your question with your progress.
EDIT:
You'll need to check the VBA help, but the first part ought to be possible via something like:
o = hdlWordDoc.CaptionLabels('Table');
o.NumberStyle = <some number corresponding to wdCaptionNumberStyleArabic>;
o.IncludeChapterNumber = true;
o.ChapterStyleLevel = 1;
o.Separator = <some number corresponding to wdSeparatorHyphen>;
In my experience, you have to get the values from the enumerations, such as wdCaptionNumberStyleArabic and wdSeparatorHyphen from a VBA script then hard-code them. You can try the following, but I don't think it works:
o.NumberStyle = 'wdCaptionNumberStyleArabic';
o.Separator = 'wdSeparatorHyphen';
Instead of hard-coding the text values into the code, you can use the enum constants. This will help when a different language of Word is installed.
A list of the Enums can be found here: https://learn.microsoft.com/en-us/office/vba/api/word(enumerations)
So instead of:
Word.Selection.InsertCaption('Table', '', '', 0, false) %# wdCaptionPositionAbove
you can use this:
NET.addAssembly('Microsoft.Office.Interop.Word')
Word.Selection.InsertCaption(...
Microsoft.Office.Interop.Word.WdCaptionLabelID.wdCaptionTable.GetHashCode,...
' My custom table caption text', '', ...
Microsoft.Office.Interop.Word.WdCaptionPosition.wdCaptionPositionAbove.GetHashCode, false)

how to change display in gtk.spinbutton

I have a gtk.spinbutton and I want to set the digits according to the locale
format.
like say I have a locale installed hungarian so my decimal separator is
'.'(dot) and thousand separator is ','(comma) eg: my spinbutton value is
1131191 so after the user focus out of the gtk.spinbutton my value should
convert to 11,311.91 . the conversion is made by me but I am not able to set
it to gtk.spinbutton either using set_text / set_value method.
Any help is appreciated !
Thanks
Formatting a SpinButton can be done by handling the output signal.
locale.setlocale(locale.LC_ALL, '')
def output(spin):
digits = int(spin.props.digits)
value = spin.props.value
text = locale.format('%.*f', (digits, value), True)
spin.props.text = text
return True
spin.connect('output', output)
If you also want to let users enter values in the localised format (e.g. let the user type "1,000" instead of "1000"), handle the input signal.
def input(spin, new_value):
text = spin.props.text
try:
value = locale.atof(text)
except ValueError:
return -1
p = ctypes.c_double.from_address(hash(new_value))
p.value = value
return True
spin.connect('input', input)
(This code is longer than it should be because PyGTK does not properly wrap input, hence the ctypes hack. It's just parsing the text and then assigning the numeric value to a pointer location.)
Credits: The ctypes hack and digits formatting are inspired by Tim Evans's post in the PyGTK mailing list.