# Tag Info

8

You can use this to create a functionality which will fit your need the best. Here's how you can preview your input cell with c highlighted Red. CellPrint[ NotebookRead @ PreviousCell[] /. "c" -> InterpretationBox[ StyleBox["c", FontColor -> RGBColor[1, 0, 0]], Unevaluated@c ] ] You can even evaluate such ...

1

deriv[f_[x_]] := Inactivate[ ToExpression@StringJoin[ToString[f], ToString[x]] = D[f[x], x], Set | D] Then: deriv[kr[x]] outputs Inactive[Set][kryx, Inactive[D][kr[yx], yx]] which displays as kryx = D[kr[yx], yx]

2

Maybe this: deriv[f_[x_]] := Inactive[D][f[x], x] Then:

5

Through[{KeyDrop, KeyTake}[asc, {"c", "f"}]]

1

The documentation example is clearly wrong. Probably was written without proper testing. A second argument giving a spacer element must be added to Row. The quotes delimiting the spacer string must be escaped. StringTemplate[ "The first 1 Fibonnaci numbers are: <* \ Row[Table[Fibonacci[n+1],{n, #1}],\", \"] *>."][5] "The first 5 Fibonnaci ...

4

I would say that there may be a mistake in the documentation. In order to get the comma separated format, you should provide an explicit separator to Row: StringTemplate["The first 1 Fibonacci numbers are: <* Row[Table[Fibonacci[n + 1], {n, #1}], \", \"] *>."][5]

2

