HumanReadableLogsHints.jsx 17 KB

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