Tag Info

Hot answers tagged

26

Have a look at FileNames: files=FileNames["*.pdf", NotebookDirectory[]] {"a.pdf","b.pdf","c.pdf"} will get you a list of all files in the directory where your notebook resides (of course you can choose any path) that match "*.pdf". You can then import the files like this: Import[#]&/@files or if you want certain files (look at the help for ...


24

Code extractor using the StackExchange API The following code uses the 2.0 version of the SE API and has also been cleaned up a bit (place it in your kernel's init.m or your custom functions package if you'd like to be able to use it anytime). The function takes a single string argument, which is the URL obtained from the "share" link under a ...


21

An alternative approach that does not require the ComputationalGeometry package: You can use a combination of ClusteringComponents and ComponentMeasurements as follows: Define chVertices[txtimg_] := Insert[#, First@#, -1] &@ ComponentMeasurements[ClusteringComponents[Binarize@txtimg, 2], "ConvexVertices"][[2, 2]] Example data: textimg1 = ...


20

You can use Inset: Show[{Graphics3D[{Opacity[0.2], Sphere[], Opacity[1.0], Blue, Inset[Graphics[Text[Style["Surprise!", Green, 24]]], {0, 0, 0}]}], ParametricPlot3D[{Sin[th] Cos[ph], Sin[th] Sin[ph], Cos[th]}, {th, 0, Pi}, {ph, 0, 2 Pi}, RegionFunction -> Function[{x, y, z}, Abs[x] < .9], PlotRange -> {-1, 1}, PlotStyle -> ...


20

It might be overkill, but with: DictionaryLookup[{"German", All}] you get a list of every German word. To be a bit more precise, you could then narrow things with string searches, i.e. DictionaryLookup[{"German", "a" ~~ ___ ~~ "b"}] gets you a list of words that begin with a and end with b. Full documentation is here.


20

Import text as a FilledCurve in graphics, using PDF as an intermediate format. Below are modified examples from Documentation Center: text = First[First[ImportString[ExportString[Style["Hi", Italic, FontSize -> 24, FontFamily -> "Times"], "PDF"], "PDF", "TextMode" -> "Outlines"]]]; Outline fonts using different edge and face forms: ...


17

You could use Row to build up the text to be shown: aboveBox[info_, colors_] := Graphics[{colors, EdgeForm[Thick], Rectangle[{0, 0}, {26, 3}], Text[Row[{Style["subject", 12, Bold, Black, TextAlignment -> Center], Style[info, 18, Bold, Red, TextAlignment -> Center]}], {26, 3}/ 2]}, ImageSize -> 300] aboveBox["AK6", ...


17

The following response borrows shamelessly from Mr.Wizard: Manipulate[ Graphics[{{Dashed, If[circle, Circle[{0, 0}, r], {}]}, Rotate[MapThread[ Rotate[Text[Style[#, FontFamily -> "Courier", fs], #2], 90° - #3] &, {txt, {-r Cos[#], r Sin[#]} & /@ (range = Range[0, arc, arc/(Length@txt - 1)]), range}], θ, {0, 0}]}, ...


17

This is just a quick sketching out of an answer (rescales galore!) textOnCurve[text_, f_, n_, p_: 0.01] := Text[Rotate[text, ArcTan @@ (f[Rescale[n + p, {0, 1}, {p, 1 - p}]] - f[Rescale[n - p, {0, 1}, {p, 1 - p}]])], f[n]] textCurve[string_, f_, stylef_: (# &), range_: {0, 1}] := With[{chars = ...


17

Here's a method based on creating a MeshRegion from the text: text = Style[HoldForm @ Sum[x^2, {x, 0, 10}], 100, Bold]; graphics = First[text ~ExportString~ "PDF" ~ImportString~ "PDF"]; region = DiscretizeGraphics[graphics, MaxCellMeasure -> 5]; image = ExampleData[{"ColorTexture", "Kingwood"}]; RegionPlot[region, Frame -> False, ...


15

Per Vitaliy's request: With[{before = 4, after = 5}, StringTake[text, First[StringPosition[text, "entitle"]] + {-before, after}]] yields "God entitle them".


15

The question could be rephrased: how do we get a vector graphic from a bitmap? The solution is pretty simple by using the code we can find here. p = Image[Graphics[Text[Style["Get Convex Hull points.", Large]]]]; img = Thinning@EdgeDetect@p; points = N@Position[ImageData[img], 1]; pts = Union@Flatten[FindCurvePath[points] /. c_Integer :> points[[c]], 1]; ...


15

For this purpose I made a function that puts an arbitrary expression into a 3D graphic. It's described on this page, going back originally to this MathGroup post, I'll copy the code here: label3D[s_, pos_, xVec_, tiltAngle_, opts : OptionsPattern[]] := Module[{ra, width, height, r}, ra = Rasterize[ Style[HoldForm[s], FilterRules[{opts}, ...


15

After downloading and unpacking the stanford Part-Of-Speech tagger that @PlatoManiac mentioned it is easy to call it with JLink: $POSTaggerPath = "/some/where/stanford-postagger-2013-11-12/"; << JLink` AddToClassPath[$POSTaggerPath]; tagString[str_String] := JavaBlock[ Module[{tagger}, ...


14

There are a variety of ways to do this. One can use Stylesheets as noted by acl. Perhaps the most direct way is this: For one Notebook: SetOptions[EvaluationNotebook[], FontSize -> 16] For all Notebooks: SetOptions[$FrontEnd, FontSize -> 16] You can also set FontSize for different Box types, such as GraphicsBox: SetOptions[$FrontEnd, ...


14

You can generate actual 3D data describing the text by Importing from PDF. wordData = ImportString[ExportString["Surprise", "PDF"], "PDF"][[1, 1, 2, 1, 1, 2]]; Graphics3D[Tube[#, 0.2] & /@ Map[Append[#, 0] &, wordData, {2}]] Or, in reference to Sjoerd's comment to the OP, wordData = ImportString[ExportString[Style["\[Euro]", FontFamily ...


14

This places a string on the outside of a unit circle. It works for variable width fonts. circularText[str_, ang : {a0_, a1_} : {0, 2 Pi}, scale:(_?NumericQ): 1] := Module[{text, curves, pts, xrange, ymin, xrlst, subgroups, maxwidth, centers}, (* transform string to FilledCurves *) text = ImportString[ ExportString[Style[str, Bold, FontFamily ...


14

You can open a text cell using Alt7, and type some text. When you need math, open a subcell using Ctrl9. Single letter variables will be formatted in italics in the subcell, as is usual. Use the usual shortcuts (e.g. Ctrl6 for superscript) to enter math. Use CtrlSpace to get out of the subcell (or the arrow keys). On a Mac, use ⌘ in place of Alt.


13

You could do something like this: string = "(Paste Here)" exps = Select[ string ~StringSplit~ "\n\n", SyntaxQ@# && ! MatchQ[MakeExpression@#, _@__Times | _@Null] &]; CellPrint@Cell[#, "Input"] & ~Scan~ exps


13

In the answer linked here, I did the following: out = FileNameJoin @ {$TemporaryDirectory, "MathematicaOutput" <> ToString /@ Date[] <> ".rtf"} /tmp/MathematicaOutput2012519111731.900549.rtf Then you would say Export[out, ...]. If you want to have the date in a more readable and less detailed form, you could use this for the name: ...


13

Here's another way...Text[] has a direction argument, so ArcTan is not necessary. txt1 = "Now we can follow" // Characters; txt2 = "an arbitrary path" // Characters; f[t_] := {Cos[2 π t], Sin[6 π t]}; totalarclength = NIntegrate[Sqrt[f'[τ].f'[τ]], {τ, 0, 1}]; invarclength = First@NDSolve[{D[$t[s], s] == 1/Sqrt[f'[$t[s]].f'[$t[s]]], $t[0] == 0}, $t, {s, 0, ...


13

Here's an attempt to implement the idea suggested by Szabolcs, based on Heike's clever image processing method. The code uses MinFilter to identify regions where the label may go without overlapping anything, and Nearest to pick the closest point to the desired position. The rest is just scaling between image and graphics coordinates. It won't be fast ...


12

Overall, your data is just badly formatted. For instance, later in the list your dates look similar to "3-Mar" which is interpreted as the third of March not March 2003, as you intended. For the most part, this is not your fault, but Excel arbitrarily formats data, and you have to be vigilant that it doesn't misinterpret it. Towards that end, I've rewritten ...


12

StringCases[text, x___ ~~ "entitle" ~~ y___ :> StringTake[x, -4] ~~ "entitle" ~~ StringTake[y, 5]] or StringCases[text, Repeated[_, 4] ~~ "entitle" ~~ Repeated[_, 5]] Generalizing: paddedString1[text_, string_, left_, right_] := StringCases[text, x___ ~~ string ~~ y___ :> StringTake[x, -left] ~~ string ~~ StringTake[y, right]] and ...


12

Using regular expressions f[text_, string_, before_, after_] := StringCases[text, RegularExpression[".{" <> ToString@before <> "}" <> string <> ".{" <> ToString@after <> "}"]] f[text, "entitle", 4, 5] (*{"God entitle them"}*) (added by J. M.) A more compact implementation of ...


12

Here is a starting point: txt = "This is some text to warp." // Characters; arc = 1; range = Range[0, arc, arc/(Length@txt - 1)]; coords = {-Cos[#], Sin[#]} & /@ range; Graphics[ MapThread[ Rotate[Text[Style[#, FontFamily -> "Courier"], #2], 90° - #3] &, {txt, coords, range}] ]


11

There is a subtle problem if you use strings as axis labels. Look closely at a plot like this: Plot[f, {x, -1, 1}, AxesLabel -> {x, "\!\(\*SubscriptBox[\(f\), \(i\)]\)(x)"}] You will see that the argument x in the function appears in a different font style than the argument on the horizontal axis. To make sure that you get a consistent font style on ...


11

Another method: text = Rasterize["Text"]; data = Position[text[[1, 1]], {0, 0, 0}]; rotated = RotationMatrix[90 Degree].# & /@ data; data2D = {-#1, #2} & @@@ rotated; << ComputationalGeometry` Quiet[convexhull = ConvexHull[data2D]]; hull = PlanarGraphPlot[data2D, convexhull]; Graphics[{Black, Point[data2D], hull[[1, 2]]}] Working it a bit ...


11

I think you can just do this: file1dat = Import["file1.txt", "Table"]; file2dat = Import["file2.txt", "Table"]; file3dat = Import["file3.txt", "Table"]; Export["output.txt", Join[file1dat, file2dat, file3dat, 2]]; Edit: Here's a better solution, which will place the entire lines of text (regardless of whether there is whitespace within a line) next to ...


11

Rather than using a Rectangle, consider a Pane that is Framed text = "Bunch of random text "; Framed@Pane[StringJoin @@ Table[text, {10}], 300] The second argument to Pane determines the width in points. If you want more control over the text within the Pane, consider putting a TextCell inside the Pane. If you just use a TextCell, you can't control ...



Only top voted, non community-wiki answers of a minimum length are eligible