After a bit, I hit upon a solution involving a round-trip through the import/export subsystem. First, it is helpful to have everything in the same representation, so we need to put the mathml into XMLElement form, e.g. mathml = ImportString[ExportString[1/2, "MathML"], {"MathML", "XMLElement"}] (* XMLElement["math", {"xmlns" -> ...

8

You have too many backslashes. ImportString["\"Applications num\303\251riques\"", "Text", CharacterEncoding -> "UTF8"] does what you want. If you already have the string imported into Mathematica incorrectly, you can use FromCharacterCode with ImportString, with its second option. In[1]:= "Applications num\303\251riques" Out[1]= "Applications ...

4

This is a pretty ugly hack, but maybe it will inspire you to something better. leastCJK = ToCharacterCode["⺀"][[1]]; StringMatchQ[#, _?(ToCharacterCode[#][[1]] < leastCJK &)] & /@ {"a", "1", ".", " ", "中", "あ"} {True, True, True, True, False, False} Note: "⺀" is unicode character U+2E80, CJK RADICAL REPEAT This hack can be used with ...

3

a = 1; b = 5; c = 12; (* version 10 *) StringTemplate["1-2-3.mx"][a, b, c] (* "1-5-12.mx" *) (* 10 and lower *) StringJoin @@ Riffle[ToString /@ {a, b, c}, "-"] <> ".mx" (* "1-5-12.mx" *)

1

Moving it to a Manipulate sounds like a better idea: Manipulate[ makes = Import[ StringJoin[ "http://www.fueleconomy.gov/ws/rest/vehicle/menu/make?year=", ToString@year], "XML"]; Row[{"Loaded car makes for the year ", Style[ToString[year], {FontFamily -> "Arial", Large, Red}]}], {year, Reverse@years} ]

3

If there is always one space at a time as shown, or if the number of spaces is irrelevant: str = "1a 789 4/7 123/7 asff %$#7 478 9/4"; StringSplit[str] /. s_String /; StringMatchQ[s, DigitCharacter ..] :> s <> "/1" // StringRiffle "1a 789/1 4/7 123/7 asff %$#7 478/1 9/4" Or adjusting J.M.'s comment code to work: StringReplace[str, w1 : ...

5

Here are two ways. SemanticInterpretation is sort of fun but extremely slow: SemanticInterpretation["{26.2417,-98.432},{26.2407,-98.4247}", List[_, _] ..] Fixing up your data to fit Yves Klett's suggestion is much faster: ToExpression["{" <> "{26.2417,-98.432},{26.2407,-98.4247}" <> "}"] Both yield (* {{26.2417, -98.432}, {26.2407`, ...

1

Without having the .csv file to work on, as guess who it is said, this should get you where your going. cord=Import["mydrive/file.csv","Data"]//ToExpression Again Please give a sample of what the data is in the .csv file.

2

Please try: StringReplace[in, d1 : DigitCharacter .. ~~ "/" ~~ d2 : DigitCharacter .. :> "\!$$\*FractionBox[\(" ~~ d1 ~~ "$$, $$" ~~ d2 ~~ "$$]\)"]

0

Since Plus already does the element-wise addition, you can do: La + Lb /. Plus -> (List /* Map[ToString] /* StringJoin) This assumes the elements won't be destroyed by the plus, but as described by LLlAMnYP you can just Listableize the function: Function[{a, b}, StringJoin[ToString /@ {a, b}], Listable][La, Lb] or ToString before the operation: ...

8

Here's an approach for any two multi-dimensional lists of strings which have arbitrary, but matching structures: stringJoin[x__String] := StringJoin[x] SetAttributes[stringJoin, Listable] stringJoin[La, Lb] EDIT Short explanation of listability: Listable functions are effectively applied separately to each element in a list, or to corresponding ...

4

sLa = Map[ToString, La, {2}]; sLb = Map[ToString, Lb, {2}]; MapThread[StringJoin, #] & /@ Transpose[{sLa, sLb}] also Thread[j @@ #] & /@ Transpose[{sLa, sLb}] /. j -> StringJoin

3

Yes, it is possible to get Mathematica to accept TeXForm input in raw form without quotes, using a method similar to the one described in this answer. Using $PreRead to intercept the input before it is interpreted by Mathematica and then convert it to a string, we can define the latextoma function as a replacement rule with$PreRead = (# /. ...

4

Here is a solution, based on pattern matching in the list of rules of the association: acs //. x_Association :> Normal[x] DeleteCases[ %, (key_->val_String) /; StringMatchQ[val, " "..], Infinity] DeleteCases[ %, _->{}] % /. List->Association (* {A->{a-> ,aa->asd},B->{bb-> }} {A->{aa->asd},B->{}} {A->{aa->asd}} ...

5

DeleteCases[Association@KeyValueMap[#1->DeleteCases[#2,_?(StringMatchQ[ToString@#,Whitespace..]&)]&,acs],_?(#==<||>&)]

3

I think this is easier to do by working with strings. First write a function that will expand strings of the form "Power(x,k)" where k is an integer in "xx...x" with k - 1 ""s. f[x_, k_] := Module[{i = Abs[ToExpression[k]] - 1}, Nest[StringJoin[#, "*" <> x] &, x, i]] A couple of tests for f. f["s", 2] "s*s" f["ab", "-3"] ...

3

Accepting that in Mathematica -c/y is automatically converted to -1*c*y^-1 and permitting the result shown in Andy's answer I believe we can use a simpler approach, at least for the kind of expression given in example. Define rules that determine how a Times or Power expression should be counted, then use Cases to find all instances in you expression and ...

1

This doesn't give the result you are looking for exactly because it uses the full form of the expression you give it. SetAttributes[countTimes, HoldAll]; countTimes[expr_] := Block[{Times, Power, power, times}, power[a_, b_ /; b > 0] := Nest[times[a, #] &, a, b - 1]; power[a_, b_ /; b < 0] := 1/power[a, -b]; power[a_, 0] := 1; times[a___, ...

9


2


10

You can test whether braces are balanced with something like (version simplified by Guess who it is.): ClearAll[balancedBracesQ] balancedBracesQ[str_String] := StringCount[str, "{"] === StringCount[str, "}"] And use it in string pattern in following way: StringCases[ "a\\newcommand{ABC{asdas}{asdsad}}{DEF{x}y}asdkashdkj\ ...

Top 50 recent answers are included