HumanReadableLogsRules.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. /* eslint-disable no-useless-escape */
  2. import React from 'react'
  3. import PropTypes from 'prop-types'
  4. import ReactDOMServer from 'react-dom/server'
  5. function WikiLink({ url, children }) {
  6. return window.wikiEnabled ? (
  7. <a href={url} target="_blank">
  8. {children}
  9. </a>
  10. ) : (
  11. <>{children}</>
  12. )
  13. }
  14. WikiLink.propTypes = {
  15. url: PropTypes.string,
  16. children: PropTypes.node.isRequired
  17. }
  18. const rules = [
  19. {
  20. regexToMatch: /Misplaced alignment tab character \&/,
  21. extraInfoURL:
  22. 'https://www.overleaf.com/learn/Errors/Misplaced_alignment_tab_character_%26',
  23. humanReadableHintComponent: (
  24. <>
  25. You have placed an alignment tab character '&' in the wrong place. If
  26. you want to align something, you must write it inside an align
  27. environment such as \begin
  28. {'{align}'} … \end
  29. {'{align}'}, \begin
  30. {'{tabular}'} … \end
  31. {'{tabular}'}, etc. If you want to write an ampersand '&' in text, you
  32. must write \& instead.
  33. </>
  34. )
  35. },
  36. {
  37. regexToMatch: /Extra alignment tab has been changed to \\cr/,
  38. extraInfoURL:
  39. 'https://www.overleaf.com/learn/Errors/Extra_alignment_tab_has_been_changed_to_%5Ccr',
  40. humanReadableHintComponent: (
  41. <>
  42. You have written too many alignment tabs in a table, causing one of them
  43. to be turned into a line break. Make sure you have specified the correct
  44. number of columns in your{' '}
  45. <WikiLink url="https://www.overleaf.com/learn/Tables">table</WikiLink>.
  46. </>
  47. )
  48. },
  49. {
  50. regexToMatch: /Display math should end with \$\$/,
  51. extraInfoURL:
  52. 'https://www.overleaf.com/learn/Errors/Display_math_should_end_with_$$',
  53. humanReadableHintComponent: (
  54. <>
  55. You have forgotten a $ sign at the end of 'display math' mode. When
  56. writing in display math mode, you must always math write inside $$ … $$.
  57. Check that the number of $s match around each math expression.
  58. </>
  59. )
  60. },
  61. {
  62. regexToMatch: /Missing [{$] inserted./,
  63. extraInfoURL: 'https://www.overleaf.com/learn/Errors/Missing_$_inserted',
  64. humanReadableHintComponent: (
  65. <>
  66. Check that your $'s match around math expressions. If they do, then
  67. you've probably used a symbol in normal text that needs to be in math
  68. mode. Symbols such as subscripts ( _ ), integrals ( \int ), Greek
  69. letters ( \alpha, \beta, \delta ), and modifiers (\vec
  70. {'{x}'}, \tilde
  71. {'{x}'} ) must be written in math mode. See the full list{' '}
  72. <WikiLink url="https://www.overleaf.com/learn/Errors/Missing_$_inserted">
  73. here
  74. </WikiLink>
  75. . If you intended to use mathematics mode, then use $ … $ for 'inline
  76. math mode', $$ … $$ for 'display math mode' or alternatively \begin
  77. {'{math}'} … \end
  78. {'{math}'}.
  79. </>
  80. )
  81. },
  82. {
  83. regexToMatch: /(undefined )?[rR]eference(s)?.+(undefined)?/,
  84. extraInfoURL:
  85. 'https://www.overleaf.com/learn/Errors/There_were_undefined_references',
  86. humanReadableHintComponent: (
  87. <>
  88. You have referenced something which has not yet been labelled. If you
  89. have labelled it already, make sure that what is written inside \ref
  90. {'{...}'} is the same as what is written inside \label
  91. {'{...}'}.
  92. </>
  93. )
  94. },
  95. {
  96. regexToMatch: /Citation .+ on page .+ undefined on input line .+/,
  97. extraInfoURL:
  98. 'https://www.overleaf.com/learn/Errors/Citation_XXX_on_page_XXX_undefined_on_input_line_XXX',
  99. humanReadableHintComponent: (
  100. <>
  101. You have cited something which is not included in your bibliography.
  102. Make sure that the citation (\cite
  103. {'{...}'}) has a corresponding key in your bibliography, and that both
  104. are spelled the same way.
  105. </>
  106. )
  107. },
  108. {
  109. regexToMatch: /(Label .+)? multiply[ -]defined( labels)?/,
  110. extraInfoURL:
  111. 'https://www.overleaf.com/learn/Errors/There_were_multiply-defined_labels',
  112. humanReadableHintComponent: (
  113. <>
  114. You have used the same label more than once. Check that each \label
  115. {'{...}'} labels only one item.
  116. </>
  117. )
  118. },
  119. {
  120. regexToMatch: /`!?h' float specifier changed to `!?ht'/,
  121. extraInfoURL:
  122. 'https://www.overleaf.com/learn/Errors/%60!h%27_float_specifier_changed_to_%60!ht%27',
  123. humanReadableHintComponent: (
  124. <>
  125. The float specifier 'h' is too strict of a demand for LaTeX to place
  126. your float in a nice way here. Try relaxing it by using 'ht', or even
  127. 'htbp' if necessary. If you want to try keep the float here anyway,
  128. check out the{' '}
  129. <WikiLink url="https://www.overleaf.com/learn/Positioning_of_Figures">
  130. float package
  131. </WikiLink>
  132. .
  133. </>
  134. )
  135. },
  136. {
  137. regexToMatch: /No positions in optional float specifier/,
  138. extraInfoURL:
  139. 'https://www.overleaf.com/learn/Errors/No_positions_in_optional_float_specifier',
  140. humanReadableHintComponent: (
  141. <>
  142. You have forgotten to include a float specifier, which tells LaTeX where
  143. to position your figure. To fix this, either insert a float specifier
  144. inside the square brackets (e.g. \begin
  145. {'{figure}'}
  146. [h]), or remove the square brackets (e.g. \begin
  147. {'{figure}'}
  148. ). Find out more about float specifiers{' '}
  149. <WikiLink url="https://www.overleaf.com/learn/Positioning_of_Figures">
  150. here
  151. </WikiLink>
  152. .
  153. </>
  154. )
  155. },
  156. {
  157. regexToMatch: /Undefined control sequence/,
  158. extraInfoURL:
  159. 'https://www.overleaf.com/learn/Errors/Undefined_control_sequence',
  160. humanReadableHintComponent: (
  161. <>
  162. The compiler is having trouble understanding a command you have used.
  163. Check that the command is spelled correctly. If the command is part of a
  164. package, make sure you have included the package in your preamble using
  165. \usepackage
  166. {'{...}'}.
  167. </>
  168. )
  169. },
  170. {
  171. regexToMatch: /File .+ not found/,
  172. extraInfoURL:
  173. 'https://www.overleaf.com/learn/Errors/File_XXX_not_found_on_input_line_XXX',
  174. humanReadableHintComponent: (
  175. <>
  176. The compiler cannot find the file you want to include. Make sure that
  177. you have{' '}
  178. <WikiLink url="https://www.overleaf.com/learn/Including_images_in_ShareLaTeX">
  179. uploaded the file
  180. </WikiLink>{' '}
  181. and{' '}
  182. <WikiLink url="https://www.overleaf.com/learn/Errors/File_XXX_not_found_on_input_line_XXX.">
  183. specified the file location correctly
  184. </WikiLink>
  185. .
  186. </>
  187. )
  188. },
  189. {
  190. regexToMatch: /LaTeX Error: Unknown graphics extension: \..+/,
  191. extraInfoURL:
  192. 'https://www.overleaf.com/learn/Errors/LaTeX_Error:_Unknown_graphics_extension:_.XXX',
  193. humanReadableHintComponent: (
  194. <>
  195. The compiler does not recognise the file type of one of your images.
  196. Make sure you are using a{' '}
  197. <WikiLink url="https://www.overleaf.com/learn/Errors/LaTeX_Error:_Unknown_graphics_extension:_.gif.">
  198. supported image format
  199. </WikiLink>{' '}
  200. for your choice of compiler, and check that there are no periods (.) in
  201. the name of your image.
  202. </>
  203. )
  204. },
  205. {
  206. regexToMatch: /LaTeX Error: Unknown float option `H'/,
  207. extraInfoURL:
  208. 'https://www.overleaf.com/learn/Errors/LaTeX_Error:_Unknown_float_option_%60H%27',
  209. humanReadableHintComponent: (
  210. <>
  211. The compiler isn't recognizing the float option 'H'. Include \usepackage
  212. {'{float}'} in your preamble to fix this.
  213. </>
  214. )
  215. },
  216. {
  217. regexToMatch: /LaTeX Error: Unknown float option `q'/,
  218. extraInfoURL:
  219. 'https://www.overleaf.com/learn/Errors/LaTeX_Error:_Unknown_float_option_%60q%27',
  220. humanReadableHintComponent: (
  221. <>
  222. You have used a float specifier which the compiler does not understand.
  223. You can learn more about the different float options available for
  224. placing figures{' '}
  225. <WikiLink url="https://www.overleaf.com/learn/Positioning_of_Figures">
  226. here
  227. </WikiLink>{' '}
  228. .
  229. </>
  230. )
  231. },
  232. {
  233. regexToMatch: /LaTeX Error: \\math.+ allowed only in math mode/,
  234. extraInfoURL:
  235. 'https://www.overleaf.com/learn/Errors/LaTeX_Error:_%5Cmathrm_allowed_only_in_math_mode',
  236. humanReadableHintComponent: (
  237. <>
  238. You have used a font command which is only available in math mode. To
  239. use this command, you must be in maths mode (E.g. $ … $ or \begin
  240. {'{math}'} … \end
  241. {'{math}'}
  242. ). If you want to use it outside of math mode, use the text version
  243. instead: \textrm, \textit, etc.
  244. </>
  245. )
  246. },
  247. {
  248. ruleId: 'hint_mismatched_environment',
  249. types: ['environment'],
  250. regexToMatch: /Error: `([^']{2,})' expected, found `([^']{2,})'.*/,
  251. newMessage: 'Error: environment does not match \\begin{$1} ... \\end{$2}',
  252. humanReadableHintComponent: (
  253. <>
  254. You have used \begin
  255. {'{...}'} without a corresponding \end
  256. {'{...}'}.
  257. </>
  258. )
  259. },
  260. {
  261. ruleId: 'hint_mismatched_brackets',
  262. types: ['environment'],
  263. regexToMatch: /Error: `([^a-zA-Z0-9])' expected, found `([^a-zA-Z0-9])'.*/,
  264. newMessage: "Error: brackets do not match, found '$2' instead of '$1'",
  265. humanReadableHintComponent: (
  266. <>You have used an open bracket without a corresponding close bracket.</>
  267. )
  268. },
  269. {
  270. regexToMatch: /LaTeX Error: Can be used only in preamble/,
  271. extraInfoURL:
  272. 'https://www.overleaf.com/learn/Errors/LaTeX_Error:_Can_be_used_only_in_preamble',
  273. humanReadableHintComponent: (
  274. <>
  275. You have used a command in the main body of your document which should
  276. be used in the preamble. Make sure that \documentclass[…]
  277. {'{…}'} and all \usepackage
  278. {'{…}'} commands are written before \begin
  279. {'{document}'}.
  280. </>
  281. )
  282. },
  283. {
  284. regexToMatch: /Missing \\right inserted/,
  285. extraInfoURL:
  286. 'https://www.overleaf.com/learn/Errors/Missing_%5Cright_insertede',
  287. humanReadableHintComponent: (
  288. <>
  289. You have started an expression with a \left command, but have not
  290. included a corresponding \right command. Make sure that your \left and
  291. \right commands balance everywhere, or else try using \Biggl and \Biggr
  292. commands instead as shown{' '}
  293. <WikiLink url="https://www.overleaf.com/learn/Errors/Missing_%5Cright_inserted">
  294. here
  295. </WikiLink>
  296. .
  297. </>
  298. )
  299. },
  300. {
  301. regexToMatch: /Double superscript/,
  302. extraInfoURL: 'https://www.overleaf.com/learn/Errors/Double_superscript',
  303. humanReadableHintComponent: (
  304. <>
  305. You have written a double superscript incorrectly as a^b^c, or else you
  306. have written a prime with a superscript. Remember to include {'{and}'}{' '}
  307. when using multiple superscripts. Try a^
  308. {'{b ^ c}'} instead.
  309. </>
  310. )
  311. },
  312. {
  313. regexToMatch: /Double subscript/,
  314. extraInfoURL: 'https://www.overleaf.com/learn/Errors/Double_subscript',
  315. humanReadableHintComponent: (
  316. <>
  317. You have written a double subscript incorrectly as a_b_c. Remember to
  318. include {'{and}'} when using multiple subscripts. Try a_
  319. {'{b_c}'} instead.
  320. </>
  321. )
  322. },
  323. {
  324. regexToMatch: /No \\author given/,
  325. extraInfoURL: 'https://www.overleaf.com/learn/Errors/No_%5Cauthor_given',
  326. humanReadableHintComponent: (
  327. <>
  328. You have used the \maketitle command, but have not specified any
  329. \author. To fix this, include an author in your preamble using the
  330. \author
  331. {'{…}'} command.
  332. </>
  333. )
  334. },
  335. {
  336. regexToMatch: /LaTeX Error: Environment .+ undefined/,
  337. extraInfoURL:
  338. 'https://www.overleaf.com/learn/Errors%2FLaTeX%20Error%3A%20Environment%20XXX%20undefined',
  339. humanReadableHintComponent: (
  340. <>
  341. You have created an environment (using \begin
  342. {'{…}'} and \end
  343. {'{…}'} commands) which is not recognized. Make sure you have included
  344. the required package for that environment in your preamble, and that the
  345. environment is spelled correctly.
  346. </>
  347. )
  348. },
  349. {
  350. regexToMatch: /LaTeX Error: Something's wrong--perhaps a missing \\item/,
  351. extraInfoURL:
  352. 'https://www.overleaf.com/learn/Errors/LaTeX_Error:_Something%27s_wrong--perhaps_a_missing_%5Citem',
  353. humanReadableHintComponent: (
  354. <>
  355. There are no entries found in a list you have created. Make sure you
  356. label list entries using the \item command, and that you have not used a
  357. list inside a table.
  358. </>
  359. )
  360. },
  361. {
  362. regexToMatch: /Misplaced \\noalign/,
  363. extraInfoURL: 'https://www.overleaf.com/learn/Errors/Misplaced_%5Cnoalign',
  364. humanReadableHintComponent: (
  365. <>
  366. You have used a \hline command in the wrong place, probably outside a
  367. table. If the \hline command is written inside a table, try including \\
  368. before it.
  369. </>
  370. )
  371. },
  372. {
  373. regexToMatch: /LaTeX Error: There's no line here to end/,
  374. extraInfoURL:
  375. 'https://www.overleaf.com/learn/Errors/LaTeX_Error:_There%27s_no_line_here_to_end',
  376. humanReadableHintComponent: (
  377. <>
  378. You have used a \\ or \newline command where LaTeX was not expecting
  379. one. Make sure that you only use line breaks after blocks of text, and
  380. be careful using linebreaks inside lists and other environments.\
  381. </>
  382. )
  383. },
  384. {
  385. regexToMatch: /LaTeX Error: \\verb ended by end of line/,
  386. extraInfoURL:
  387. 'https://www.overleaf.com/learn/Errors/LaTeX_Error:_%5Cverb_ended_by_end_of_line',
  388. humanReadableHintComponent: (
  389. <>
  390. You have used a \verb command incorrectly. Try replacling the \verb
  391. command with \begin
  392. {'{verbatim}'}
  393. …\end
  394. {'{verbatim}'}
  395. .\
  396. </>
  397. )
  398. },
  399. {
  400. regexToMatch: /Illegal unit of measure (pt inserted)/,
  401. extraInfoURL:
  402. 'https://www.overleaf.com/learn/Errors%2FIllegal%20unit%20of%20measure%20(pt%20inserted)',
  403. humanReadableHintComponent: (
  404. <>
  405. You have written a length, but have not specified the appropriate units
  406. (pt, mm, cm etc.). If you have not written a length, check that you have
  407. not witten a linebreak \\ followed by square brackets […] anywhere.
  408. </>
  409. )
  410. },
  411. {
  412. regexToMatch: /Extra \\right/,
  413. extraInfoURL: 'https://www.overleaf.com/learn/Errors/Extra_%5Cright',
  414. humanReadableHintComponent: (
  415. <>
  416. You have written a \right command without a corresponding \left command.
  417. Check that all \left and \right commands balance everywhere.
  418. </>
  419. )
  420. },
  421. {
  422. regexToMatch: /Missing \\begin{document}/,
  423. extraInfoURL:
  424. 'https://www.overleaf.com/learn/Errors%2FLaTeX%20Error%3A%20Missing%20%5Cbegin%20document',
  425. humanReadableHintComponent: (
  426. <>
  427. No \begin
  428. {'{document}'} command was found. Make sure you have included \begin
  429. {'{document}'} in your preamble, and that your main document is set
  430. correctly.
  431. </>
  432. )
  433. },
  434. {
  435. ruleId: 'hint_mismatched_environment2',
  436. types: ['environment'],
  437. cascadesFrom: ['environment'],
  438. regexToMatch: /Error: `\\end\{([^\}]+)\}' expected but found `\\end\{([^\}]+)\}'.*/,
  439. newMessage: 'Error: environments do not match: \\begin{$1} ... \\end{$2}',
  440. humanReadableHintComponent: (
  441. <>
  442. You have used \begin
  443. {'{}'} without a corresponding \end
  444. {'{}'}.
  445. </>
  446. )
  447. },
  448. {
  449. ruleId: 'hint_mismatched_environment3',
  450. types: ['environment'],
  451. cascadesFrom: ['environment'],
  452. regexToMatch: /Warning: No matching \\end found for `\\begin\{([^\}]+)\}'.*/,
  453. newMessage: 'Warning: No matching \\end found for \\begin{$1}',
  454. humanReadableHintComponent: (
  455. <>
  456. You have used \begin
  457. {'{}'} without a corresponding \end
  458. {'{}'}.
  459. </>
  460. )
  461. },
  462. {
  463. ruleId: 'hint_mismatched_environment4',
  464. types: ['environment'],
  465. cascadesFrom: ['environment'],
  466. regexToMatch: /Error: Found `\\end\{([^\}]+)\}' without corresponding \\begin.*/,
  467. newMessage: 'Error: found \\end{$1} without a corresponding \\begin{$1}',
  468. humanReadableHintComponent: (
  469. <>
  470. You have used \begin
  471. {'{}'} without a corresponding \end
  472. {'{}'}.
  473. </>
  474. )
  475. }
  476. ]
  477. rules.forEach(rule => {
  478. rule.humanReadableHint = ReactDOMServer.renderToStaticMarkup(
  479. rule.humanReadableHintComponent
  480. )
  481. rule.extraInfoURL = window.wikiEnabled ? rule.extraInfoURL : null
  482. })
  483. export default rules